public class MutableInteger
extends java.lang.Number
implements java.lang.Comparable
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
| Constructor and Description |
|---|
MutableInteger()
Constructs a new MutableInteger with default value 0.
|
MutableInteger(int initialValue) |
| Modifier and Type | Method and Description |
|---|---|
MutableInteger |
add(double value)
Increases the int's value by value.
|
int |
compareTo(java.lang.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(java.lang.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.
|
java.lang.String |
toString() |
public MutableInteger()
public MutableInteger(int initialValue)
public int intValue()
intValue in class java.lang.Numberpublic long longValue()
longValue in class java.lang.Numberpublic float floatValue()
floatValue in class java.lang.Numberpublic double doubleValue()
doubleValue in class java.lang.Numberpublic MutableInteger add(double value)
(int) ( intValue() + value ) .value - the amount to addpublic MutableInteger subtract(double value)
(int) ( intValue() - value ) .value - the amount to subtractpublic int compareTo(java.lang.Object o)
compareTo in interface java.lang.ComparableComparablepublic boolean equals(java.lang.Object obj)
true if and only if the argument is not
null and is an MutableInteger object that contains
the same int value as this object.equals in class java.lang.Objectobj - the object to compare with.true if the objects are the same;
false otherwise.public int hashCode()
hashCode in class java.lang.Objectpublic void setInteger(int newInteger)
public MutableInteger increment()
public void decrement()
public java.lang.String toString()
toString in class java.lang.Object