edu.uci.ics.jung.utils
Class MutableDouble

java.lang.Object
  extended byjava.lang.Number
      extended byedu.uci.ics.jung.utils.MutableDouble
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class MutableDouble
extends java.lang.Number
implements java.lang.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(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.
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
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.


longValue

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


floatValue

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


doubleValue

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


compareTo

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

equals

public boolean equals(java.lang.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.

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.

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 java.lang.String toString()
Uses the default String converter to return the value of this as a string.