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