public class IntegerMutable extends Object
Integer
.
I needed an wrapper of an primitive int to share the same value between different instances and to have the changes made to the primitive value take effect on all owners of the same instance.
What a pity that java.lang.Integer does not allow to change it's internal value at runtime. Every time a new Integer has to be constructed.
Modifier and Type | Field and Description |
---|---|
static int |
MAX_VALUE
The largest value of type
int . |
static int |
MIN_VALUE
The smallest value of type
int . |
Constructor and Description |
---|
IntegerMutable(int value)
Constructs a newly allocated
Integer object that represents
the primitive int argument. |
Modifier and Type | Method and Description |
---|---|
void |
add(int i)
Adds the given value to the internal value.
|
void |
add(Integer i)
Adds the given value to the internal value.
|
void |
add(IntegerMutable i)
Adds the given value to the internal value.
|
boolean |
equals(Object obj) |
int |
getValue()
Returns the value as an int.
|
int |
hashCode() |
int |
intValue()
Returns the value as an int.
|
void |
setValue(int value)
Sets the value.
|
void |
sub(int i)
Substracts the given value from the internal value.
|
void |
sub(Integer i)
Substracts the given value from the internal value.
|
void |
sub(IntegerMutable i)
Substracts the given value from the internal value.
|
String |
toString()
Returns a String object representing this Integer's value.
|
public static final int MAX_VALUE
int
. The constant value of this
field is 2147483647.public static final int MIN_VALUE
int
. The constant value of this
field is -2147483648.public IntegerMutable(int value)
Integer
object that represents
the primitive int
argument.value
- the value to be represented by the Integer
.public void add(int i) throws ArithmeticException
i
- the value to add.ArithmeticException
- if an overflow (Integer.MAX_VALUE
) occurs.public void add(Integer i) throws ArithmeticException
i
- the value to add.ArithmeticException
- if an overflow (Integer.MAX_VALUE
) occurs.public void add(IntegerMutable i) throws ArithmeticException
i
- the value to add.ArithmeticException
- if an overflow (Integer.MAX_VALUE
) occurs.public boolean equals(Object obj)
equals
in class Object
Object.equals(java.lang.Object)
public int getValue()
public int hashCode()
hashCode
in class Object
Object.hashCode()
public int intValue()
public void setValue(int value)
value
- the value.public void sub(int i) throws ArithmeticException
i
- the value to subtract.ArithmeticException
- if a carry (Integer.MIN_VALUE
) occurs.public void sub(Integer i) throws ArithmeticException
i
- the value to subtract.ArithmeticException
- if a carry (Integer.MIN_VALUE
) occurs.public void sub(IntegerMutable i) throws ArithmeticException
i
- the value to subtract.ArithmeticException
- if a carry (Integer.MIN_VALUE
) occurs.public String toString()
The value is converted to signed decimal representation and returned as a
string, exactly as if the integer value were given as an argument to the
Integer.toString(int)
method.
Copyright © 2001 - 2010 LGPL, All Rights Footloose.