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 19 20 package com.maverick.util; 21 22 27 public class UnsignedInteger32 { 28 29 30 public final static long MAX_VALUE = 0xffffffffL; 31 32 33 public final static long MIN_VALUE = 0; 34 private Long value; 35 36 43 public UnsignedInteger32(long a) { 44 if ( (a < MIN_VALUE) || (a > MAX_VALUE)) { 45 throw new NumberFormatException (); 46 } 47 48 value = new Long (a); 49 } 50 51 58 public UnsignedInteger32(String a) throws NumberFormatException { 59 60 long longValue = Long.parseLong(a); 61 62 if ( (longValue < MIN_VALUE) || (longValue > MAX_VALUE)) { 63 throw new NumberFormatException (); 64 } 65 66 value = new Long (longValue); 67 } 68 69 74 public int intValue() { 75 return (int) value.longValue(); 76 } 77 78 83 public long longValue() { 84 return value.longValue(); 85 } 86 87 88 93 public String toString() { 94 return value.toString(); 95 } 96 97 102 public int hashCode() { 103 return value.hashCode(); 104 } 105 106 113 public boolean equals(Object o) { 114 if (! (o instanceof UnsignedInteger32)) { 115 return false; 116 } 117 118 return ( ( (UnsignedInteger32) o).value.equals(this.value)); 119 } 120 121 129 public static UnsignedInteger32 add(UnsignedInteger32 x, UnsignedInteger32 y) { 130 return new UnsignedInteger32(x.longValue() + y.longValue()); 131 } 132 133 141 public static UnsignedInteger32 add(UnsignedInteger32 x, int y) { 142 return new UnsignedInteger32(x.longValue() + y); 143 } 144 } 145
| Popular Tags
|