1 16 17 package org.apache.commons.lang.mutable; 18 19 import org.apache.commons.lang.math.NumberUtils; 20 21 28 public class MutableFloat extends Number implements Comparable , Mutable { 29 30 31 private static final long serialVersionUID = 5787169186L; 32 33 34 private float value; 35 36 39 public MutableFloat() { 40 super(); 41 } 42 43 49 public MutableFloat(float value) { 50 super(); 51 this.value = value; 52 } 53 54 62 public MutableFloat(Number value) { 63 super(); 64 this.value = value.floatValue(); 65 } 66 67 73 public Object getValue() { 74 return new Float (this.value); 75 } 76 77 83 public void setValue(float value) { 84 this.value = value; 85 } 86 87 97 public void setValue(Object value) { 98 setValue(((Number ) value).floatValue()); 99 } 100 101 108 public int intValue() { 109 return (int) value; 110 } 111 112 117 public long longValue() { 118 return (long) value; 119 } 120 121 126 public float floatValue() { 127 return value; 128 } 129 130 135 public double doubleValue() { 136 return value; 137 } 138 139 144 public boolean isNaN() { 145 return Float.isNaN(value); 146 } 147 148 153 public boolean isInfinite() { 154 return Float.isInfinite(value); 155 } 156 157 189 public boolean equals(Object obj) { 190 return (obj instanceof MutableFloat) 191 && (Float.floatToIntBits(((MutableFloat) obj).value) == Float.floatToIntBits(value)); 192 } 193 194 200 public int hashCode() { 201 return Float.floatToIntBits(value); 202 } 203 204 211 public int compareTo(Object obj) { 212 MutableFloat other = (MutableFloat) obj; 213 float anotherVal = other.value; 214 return NumberUtils.compare(value, anotherVal); 215 } 216 217 222 public String toString() { 223 return String.valueOf(value); 224 } 225 226 } 227 | Popular Tags |