public class MutableDouble
extends java.lang.Number
implements java.lang.Comparable
MutableDouble
class wraps a value of the primitive type double
in a mutable object. An object of type MutableDouble
contains a single field whose type is double
.
This allows the system to not pile up large
sets of temporary "numbers" and reduces object creation when doing math.
In addition, this class provides several methods for converting a double
to a String and a String to a double
.
Warning: It is important to not modify Mutable values when they are in a sorted data structure, such as a TreeSet! They will fall out of order and cause the set to be inconsistent
Constructor and Description |
---|
MutableDouble()
Constructs a new MutableDouble with a default value of 0
assigned
|
MutableDouble(double initialValue)
Constructs a new MutableDouble with the input value.
|
Modifier and Type | Method and Description |
---|---|
MutableDouble |
add(double value)
Increases the double's value by value.
|
int |
compareTo(java.lang.Object o) |
double |
doubleValue()
Returns the value as a double, accomplished by returning the
primitive contained double.
|
boolean |
equals(java.lang.Object obj)
Compares this object to the specified object.
|
float |
floatValue()
Returns the nearest float value, accomplished by casting the
contained double to
float . |
int |
hashCode()
Returns a hashcode for this Integer.
|
int |
intValue()
Returns the floor integer value, accomplished by casting the
contained double to
int . |
long |
longValue()
Returns the floor integer value as a long, accomplished by casting the
contained double to
long . |
void |
setDoubleValue(double newDouble)
Sets the double value to a new value.
|
MutableDouble |
subtract(double value)
Decreases the double's value by value.
|
java.lang.String |
toString()
Uses the default String converter to return the value of this
as a string.
|
public MutableDouble()
public MutableDouble(double initialValue)
public int intValue()
int
.intValue
in class java.lang.Number
public long longValue()
long
.longValue
in class java.lang.Number
public float floatValue()
float
.floatValue
in class java.lang.Number
public double doubleValue()
doubleValue
in class java.lang.Number
public int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable
Comparable
public boolean equals(java.lang.Object obj)
true
if and only if the argument is not
null
and is an MutableDouble
object that contains
the same double
value as this object.equals
in class java.lang.Object
obj
- the object to compare with.true
if the objects are the same;
false
otherwise.public int hashCode()
hashCode
in class java.lang.Object
public void setDoubleValue(double newDouble)
public MutableDouble add(double value)
doubleValue() + value
.value
- the amount to addpublic MutableDouble subtract(double value)
doubleValue() - value
.value
- the amount to subtractpublic java.lang.String toString()
toString
in class java.lang.Object