1 9 10 package org.jboss.util; 11 12 18 public class MuShort 19 extends MuNumber 20 { 21 22 private short value; 23 24 27 public MuShort() {} 28 29 34 public MuShort(short s) { 35 value = s; 36 } 37 38 43 public MuShort(Object obj) { 44 setValue(obj); 45 } 46 47 53 public short set(short s) { 54 short old = value; 55 value = s; 56 return old; 57 } 58 59 64 public short get() { 65 return value; 66 } 67 68 76 public boolean commit(short assumed, short b) { 77 boolean success = (assumed == value); 78 if (success) value = b; 79 return success; 80 } 81 82 88 public short swap(MuShort b) { 89 if (b == this) return value; 90 91 short temp = value; 92 value = b.value; 93 b.value = temp; 94 95 return value; 96 } 97 98 103 public short increment() { 104 return ++value; 105 } 106 107 112 public short decrement() { 113 return --value; 114 } 115 116 122 public short add(short amount) { 123 return value += amount; 124 } 125 126 132 public short subtract(short amount) { 133 return value -= amount; 134 } 135 136 142 public short multiply(short factor) { 143 return value *= factor; 144 } 145 146 152 public short divide(short factor) { 153 return value /= factor; 154 } 155 156 161 public short negate() { 162 value = ((short)-value); 163 return value; 164 } 165 166 171 public short complement() { 172 value = (short)~value; 173 return value; 174 } 175 176 182 public short and(short b) { 183 value = (short)(value & b); 184 return value; 185 } 186 187 193 public short or(short b) { 194 value = (short)(value | b); 195 return value; 196 } 197 198 204 public short xor(short b) { 205 value = (short)(value ^ b); 206 return value; 207 } 208 209 215 public short shiftRight(int bits) { 216 value >>= bits; 217 return value; 218 } 219 220 226 public short shiftRightZero(int bits) { 227 value >>>= bits; 228 return value; 229 } 230 231 237 public short shiftLeft(int bits) { 238 value <<= bits; 239 return value; 240 } 241 242 250 public int compareTo(short other) { 251 return (value < other) ? -1 : (value == other) ? 0 : 1; 252 } 253 254 264 public int compareTo(Object obj) { 265 return compareTo((MuShort)obj); 266 } 267 268 273 public String toString() { 274 return String.valueOf(value); 275 } 276 277 282 public int hashCode() { 283 return (int)value; 284 } 285 286 292 public boolean equals(Object obj) { 293 if (obj == this) return true; 294 295 if (obj != null && obj.getClass() == getClass()) { 296 return value == ((MuShort)obj).shortValue(); 297 } 298 299 return false; 300 } 301 302 307 public Object clone() { 308 try { 309 return super.clone(); 310 } 311 catch (CloneNotSupportedException e) { 312 throw new InternalError (); 313 } 314 } 315 316 317 321 326 public byte byteValue() { 327 return (byte)value; 328 } 329 330 335 public short shortValue() { 336 return (short)value; 337 } 338 339 344 public int intValue() { 345 return (int)value; 346 } 347 348 353 public long longValue() { 354 return (long)value; 355 } 356 357 362 public float floatValue() { 363 return (float)value; 364 } 365 366 371 public double doubleValue() { 372 return (double)value; 373 } 374 375 376 380 387 public void setValue(Object obj) { 388 if (obj instanceof Number ) { 389 value = ((Number )obj).shortValue(); 390 } 391 else { 392 throw new NotCoercibleException("can not convert to 'short': " + obj); 393 } 394 } 395 396 401 public Object getValue() { 402 return new Short (value); 403 } 404 } 405 | Popular Tags |