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 package org.apache.torque.om; 2 3 21 22 import java.math.BigDecimal ; 23 24 34 public class NumberKey extends SimpleKey 35 { 36 39 private static final long serialVersionUID = -5566819786708264162L; 40 41 45 public NumberKey() 46 { 47 } 48 49 54 public NumberKey(String key) 55 { 56 this.key = new BigDecimal (key); 57 } 58 59 64 public NumberKey(BigDecimal key) 65 { 66 this.key = key; 67 } 68 69 74 public NumberKey(NumberKey key) 75 { 76 if (key != null) 77 { 78 this.key = key.getValue(); 79 } 80 else 81 { 82 this.key = null; 83 } 84 } 85 86 91 public NumberKey(long key) 92 { 93 this.key = BigDecimal.valueOf(key); 94 } 95 96 101 public NumberKey(double key) 102 { 103 this.key = new BigDecimal (key); 104 } 105 106 112 public NumberKey(int key) 113 { 114 this((long) key); 115 } 116 117 123 public NumberKey(Number key) 124 { 125 if (key != null) 126 { 127 this.key = new BigDecimal (key.toString()); 128 } 129 else 130 { 131 this.key = null; 132 } 133 } 134 135 142 public void setValue(String key) throws NumberFormatException  143 { 144 this.key = new BigDecimal (key); 145 } 146 147 152 public void setValue(BigDecimal key) 153 { 154 this.key = key; 155 } 156 157 162 public void setValue(NumberKey key) 163 { 164 this.key = (key == null ? null : key.getValue()); 165 } 166 167 172 public BigDecimal getBigDecimal() 173 { 174 return (BigDecimal ) key; 175 } 176 177 184 public boolean equals(Object keyObj) 185 { 186 if (keyObj == this) 187 { 188 return true; 189 } 190 191 if (!(keyObj instanceof NumberKey)) 192 { 193 if (keyObj instanceof String ) 197 { 198 throw new IllegalArgumentException ( 199 "NumberKeys are not comparable to Strings"); 200 } 201 202 return false; 203 } 204 205 if (getValue() != null) 206 { 207 return getValue().equals(((NumberKey) keyObj).getValue()); 208 } 209 else 210 { 211 return false; 213 } 214 } 215 216 219 public int hashCode() 220 { 221 if (getValue() == null) 222 { 223 return super.hashCode(); 224 } 225 else 226 { 227 return getValue().hashCode(); 228 } 229 } 230 231 235 public int compareTo(Object o) 236 { 237 return getBigDecimal().compareTo(((NumberKey) o).getBigDecimal()); 238 } 239 240 246 public String toString() 247 { 248 if (key != null) 249 { 250 return key.toString(); 251 } 252 return ""; 253 } 254 255 262 public byte byteValue() 263 { 264 return getBigDecimal().byteValue(); 265 } 266 267 279 public int intValue() 280 { 281 return getBigDecimal().intValue(); 282 } 283 284 296 public short shortValue() 297 { 298 return getBigDecimal().shortValue(); 299 } 300 301 308 public long longValue() 309 { 310 return getBigDecimal().longValue(); 311 } 312 313 323 public float floatValue() 324 { 325 return getBigDecimal().floatValue(); 326 } 327 328 338 public double doubleValue() 339 { 340 return getBigDecimal().doubleValue(); 341 } 342 } 343
| Popular Tags
|