Package info.monitorenter.util.math
Class IntegerMutable
java.lang.Object
info.monitorenter.util.math.IntegerMutable
Mutable
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.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionIntegerMutable
(int value) Constructs a newly allocatedInteger
object that represents the primitiveint
argument. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int i) Adds the given value to the internal value.void
Adds the given value to the internal value.void
Adds the given value to the internal value.boolean
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
Substracts the given value from the internal value.void
Substracts the given value from the internal value.toString()
Returns a String object representing this Integer's value.
-
Field Details
-
MAX_VALUE
public static final int MAX_VALUEThe largest value of typeint
. The constant value of this field is 2147483647.- See Also:
-
MIN_VALUE
public static final int MIN_VALUEThe smallest value of typeint
. The constant value of this field is -2147483648.- See Also:
-
-
Constructor Details
-
IntegerMutable
public IntegerMutable(int value) Constructs a newly allocatedInteger
object that represents the primitiveint
argument.- Parameters:
value
- the value to be represented by theInteger
.
-
-
Method Details
-
add
Adds the given value to the internal value.- Parameters:
i
- the value to add.- Throws:
ArithmeticException
- if an overflow (Integer.MAX_VALUE
) occurs.
-
add
Adds the given value to the internal value.- Parameters:
i
- the value to add.- Throws:
ArithmeticException
- if an overflow (Integer.MAX_VALUE
) occurs.
-
add
Adds the given value to the internal value.- Parameters:
i
- the value to add.- Throws:
ArithmeticException
- if an overflow (Integer.MAX_VALUE
) occurs.
-
equals
-
getValue
public int getValue()Returns the value as an int.- Returns:
- the value as an int.
-
hashCode
public int hashCode() -
intValue
public int intValue()Returns the value as an int.- Returns:
- the value as an int.
-
setValue
public void setValue(int value) Sets the value.- Parameters:
value
- the value.
-
sub
Substracts the given value from the internal value.- Parameters:
i
- the value to subtract.- Throws:
ArithmeticException
- if a carry (Integer.MIN_VALUE
) occurs.
-
sub
Substracts the given value from the internal value.- Parameters:
i
- the value to subtract.- Throws:
ArithmeticException
- if a carry (Integer.MIN_VALUE
) occurs.
-
sub
Substracts the given value from the internal value.- Parameters:
i
- the value to subtract.- Throws:
ArithmeticException
- if a carry (Integer.MIN_VALUE
) occurs.
-
toString
Returns a String object representing this Integer's value.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.
-