org.openmali.types.primitives
Class MutableInteger

java.lang.Object
  extended by java.lang.Number
      extended by org.openmali.types.primitives.MutableInteger
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<MutableInteger>

public class MutableInteger
extends java.lang.Number
implements java.lang.Comparable<MutableInteger>

This a mutable derivation of the Integer class. Most of the code is borrowed from the Integer class.

See Also:
Serialized Form

Constructor Summary
MutableInteger(int value)
          Constructs a newly allocated MutableInteger object that represents the specified int value.
MutableInteger(java.lang.String s)
          Constructs a newly allocated MutableInteger object that represents the int value indicated by the String parameter.
 
Method Summary
 byte byteValue()
          Returns the value of this MutableInteger as a byte.
 int compareTo(MutableInteger anotherInteger)
          Compares two MutableInteger objects numerically.
 double doubleValue()
          Returns the value of this MutableInteger as a double.
 boolean equals(java.lang.Object obj)
          Compares this object to the specified object.
 float floatValue()
          Returns the value of this MutableInteger as a float.
 int hashCode()
          Returns a hash code for this MutableInteger.
 int intValue()
          Returns the value of this MutableInteger as an int.
 long longValue()
          Returns the value of this MutableInteger as a long.
 void setValue(int value)
           
 short shortValue()
          Returns the value of this MutableInteger as a short.
 java.lang.String toString()
          Returns a String object representing this MutableInteger's value.
static MutableInteger valueOf(int i)
          Returns a MutableInteger instance representing the specified int value.
static MutableInteger valueOf(java.lang.String s)
          Returns an MutableInteger object holding the value of the specified String.
static MutableInteger valueOf(java.lang.String s, int radix)
          Returns an MutableInteger object holding the value extracted from the specified String when parsed with the radix given by the second argument.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MutableInteger

public MutableInteger(int value)
Constructs a newly allocated MutableInteger object that represents the specified int value.

Parameters:
value - the value to be represented by the MutableInteger object.

MutableInteger

public MutableInteger(java.lang.String s)
               throws java.lang.NumberFormatException
Constructs a newly allocated MutableInteger object that represents the int value indicated by the String parameter. The string is converted to an int value in exactly the manner used by the parseInt method for radix 10.

Parameters:
s - the String to be converted to an MutableInteger.
Throws:
java.lang.NumberFormatException - if the String does not contain a parsable integer.
See Also:
Integer.parseInt(java.lang.String, int)
Method Detail

setValue

public final void setValue(int value)

byteValue

public final byte byteValue()
Returns the value of this MutableInteger as a byte.

Overrides:
byteValue in class java.lang.Number

shortValue

public final short shortValue()
Returns the value of this MutableInteger as a short.

Overrides:
shortValue in class java.lang.Number

intValue

public final int intValue()
Returns the value of this MutableInteger as an int.

Specified by:
intValue in class java.lang.Number

longValue

public final long longValue()
Returns the value of this MutableInteger as a long.

Specified by:
longValue in class java.lang.Number

floatValue

public final float floatValue()
Returns the value of this MutableInteger as a float.

Specified by:
floatValue in class java.lang.Number

doubleValue

public final double doubleValue()
Returns the value of this MutableInteger as a double.

Specified by:
doubleValue in class java.lang.Number

toString

public java.lang.String toString()
Returns a String object representing this MutableInteger'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 java.lang.Object
Returns:
a string representation of the value of this object in base 10.

hashCode

public int hashCode()
Returns a hash code for this MutableInteger.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object, equal to the primitive int value represented by this MutableInteger object.

equals

public boolean equals(java.lang.Object obj)
Compares this object to the specified object. The result is true if and only if the argument is not null and is an MutableInteger object that contains the same int value as this object.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare with.
Returns:
true if the objects are the same; false otherwise.

compareTo

public int compareTo(MutableInteger anotherInteger)
Compares two MutableInteger objects numerically.

Specified by:
compareTo in interface java.lang.Comparable<MutableInteger>
Parameters:
anotherInteger - the MutableInteger to be compared.
Returns:
the value 0 if this MutableInteger is equal to the argument MutableInteger; a value less than 0 if this MutableInteger is numerically less than the argument MutableInteger; and a value greater than 0 if this MutableInteger is numerically greater than the argument MutableInteger (signed comparison).
Since:
1.2

valueOf

public static MutableInteger valueOf(java.lang.String s,
                                     int radix)
                              throws java.lang.NumberFormatException
Returns an MutableInteger object holding the value extracted from the specified String when parsed with the radix given by the second argument. The first argument is interpreted as representing a signed integer in the radix specified by the second argument, exactly as if the arguments were given to the Integer.parseInt(java.lang.String, int) method. The result is an MutableInteger object that represents the integer value specified by the string.

In other words, this method returns an MutableInteger object equal to the value of:

new MutableInteger(Integer.parseInt(s, radix))

Parameters:
s - the string to be parsed.
radix - the radix to be used in interpreting s
Returns:
an MutableInteger object holding the value represented by the string argument in the specified radix.
Throws:
java.lang.NumberFormatException - if the String does not contain a parsable int.

valueOf

public static MutableInteger valueOf(java.lang.String s)
                              throws java.lang.NumberFormatException
Returns an MutableInteger object holding the value of the specified String. The argument is interpreted as representing a signed decimal integer, exactly as if the argument were given to the Integer.parseInt(java.lang.String) method. The result is an MutableInteger object that represents the integer value specified by the string.

In other words, this method returns an MutableInteger object equal to the value of:

new MutableInteger(Integer.parseInt(s))

Parameters:
s - the string to be parsed.
Returns:
an MutableInteger object holding the value represented by the string argument.
Throws:
java.lang.NumberFormatException - if the string cannot be parsed as an integer.

valueOf

public static MutableInteger valueOf(int i)
Returns a MutableInteger instance representing the specified int value. If a new MutableInteger instance is not required, this method should generally be used in preference to the constructor MutableInteger(int), as this method is likely to yield significantly better space and time performance by caching frequently requested values.

Parameters:
i - an int value.
Returns:
a MutableInteger instance representing i.
Since:
1.5