1 9 package org.jscience.mathematics.numbers; 10 11 import javolution.lang.MathLib; 12 import javolution.text.Text; 13 import javolution.text.TypeFormat; 14 import javolution.xml.XMLFormat; 15 import javolution.xml.stream.XMLStreamException; 16 17 25 public final class Integer64 extends Number <Integer64> { 26 27 32 protected static final XMLFormat<Integer64> XML = new XMLFormat<Integer64>(Integer64.class) { 33 34 @Override 35 public Integer64 newInstance(Class <Integer64> cls, InputElement xml) 36 throws XMLStreamException { 37 return Integer64.valueOf(xml.getAttribute("value", 0L)); 38 } 39 40 public void write(Integer64 integer64, OutputElement xml) 41 throws XMLStreamException { 42 xml.setAttribute("value", integer64._value); 43 } 44 45 public void read(InputElement xml, Integer64 integer64) { 46 } 48 }; 49 50 53 private static final Factory<Integer64> FACTORY = new Factory<Integer64>() { 54 55 public Integer64 create() { 56 return new Integer64(); 57 } 58 }; 59 60 63 public static final Integer64 ZERO = new Integer64(0L); 64 65 68 public static final Integer64 ONE = new Integer64(1L); 69 70 73 private long _value; 74 75 78 private Integer64() { 79 } 80 81 87 private Integer64(long longValue) { 88 _value = longValue; 89 } 90 91 98 public static Integer64 valueOf(long longValue) { 99 Integer64 r = FACTORY.object(); 100 r._value = longValue; 101 return r; 102 } 103 104 110 public static Integer64 valueOf(CharSequence chars) { 111 Integer64 r = FACTORY.object(); 112 r._value = TypeFormat.parseLong(chars); 113 return r; 114 } 115 116 121 public Integer64 opposite() { 122 Integer64 r = FACTORY.object(); 123 r._value = -this._value; 124 return r; 125 } 126 127 133 public Integer64 plus(Integer64 that) { 134 Integer64 r = FACTORY.object(); 135 r._value = this._value + that._value; 136 return r; 137 } 138 139 145 public Integer64 minus(Integer64 that) { 146 Integer64 r = FACTORY.object(); 147 r._value = this._value - that._value; 148 return r; 149 } 150 151 157 public Integer64 times(Integer64 that) { 158 Integer64 r = FACTORY.object(); 159 r._value = this._value * that._value; 160 return r; 161 } 162 163 169 public Integer64 divide(Integer64 that) { 170 Integer64 r = FACTORY.object(); 171 r._value = this._value / that._value; 172 return r; 173 } 174 175 180 public boolean isLargerThan(Integer64 that) { 181 return MathLib.abs(this._value) > MathLib.abs(that._value); 182 } 183 184 189 public Integer64 abs() { 190 Integer64 r = FACTORY.object(); 191 r._value = MathLib.abs(this._value); 192 return r; 193 } 194 195 200 public Text toText() { 201 return Text.valueOf(_value); 202 } 203 204 211 public boolean equals(Object that) { 212 return (that instanceof Integer64) 213 && (this._value == ((Integer64) that)._value); 214 } 215 216 221 public int hashCode() { 222 int h = Float.floatToIntBits((float) _value); 223 h += ~(h << 9); 224 h ^= (h >>> 14); 225 h += (h << 4); 226 return h ^ (h >>> 10); 227 } 228 229 @Override 230 public long longValue() { 231 return _value; 232 } 233 234 @Override 235 public double doubleValue() { 236 return _value; 237 } 238 239 @Override 240 public int compareTo(Integer64 that) { 241 if (this._value < that._value) { 242 return -1; 243 } else if (this._value > that._value) { 244 return 1; 245 } else { 246 return 0; 247 } 248 } 249 250 private static final long serialVersionUID = 1L; 251 } | Popular Tags |