Expresso 5-6

com.jcorporate.expresso.core.misc
Class ReusableLong

java.lang.Object
  extended byjava.lang.Number
      extended bycom.jcorporate.expresso.core.misc.ReusableLong
All Implemented Interfaces:
Comparable, Serializable

public final class ReusableLong
extends Number
implements Comparable, Serializable

Class that is nearly identical to the java.lang.Long class, except that you can reset the long value, useful for object reuse.

Author:
Michael Rimov
See Also:
Serialized Form

Field Summary
static long MAX_VALUE
          The largest value of type long.
static long MIN_VALUE
          The smallest value of type long.
 
Constructor Summary
ReusableLong()
          Creates a new ReusableLong object.
ReusableLong(long value)
           
ReusableLong(Long l)
          Constructs a newly allocated ReusableLong object from a java.lang.Long object.
ReusableLong(String s)
          Constructor taking a sting value
 
Method Summary
 byte byteValue()
          Returns the value of this Long as a byte.
 int compareTo(Object o)
          Compares this Long to another Object.
 int compareTo(ReusableLong anotherLong)
          Compares two Longs numerically.
static ReusableLong decode(String nm)
          Decodes a String into a Long.
 double doubleValue()
          Returns the value of this Long as a double.
 boolean equals(Object obj)
          Compares this object against the specified object.
 float floatValue()
          Returns the value of this Long as a float.
static ReusableLong getLong(String nm)
          Determines the long value of the system property with the specified name.
static ReusableLong getLong(String nm, long val)
          Determines the long value of the system property with the specified name.
static ReusableLong getLong(String nm, Long val)
          Returns the long value of the system property with the specified name.
 int hashCode()
          Computes a hashcode for this Long.
 int intValue()
          Returns the value of this Long as an int.
 long longValue()
          Returns the value of this Long as a long value.
static long parseLong(String s)
          Parses the string argument as a signed decimal long.
static long parseLong(String s, int radix)
          Parses the string argument as a signed long in the radix specified by the second argument.
 void setLong(long newValue)
          Resets the current long value.
 short shortValue()
          Returns the value of this Long as a short.
static String toBinaryString(long i)
          Creates a string representation of the long argument as an unsigned integer in base 2.
static String toHexString(long i)
          Creates a string representation of the long argument as an unsigned integer in base 16.
static String toOctalString(long i)
          Creates a string representation of the long argument as an unsigned integer in base 8.
static ReusableLong toReusableLong(Long l)
          Converts a Long value to a reusable long value.
 String toString()
          Returns a String object representing this Long's value.
static String toString(long i)
          Returns a new String object representing the specified integer.
static String toString(long i, int radix)
          Creates a string representation of the first argument in the radix specified by the second argument.
static ReusableLong valueOf(String s)
          Returns a new long object initialized to the value of the specified String.
static ReusableLong valueOf(String s, int radix)
          Returns a new long object initialized to the value of the specified String.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_VALUE

public static final long MIN_VALUE
The smallest value of type long.

See Also:
Constant Field Values

MAX_VALUE

public static final long MAX_VALUE
The largest value of type long.

See Also:
Constant Field Values
Constructor Detail

ReusableLong

public ReusableLong()
Creates a new ReusableLong object.


ReusableLong

public ReusableLong(long value)
Parameters:
value - the value to be represented by the Long object.
See Also:
Constructs a newly allocated Long object that represents the primitive long argument.

ReusableLong

public ReusableLong(Long l)
Constructs a newly allocated ReusableLong object from a java.lang.Long object.

Parameters:
l - A java.lang.Long object

ReusableLong

public ReusableLong(String s)
             throws NumberFormatException
Constructor taking a sting value

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

decode

public static ReusableLong decode(String nm)
                           throws NumberFormatException
Decodes a String into a Long.

Parameters:
nm - Decodes a string to a usable state.
Returns:
a ReusableLong object
Throws:
NumberFormatException - if the String does not contain a parsable long.
See Also:
Long.decode(String), Long.parseLong(String, int)

parseLong

public static long parseLong(String s,
                             int radix)
                      throws NumberFormatException
Parses the string argument as a signed long in the radix specified by the second argument.

Parameters:
s - the String containing the long.
radix - the radix to be used.
Returns:
the long represented by the string argument in the specified radix.
Throws:
NumberFormatException - if the string does not contain a parsable integer.
See Also:
Long.parseLong(java.lang.String)

parseLong

public static long parseLong(String s)
                      throws NumberFormatException
Parses the string argument as a signed decimal long.

Parameters:
s - a string.
Returns:
the long represented by the argument in decimal.
Throws:
NumberFormatException - if the string does not contain a parsable long.
See Also:
Long.parseLong(java.lang.String)

toBinaryString

public static String toBinaryString(long i)
Creates a string representation of the long argument as an unsigned integer in base 2.

Parameters:
i - a long.
Returns:
the string representation of the unsigned long value represented by the argument in binary (base 2).
See Also:
Long.toBinaryString(long)

toHexString

public static String toHexString(long i)
Creates a string representation of the long argument as an unsigned integer in base 16.

Parameters:
i - a long.
Returns:
the string representation of the unsigned long value represented by the argument in hexadecimal (base 16).
See Also:
Long.toHexString(long)

toOctalString

public static String toOctalString(long i)
Creates a string representation of the long argument as an unsigned integer in base 8.

Parameters:
i - a long.
Returns:
the string representation of the unsigned long value represented by the argument in octal (base 8).
See Also:
Long.toOctalString(long)

toReusableLong

public static ReusableLong toReusableLong(Long l)
Converts a Long value to a reusable long value. This and the static values are definitely not for general purpose use.

Parameters:
l - a java.lang.Long object
Returns:
an instantiated Reusable Long object

toString

public static String toString(long i,
                              int radix)
Creates a string representation of the first argument in the radix specified by the second argument.

Parameters:
i - a long.
radix - the radix.
Returns:
a string representation of the argument in the specified radix.
See Also:
Long.toString(), Character.MAX_RADIX, Character.MIN_RADIX

toString

public static String toString(long i)
Returns a new String object representing the specified integer.

Parameters:
i - a long to be converted.
Returns:
a string representation of the argument in base 10.
See Also:
Long.toString()

valueOf

public static ReusableLong valueOf(String s,
                                   int radix)
                            throws NumberFormatException
Returns a new long object initialized to the value of the specified String. Throws an exception if the String cannot be parsed as a long.

Parameters:
s - the String containing the long.
radix - the radix to be used.
Returns:
a newly constructed Long initialized to the value represented by the string argument in the specified radix.
Throws:
NumberFormatException - If the String does not contain a parsable long.
See Also:
Long.valueOf(String,int)

valueOf

public static ReusableLong valueOf(String s)
                            throws NumberFormatException
Returns a new long object initialized to the value of the specified String.

Parameters:
s - the string to be parsed.
Returns:
a newly constructed Long initialized to the value represented by the string argument.
Throws:
NumberFormatException - If the String does not contain a parsable long.
See Also:
Long.valueOf(String)

setLong

public void setLong(long newValue)
Resets the current long value. This saves a call to new() and garbage collection

Parameters:
newValue - a new value for the long object

getLong

public static ReusableLong getLong(String nm)
Determines the long value of the system property with the specified name.

Parameters:
nm - property name.
Returns:
the Long value of the property.
See Also:
Long.getLong(java.lang.String), System.getProperty(java.lang.String), System.getProperty(java.lang.String, java.lang.String)

getLong

public static ReusableLong getLong(String nm,
                                   long val)
Determines the long value of the system property with the specified name.

Parameters:
nm - property name.
val - default value.
Returns:
the Long value of the property.
See Also:
Long.getLong(java.lang.String), System.getProperty(java.lang.String), System.getProperty(java.lang.String, java.lang.String)

getLong

public static ReusableLong getLong(String nm,
                                   Long val)
Returns the long value of the system property with the specified name.

Parameters:
nm - the system property name
val - The java.lang.Long to translate
Returns:
an instantiated ReusableLong object
See Also:
java.lang.Long#getLong(), System.getProperty(String), System.getProperty(String,String), Long.decode(String)

byteValue

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

Returns:
a byte value
See Also:
Long.byteValue()

compareTo

public int compareTo(ReusableLong anotherLong)
Compares two Longs numerically.

Parameters:
anotherLong - another Long obejct to compare
Returns:
-1 0 or 1 as per java.lang.Comparable.
See Also:
Long.compareTo(Long)

compareTo

public int compareTo(Object o)
Compares this Long to another Object.

Specified by:
compareTo in interface Comparable
Parameters:
o - The object to compare to.
Returns:
-1, 0, or -1 as per the java.lang.Comparable interface semantics
See Also:
Long.compareTo(Object)

doubleValue

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

Returns:
the long value represented by this object that is converted to type double and the result of the conversion is returned.
See Also:
Long.doubleValue()

equals

public boolean equals(Object obj)
Compares this object against the specified object. The result is true if and only if the argument is not null and is a Long object that contains the same long value as this object.

Parameters:
obj - the object to compare with.
Returns:
true if the objects are the same; false otherwise.
See Also:
Long.equals(java.lang.Object)

floatValue

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

Returns:
the long value represented by this object is converted to type float and the result of the conversion is returned.
See Also:
Long.floatValue()

hashCode

public int hashCode()
Computes a hashcode for this Long. The result is the exclusive OR of the two halves of the primitive long value represented by this Long object. That is, the hashcode is the value of the expression:
 (int)(this.longValue()^(this.longValue()>>>32))
 

Returns:
a hash code value for this object.
See Also:
java.lang.Long#hashcode

intValue

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

Returns:
the long value represented by this object is converted to type int and the result of the conversion is returned.
See Also:
Long.intValue()

longValue

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

Returns:
the long value represented by this object.
See Also:
Long.longValue()

shortValue

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

Returns:
a short object. It may be truncated
See Also:
Long.shortValue()

toString

public String toString()
Returns a String object representing this Long's value.

Returns:
a string representation of this object in base 10.
See Also:
Long.toString()

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.