1 9 10 package org.jboss.util; 11 12 18 public class MuByte 19 extends MuNumber 20 { 21 22 private byte value; 24 27 public MuByte() {} 28 29 34 public MuByte(byte b) { 35 value = b; 36 } 37 38 43 public MuByte(Object obj) { 44 setValue(obj); 45 } 46 47 53 public byte set(byte b) { 54 byte old = value; 55 value = b; 56 return old; 57 } 58 59 64 public byte get() { 65 return value; 66 } 67 68 76 public boolean commit(byte assumed, byte b) { 77 boolean success = (assumed == value); 78 if (success) value = b; 79 return success; 80 } 81 82 88 public byte swap(MuByte b) { 89 if (b == this) return value; 90 91 byte temp = value; 92 value = b.value; 93 b.value = temp; 94 95 return value; 96 } 97 98 103 public byte increment() { 104 return ++value; 105 } 106 107 112 public byte decrement() { 113 return --value; 114 } 115 116 122 public byte add(byte amount) { 123 return value += amount; 124 } 125 126 132 public byte subtract(byte amount) { 133 return value -= amount; 134 } 135 136 142 public byte multiply(byte factor) { 143 return value *= factor; 144 } 145 146 152 public byte divide(byte factor) { 153 return value /= factor; 154 } 155 156 161 public byte negate() { 162 value = ((byte)-value); 163 return value; 164 } 165 166 171 public byte complement() { 172 value = (byte)~value; 173 return value; 174 } 175 176 182 public byte and(byte b) { 183 value = (byte)(value & b); 184 return value; 185 } 186 187 193 public byte or(byte b) { 194 value = (byte)(value | b); 195 return value; 196 } 197 198 204 public byte xor(byte b) { 205 value = (byte)(value ^ b); 206 return value; 207 } 208 209 215 public byte shiftRight(int bits) { 216 value >>= bits; 217 return value; 218 } 219 220 226 public byte shiftRightZero(int bits) { 227 value >>>= bits; 228 return value; 229 } 230 231 237 public byte shiftLeft(int bits) { 238 value <<= bits; 239 return value; 240 } 241 242 250 public int compareTo(byte other) { 251 return (value < other) ? -1 : (value == other) ? 0 : 1; 252 } 253 254 264 public int compareTo(Object obj) throws ClassCastException { 265 return compareTo((MuByte)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 == ((MuByte)obj).byteValue(); 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 385 public void setValue(Object obj) { 386 if (obj instanceof Number ) { 387 value = ((Number )obj).byteValue(); 388 } 389 else { 390 value = (byte)obj.hashCode(); 391 } 392 } 393 394 399 public Object getValue() { 400 return new Byte (value); 401 } 402 } 403 | Popular Tags |