1 3 package jodd.mutable; 4 5 import jodd.util.MathUtil; 6 7 10 public final class MutableDouble extends Number implements Comparable { 11 12 13 public MutableDouble() { 14 super(); 15 } 16 17 public MutableDouble(double value) { 18 super(); 19 this.value = value; 20 } 21 22 public MutableDouble(String value) { 23 this(Double.parseDouble(value)); 24 } 25 26 28 31 public double value; 32 33 36 public double getValue() { 37 return value; 38 } 39 40 43 public void setValue(double value) { 44 this.value = value; 45 } 46 47 50 public void setValue(Number value) { 51 this.value = value.doubleValue(); 52 } 53 54 56 59 public String toString() { 60 return Double.toString(value); 61 } 62 63 66 public int hashCode() { 67 long bits = Double.doubleToLongBits(value); 68 return (int) (bits ^ (bits >>> 32)); 69 } 70 71 78 public boolean equals(Object obj) { 79 if (obj != null) { 80 if (obj instanceof Double ) { 81 return Double.doubleToLongBits(value) == Double.doubleToLongBits(((Double ) obj).doubleValue()); 82 } 83 if (obj instanceof MutableDouble) { 84 return Double.doubleToLongBits(value) == Double.doubleToLongBits(((MutableDouble) obj).value); 85 } 86 } 87 return false; 88 } 89 90 92 95 public int intValue() { 96 return (int) value; 97 } 98 99 102 public long longValue() { 103 return (long) value; 104 } 105 106 109 public float floatValue() { 110 return (float) value; 111 } 112 113 116 public double doubleValue() { 117 return value; 118 } 119 120 122 125 public boolean isNaN() { 126 return Double.isNaN(value); 127 } 128 129 132 public boolean isInfinite() { 133 return Double.isInfinite(value); 134 } 135 136 139 public int compareTo(Object obj) { 140 MutableDouble other = (MutableDouble) obj; 141 return MathUtil.compare(value, other.value); 142 } 143 } | Popular Tags |