info.monitorenter.util.math
Class IntegerReuseable

java.lang.Object
  extended by info.monitorenter.util.math.IntegerReuseable

public class IntegerReuseable
extends Object

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
static int MAX_VALUE
          The largest value of type int.
static int MIN_VALUE
          The smallest value of type int.
 
Constructor Summary
IntegerReuseable(int value)
          Constructs a newly allocated Integer object that represents the primitive int argument.
 
Method Summary
 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(IntegerReuseable i)
          Adds the given value to the internal value.
 int getValue()
          Returns the value as an int.
 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(IntegerReuseable i)
          Substracts the given value from the internal value.
 String toString()
          Returns a String object representing this Integer's value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_VALUE

public static final int MAX_VALUE
The largest value of type int. 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 type int. The constant value of this field is -2147483648.

See Also:
Constant Field Values
Constructor Detail

IntegerReuseable

public IntegerReuseable(int value)
Constructs a newly allocated Integer object that represents the primitive int argument.

Parameters:
value - the value to be represented by the Integer.
Method Detail

add

public void add(int i)
         throws ArithmeticException
Adds the given value to the internal value.

Parameters:
i - the value to add.
Throws:
ArithmeticException - if an overflow (Integer.MAX_VALUE) occurs.

add

public void add(Integer i)
         throws ArithmeticException
Adds the given value to the internal value.

Parameters:
i - the value to add.
Throws:
ArithmeticException - if an overflow (Integer.MAX_VALUE) occurs.

add

public void add(IntegerReuseable i)
         throws ArithmeticException
Adds the given value to the internal value.

Parameters:
i - the value to add.
Throws:
ArithmeticException - if an overflow (Integer.MAX_VALUE) occurs.

getValue

public int getValue()
Returns the value as an int.

Returns:
the value as an int.

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 ArithmeticException
Substracts the given value from the internal value.

Parameters:
i - the value to subtract.
Throws:
ArithmeticException - if a carry (Integer.MIN_VALUE) occurs.

sub

public void sub(Integer i)
         throws ArithmeticException
Substracts the given value from the internal value.

Parameters:
i - the value to subtract.
Throws:
ArithmeticException - if a carry (Integer.MIN_VALUE) occurs.

sub

public void sub(IntegerReuseable i)
         throws ArithmeticException
Substracts the given value from the internal value.

Parameters:
i - the value to subtract.
Throws:
ArithmeticException - if a carry (Integer.MIN_VALUE) occurs.

toString

public 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:
toString in class Object
Returns:
a string representation of the value of this object in base 10.


Copyright © 2001 - 2007 LGPL, All Rights Footloose.