edu.uci.ics.jung.utils
Class MutableInteger

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

public class MutableInteger
extends Number
implements Comparable

The MutableInteger class wraps a value of the primitive type int in a mutable object. An object of type MutableInteger contains a single field whose type is int. 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 int to a String and a String to a int.

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
MutableInteger()
          Constructs a new MutableInteger with default value 0.
MutableInteger(int initialValue)
           
 
Method Summary
 MutableInteger add(double value)
          Increases the int's value by value.
 int compareTo(Object o)
           
 void decrement()
          Subtracts one from the contained integer value.
 double doubleValue()
          Returns the integer value of this object, expressed as a double.
 boolean equals(Object obj)
          Compares this object to the specified object.
 float floatValue()
          Returns the integer value of this object, expressed as a float.
 int hashCode()
          Returns a hashcode for this Integer.
 MutableInteger increment()
          Adds one to the contained integer value.
 int intValue()
          Returns the integer value of this object.
 long longValue()
          Returns the integer value of this object, expressed as a long.
 void setInteger(int newInteger)
          Sets the value of this object to newInteger.
 MutableInteger subtract(double value)
          Increases the int's value by value.
 String toString()
           
 
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

MutableInteger

public MutableInteger()
Constructs a new MutableInteger with default value 0.


MutableInteger

public MutableInteger(int initialValue)
Method Detail

intValue

public int intValue()
Returns the integer value of this object.

Specified by:
intValue in class Number

longValue

public long longValue()
Returns the integer value of this object, expressed as a long.

Specified by:
longValue in class Number

floatValue

public float floatValue()
Returns the integer value of this object, expressed as a float.

Specified by:
floatValue in class Number

doubleValue

public double doubleValue()
Returns the integer value of this object, expressed as a double.

Specified by:
doubleValue in class Number

add

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

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

subtract

public MutableInteger subtract(double value)
Increases the int's value by value. The object will, after this call, contain the value (int) ( intValue() - value ) .

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

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 MutableInteger object that contains the same int 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 MutableInteger object.

setInteger

public void setInteger(int newInteger)
Sets the value of this object to newInteger.


increment

public MutableInteger increment()
Adds one to the contained integer value.

Returns:
this, to assist in chaining.

decrement

public void decrement()
Subtracts one from the contained integer value.


toString

public String toString()
Overrides:
toString in class Object