Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 9 10 package org.jboss.util; 11 12 18 public class MuInteger 19 extends MuNumber 20 { 21 22 private int value; 23 24 27 public MuInteger() {} 28 29 34 public MuInteger(int i) { 35 value = i; 36 } 37 38 43 public MuInteger(Object obj) { 44 setValue(obj); 45 } 46 47 55 public boolean commit(int assumed, int i) { 56 boolean success = (assumed == value); 57 if (success) value = i; 58 return success; 59 } 60 61 67 public int swap(MuInteger i) { 68 if (i == this) return i.value; 69 70 int temp = value; 71 value = i.value; 72 i.value = temp; 73 74 return value; 75 } 76 77 82 public int increment() { 83 return ++value; 84 } 85 86 91 public int decrement() { 92 return --value; 93 } 94 95 101 public int add(int amount) { 102 return value += amount; 103 } 104 105 111 public int subtract(int amount) { 112 return value -= amount; 113 } 114 115 121 public int multiply(int factor) { 122 return value *= factor; 123 } 124 125 131 public int divide(int factor) { 132 return value /= factor; 133 } 134 135 140 public int negate() { 141 value = ((int)-value); 142 return value; 143 } 144 145 150 public int complement() { 151 value = (int)~value; 152 return value; 153 } 154 155 161 public int and(int b) { 162 value = (int)(value & b); 163 return value; 164 } 165 166 172 public int or(int b) { 173 value = (int)(value | b); 174 return value; 175 } 176 177 183 public int xor(int b) { 184 value = (int)(value ^ b); 185 return value; 186 } 187 188 194 public int shiftRight(int bits) { 195 value >>= bits; 196 return value; 197 } 198 199 205 public int shiftRightZero(int bits) { 206 value >>>= bits; 207 return value; 208 } 209 210 216 public int shiftLeft(int bits) { 217 value <<= bits; 218 return value; 219 } 220 221 229 public int compareTo(int other) { 230 return (value < other) ? -1 : (value == other) ? 0 : 1; 231 } 232 233 243 public int compareTo(Object obj) { 244 return compareTo(((MuInteger)obj).value); 245 } 246 247 252 public String toString() { 253 return String.valueOf(value); 254 } 255 256 261 public int hashCode() { 262 return value; 263 } 264 265 271 public boolean equals(Object obj) { 272 if (obj == this) return true; 273 274 if (obj != null && obj.getClass() == getClass()) { 275 return value == ((MuInteger)obj).intValue(); 276 } 277 278 return false; 279 } 280 281 286 public Object clone() { 287 try { 288 return super.clone(); 289 } 290 catch (CloneNotSupportedException e) { 291 throw new InternalError (); 292 } 293 } 294 295 299 304 public byte byteValue() { 305 return (byte)value; 306 } 307 308 313 public short shortValue() { 314 return (short)value; 315 } 316 317 322 public int intValue() { 323 return (int)value; 324 } 325 326 331 public long longValue() { 332 return (long)value; 333 } 334 335 340 public float floatValue() { 341 return (float)value; 342 } 343 344 349 public double doubleValue() { 350 return (double)value; 351 } 352 353 354 358 365 public void setValue(Object obj) { 366 if (obj instanceof Number ) { 367 value = ((Number )obj).intValue(); 368 } 369 else { 370 throw new NotCoercibleException("can not convert to 'int': " + obj); 371 } 372 } 373 374 379 public Object getValue() { 380 return new Integer (value); 381 } 382 } 383
| Popular Tags
|