Package info.monitorenter.util.math
Class IntegerMutable
- java.lang.Object
-
- info.monitorenter.util.math.IntegerMutable
-
public class IntegerMutable extends java.lang.ObjectMutableInteger.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.
-
-
Constructor Summary
Constructors Constructor Description IntegerMutable(int value)Constructs a newly allocatedIntegerobject that represents the primitiveintargument.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int i)Adds the given value to the internal value.voidadd(IntegerMutable i)Adds the given value to the internal value.voidadd(java.lang.Integer i)Adds the given value to the internal value.booleanequals(java.lang.Object obj)intgetValue()Returns the value as an int.inthashCode()intintValue()Returns the value as an int.voidsetValue(int value)Sets the value.voidsub(int i)Substracts the given value from the internal value.voidsub(IntegerMutable i)Substracts the given value from the internal value.voidsub(java.lang.Integer i)Substracts the given value from the internal value.java.lang.StringtoString()Returns a String object representing this Integer's value.
-
-
-
Field Detail
-
MAX_VALUE
public static final int MAX_VALUE
The largest value of typeint. The constant value of this field is 2147483647.- See Also:
- Constant Field Values
-
MIN_VALUE
public static final int MIN_VALUE
The smallest value of typeint. The constant value of this field is -2147483648.- See Also:
- Constant Field Values
-
-
Method Detail
-
add
public void add(int i) throws java.lang.ArithmeticExceptionAdds the given value to the internal value.- Parameters:
i- the value to add.- Throws:
java.lang.ArithmeticException- if an overflow (Integer.MAX_VALUE) occurs.
-
add
public void add(java.lang.Integer i) throws java.lang.ArithmeticExceptionAdds the given value to the internal value.- Parameters:
i- the value to add.- Throws:
java.lang.ArithmeticException- if an overflow (Integer.MAX_VALUE) occurs.
-
add
public void add(IntegerMutable i) throws java.lang.ArithmeticException
Adds the given value to the internal value.- Parameters:
i- the value to add.- Throws:
java.lang.ArithmeticException- if an overflow (Integer.MAX_VALUE) occurs.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object- See Also:
Object.equals(java.lang.Object)
-
getValue
public int getValue()
Returns the value as an int.- Returns:
- the value as an int.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object- See Also:
Object.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
public void sub(int i) throws java.lang.ArithmeticExceptionSubstracts the given value from the internal value.- Parameters:
i- the value to subtract.- Throws:
java.lang.ArithmeticException- if a carry (Integer.MIN_VALUE) occurs.
-
sub
public void sub(java.lang.Integer i) throws java.lang.ArithmeticExceptionSubstracts the given value from the internal value.- Parameters:
i- the value to subtract.- Throws:
java.lang.ArithmeticException- if a carry (Integer.MIN_VALUE) occurs.
-
sub
public void sub(IntegerMutable i) throws java.lang.ArithmeticException
Substracts the given value from the internal value.- Parameters:
i- the value to subtract.- Throws:
java.lang.ArithmeticException- if a carry (Integer.MIN_VALUE) occurs.
-
toString
public java.lang.String 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.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of the value of this object in base 10.
-
-