edu.uci.ics.jung.utils
Class MutableDouble

java.lang.Object
  extended by java.lang.Number
      extended by edu.uci.ics.jung.utils.MutableDouble
All Implemented Interfaces:
Serializable, Comparable

public class MutableDouble
extends Number
implements Comparable

The 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

Author:
Scott White
See Also:
Serialized Form

Constructor Summary
MutableDouble()
          Constructs a new MutableDouble with a default value of 0 assigned
MutableDouble(double initialValue)
          Constructs a new MutableDouble with the input value.
 
Method Summary
 MutableDouble add(double value)
          Increases the double's value by value.
 int compareTo(Object o)
           
 double doubleValue()
          Returns the value as a double, accomplished by returning the primitive contained double.
 boolean equals(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.
 String toString()
          Uses the default String converter to return the value of this as a string.
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MutableDouble

public MutableDouble()
Constructs a new MutableDouble with a default value of 0 assigned


MutableDouble

public MutableDouble(double initialValue)
Constructs a new MutableDouble with the input value.

Method Detail

intValue

public int intValue()
Returns the floor integer value, accomplished by casting the contained double to int.

Specified by:
intValue in class Number

longValue

public long longValue()
Returns the floor integer value as a long, accomplished by casting the contained double to long.

Specified by:
longValue in class Number

floatValue

public float floatValue()
Returns the nearest float value, accomplished by casting the contained double to float.

Specified by:
floatValue in class Number

doubleValue

public double doubleValue()
Returns the value as a double, accomplished by returning the primitive contained double.

Specified by:
doubleValue in class Number

compareTo

public int compareTo(Object o)
Specified by:
compareTo in interface Comparable
See Also:
Comparable

equals

public boolean equals(Object obj)
Compares this object to the specified object. The result is true if and only if the argument is not null and is an MutableDouble object that contains the same double value as this object.

Overrides:
equals in class Object
Parameters:
obj - the object to compare with.
Returns:
true if the objects are the same; false otherwise.

hashCode

public int hashCode()
Returns a hashcode for this Integer.

Overrides:
hashCode in class Object
Returns:
a hash code value for this object, equal to the primitive int value represented by this MutableDouble object.

setDoubleValue

public void setDoubleValue(double newDouble)
Sets the double value to a new value.


add

public MutableDouble add(double value)
Increases the double's value by value. The object will, after this call, contain the value doubleValue() + value.

Parameters:
value - the amount to add
Returns:
this object, for convenience in chaining operations

subtract

public MutableDouble subtract(double value)
Decreases the double's value by value. The object will, after this call, contain the value doubleValue() - value.

Parameters:
value - the amount to subtract
Returns:
this object, for convenience in chaining operations

toString

public String toString()
Uses the default String converter to return the value of this as a string.

Overrides:
toString in class Object