org.openmali.types.primitives
Class MutableLong

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

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

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

See Also:
Serialized Form

Constructor Summary
MutableLong(long value)
          Constructs a newly allocated MutableLong object that represents the specified long argument.
MutableLong(java.lang.String s)
          Constructs a newly allocated MutableLong object that represents the long value indicated by the String parameter.
 
Method Summary
 byte byteValue()
          Returns the value of this MutableLong as a byte.
 int compareTo(MutableLong anotherLong)
          Compares two MutableLong objects numerically.
 double doubleValue()
          Returns the value of this MutableLong as a double.
 boolean equals(java.lang.Object obj)
          Compares this object to the specified object.
 float floatValue()
          Returns the value of this MutableLong as a float.
 int hashCode()
          Returns a hash code for this MutableLong.
 int intValue()
          Returns the value of this MutableLong as an int.
 long longValue()
          Returns the value of this MutableLong as a long value.
 void setValue(long value)
           
 short shortValue()
          Returns the value of this MutableLong as a short.
 java.lang.String toString()
          Returns a String object representing this MutableLong's value.
static MutableLong valueOf(long l)
          Returns a MutableLong instance representing the specified long value.
static MutableLong valueOf(java.lang.String s)
          Returns a MutableLong object holding the value of the specified String.
static MutableLong valueOf(java.lang.String s, int radix)
          Returns a MutableLong 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

MutableLong

public MutableLong(long value)
Constructs a newly allocated MutableLong object that represents the specified long argument.

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

MutableLong

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

Parameters:
s - the String to be converted to a MutableLong.
Throws:
java.lang.NumberFormatException - if the String does not contain a parsable long.
See Also:
Long.parseLong(java.lang.String, int)
Method Detail

setValue

public final void setValue(long value)

byteValue

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

Overrides:
byteValue in class java.lang.Number

shortValue

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

Overrides:
shortValue in class java.lang.Number

intValue

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

Specified by:
intValue in class java.lang.Number

longValue

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

Specified by:
longValue in class java.lang.Number

floatValue

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

Specified by:
floatValue in class java.lang.Number

doubleValue

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

Specified by:
doubleValue in class java.lang.Number

toString

public java.lang.String toString()
Returns a String object representing this MutableLong's value. The value is converted to signed decimal representation and returned as a string, exactly as if the long value were given as an argument to the Long.toString(long) 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 MutableLong. The result is the exclusive OR of the two halves of the primitive long value held by this MutableLong object. That is, the hashcode is the value of the expression:
 (int)(this.longValue()^(this.longValue()>>>32))
 

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this 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 a MutableLong object that contains the same long 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(MutableLong anotherLong)
Compares two MutableLong objects numerically.

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

valueOf

public static MutableLong valueOf(java.lang.String s,
                                  int radix)
                           throws java.lang.NumberFormatException
Returns a MutableLong 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 long in the radix specified by the second argument, exactly as if the arguments were given to the Long.parseLong(java.lang.String, int) method. The result is a MutableLong object that represents the long value specified by the string.

In other words, this method returns a MutableLong object equal to the value of:

new MutableLong(Long.parseLong(s, radix))

Parameters:
s - the string to be parsed
radix - the radix to be used in interpreting s
Returns:
a MutableLong 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 long.

valueOf

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

In other words, this method returns a MutableLong object equal to the value of:

 new MutableLong(Long.parseLong(s))
 

Parameters:
s - the string to be parsed.
Returns:
a MutableLong object holding the value represented by the string argument.
Throws:
java.lang.NumberFormatException - If the string cannot be parsed as a long.

valueOf

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

Parameters:
l - a long value.
Returns:
a MutableLong instance representing l.
Since:
1.5