1 16 17 package org.apache.commons.lang.mutable; 18 19 import org.apache.commons.lang.math.NumberUtils; 20 21 28 public class MutableDouble extends Number implements Comparable , Mutable { 29 30 31 private static final long serialVersionUID = 1587163916L; 32 33 34 private double value; 35 36 39 public MutableDouble() { 40 super(); 41 } 42 43 49 public MutableDouble(double value) { 50 super(); 51 this.value = value; 52 } 53 54 62 public MutableDouble(Number value) { 63 super(); 64 this.value = value.doubleValue(); 65 } 66 67 73 public Object getValue() { 74 return new Double (this.value); 75 } 76 77 83 public void setValue(double value) { 84 this.value = value; 85 } 86 87 97 public void setValue(Object value) { 98 setValue(((Number ) value).doubleValue()); 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 (float) value; 128 } 129 130 135 public double doubleValue() { 136 return value; 137 } 138 139 144 public boolean isNaN() { 145 return Double.isNaN(value); 146 } 147 148 153 public boolean isInfinite() { 154 return Double.isInfinite(value); 155 } 156 157 188 public boolean equals(Object obj) { 189 return (obj instanceof MutableDouble) 190 && (Double.doubleToLongBits(((MutableDouble) obj).value) == Double.doubleToLongBits(value)); 191 } 192 193 198 public int hashCode() { 199 long bits = Double.doubleToLongBits(value); 200 return (int) (bits ^ (bits >>> 32)); 201 } 202 203 211 public int compareTo(Object obj) { 212 MutableDouble other = (MutableDouble) obj; 213 double 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 |