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 MuLong 19 extends MuNumber 20 { 21 22 private long value; 23 24 27 public MuLong() {} 28 29 34 public MuLong(long l) { 35 value = l; 36 } 37 38 43 public MuLong(Object obj) { 44 setValue(obj); 45 } 46 47 55 public boolean commit(long assumed, long b) { 56 boolean success = (assumed == value); 57 if (success) value = b; 58 return success; 59 } 60 61 67 public long swap(MuLong b) { 68 if (b == this) return value; 69 70 long temp = value; 71 value = b.value; 72 b.value = temp; 73 74 return value; 75 } 76 77 82 public long increment() { 83 return ++value; 84 } 85 86 91 public long decrement() { 92 return --value; 93 } 94 95 101 public long add(long amount) { 102 return value += amount; 103 } 104 105 111 public long subtract(long amount) { 112 return value -= amount; 113 } 114 115 121 public long multiply(long factor) { 122 return value *= factor; 123 } 124 125 131 public long divide(long factor) { 132 return value /= factor; 133 } 134 135 140 public long negate() { 141 value = ((long)-value); 142 return value; 143 } 144 145 150 public long complement() { 151 value = (long)~value; 152 return value; 153 } 154 155 161 public long and(long b) { 162 value = (long)(value & b); 163 return value; 164 } 165 166 172 public long or(long b) { 173 value = (long)(value | b); 174 return value; 175 } 176 177 183 public long xor(long b) { 184 value = (long)(value ^ b); 185 return value; 186 } 187 188 194 public long shiftRight(int bits) { 195 value >>= bits; 196 return value; 197 } 198 199 205 public long shiftRightZero(int bits) { 206 value >>>= bits; 207 return value; 208 } 209 210 216 public long shiftLeft(int bits) { 217 value <<= bits; 218 return value; 219 } 220 221 229 public int compareTo(long other) { 230 return (value < other) ? -1 : (value == other) ? 0 : 1; 231 } 232 233 243 public int compareTo(Object obj) { 244 return compareTo((MuLong)obj); 245 } 246 247 252 public String toString() { 253 return String.valueOf(value); 254 } 255 256 261 public int hashCode() { 262 return HashCode.generate(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 == ((MuLong)obj).longValue(); 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 358 public void set(long value) 359 { 360 this.value = value; 361 } 362 363 364 368 375 public void setValue(Object obj) { 376 if (obj instanceof Number ) { 377 value = ((Number )obj).longValue(); 378 } 379 else { 380 throw new NotCoercibleException("can not convert to 'long': " + obj); 381 } 382 } 383 384 389 public Object getValue() { 390 return new Long (value); 391 } 392 } 393
| Popular Tags
|