1 64 package com.jcorporate.expresso.core.misc; 65 66 import java.io.ObjectInputStream ; 67 import java.io.ObjectOutputStream ; 68 69 71 77 public final class ReusableLong extends Number implements Comparable , 78 java.io.Serializable { 79 82 public static final long MIN_VALUE = Long.MIN_VALUE; 83 84 87 public static final long MAX_VALUE = Long.MAX_VALUE; 88 89 94 private long value; 95 96 99 public ReusableLong() { 100 } 101 102 108 public ReusableLong(long value) { 109 this.value = value; 110 } 111 112 118 public ReusableLong(Long l) { 119 value = l.longValue(); 120 } 121 122 131 public ReusableLong(String s) throws NumberFormatException { 132 this.value = parseLong(s, 10); 133 } 134 135 145 public static ReusableLong decode(String nm) throws NumberFormatException { 146 return toReusableLong(Long.decode(nm)); 147 } 148 149 161 public static long parseLong(String s, int radix) 162 throws NumberFormatException { 163 return Long.parseLong(s, radix); 164 } 165 166 175 public static long parseLong(String s) throws NumberFormatException { 176 return Long.parseLong(s); 177 } 178 179 188 public static String toBinaryString(long i) { 189 return Long.toBinaryString(i); 190 } 191 192 201 public static String toHexString(long i) { 202 return Long.toHexString(i); 203 } 204 205 214 public static String toOctalString(long i) { 215 return Long.toOctalString(i); 216 } 217 218 225 public static ReusableLong toReusableLong(Long l) { 226 return new ReusableLong(l.longValue()); 227 } 228 229 240 public static String toString(long i, int radix) { 241 return Long.toString(i, radix); 242 } 243 244 251 public static String toString(long i) { 252 return Long.toString(i); 253 } 254 255 267 public static ReusableLong valueOf(String s, int radix) 268 throws NumberFormatException { 269 return toReusableLong(Long.valueOf(s, radix)); 270 } 271 272 283 public static ReusableLong valueOf(String s) throws NumberFormatException { 284 return toReusableLong(Long.valueOf(s)); 285 } 286 287 293 public void setLong(long newValue) { 294 value = newValue; 295 } 296 297 307 public static ReusableLong getLong(String nm) { 308 return getLong(nm, null); 309 } 310 311 322 public static ReusableLong getLong(String nm, long val) { 323 ReusableLong result = ReusableLong.getLong(nm, null); 324 325 return (result == null) ? new ReusableLong(val) : result; 326 } 327 328 339 public static ReusableLong getLong(String nm, Long val) { 340 return toReusableLong(Long.getLong(nm, val)); 341 } 342 343 349 public byte byteValue() { 350 return (byte) value; 351 } 352 353 360 public int compareTo(ReusableLong anotherLong) { 361 long thisVal = this.value; 362 long anotherVal = anotherLong.value; 363 364 return ((thisVal < anotherVal) ? (-1) : ((thisVal == anotherVal) ? 0 : 1)); 365 } 366 367 374 public int compareTo(Object o) { 375 return compareTo((ReusableLong) o); 376 } 377 378 386 public double doubleValue() { 387 return (double) value; 388 } 389 390 401 public boolean equals(Object obj) { 402 if (obj instanceof ReusableLong) { 403 return value == ((ReusableLong) obj).longValue(); 404 } 405 406 return false; 407 } 408 409 417 public float floatValue() { 418 return (float) value; 419 } 420 421 435 public int hashCode() { 436 return (int) (value ^ (value >> 32)); 437 } 438 439 447 public int intValue() { 448 return (int) value; 449 } 450 451 457 public long longValue() { 458 return (long) value; 459 } 460 461 467 public short shortValue() { 468 return (short) value; 469 } 470 471 477 public String toString() { 478 return String.valueOf(value); 479 } 480 481 486 private void readObject(ObjectInputStream ois) 487 throws ClassNotFoundException , java.io.IOException { 488 value = ois.readLong(); 489 } 490 491 496 private void writeObject(ObjectOutputStream oos) throws java.io.IOException { 497 oos.writeLong(value); 498 } 499 } 500 | Popular Tags |