com.internationalnetwork.lang
Class VeryLong

Object
  extended by Number
      extended by com.internationalnetwork.lang.VeryLong
All Implemented Interfaces:
java.io.Serializable, Comparable

public final class VeryLong
extends Number
implements Comparable

Instances of class VeryLong represent non-existent primitive 128-bit verylong values by using a 16-byte primitive byte[] array.  The BigInteger class is used internally to provide functions but without exceeding the boundaries of a signed 128-bit value.

Additionally, this class provides various helper functions and variables useful in dealing with VeryLong values.

See Also:
Serialized Form

Field Summary
static java.math.BigInteger MAX_VALUE
          A constant holding the maximum value a VeryLong can represent; 170141183460469231731687303715884105727 (or 2127 -1).
static java.math.BigInteger MIN_VALUE
          A constant holding the minimum value a VaryLong can represent; -170141183460469231731687303715884105728 (or -2127).
static int SIZE
          The number of bits needed to represent a VeryLong.
static int SIZE8
          The number of bytes needed to represent a VeryLong.
static String VERSION
          Version number of this Package (read-only).
 
Constructor Summary
VeryLong(java.math.BigInteger b)
          Create a VeryLong object representing the converted value of the BigInteger argument.  If the value is out of range, then an exception will be thrown.
VeryLong(byte[] value)
          Create a VeryLong object representing the value of the byte argument.
VeryLong(int value)
          Create a VeryLong object representing the value of the int argument.
VeryLong(String s)
          Create a VeryLong object representing the parsed value of the String argument.  If the value is out of range, or can't be parsed, then an exception will be thrown.
VeryLong(String s, int radix)
          Create a VeryLong object representing the parsed value of the String argument in the specified radix.  If the value is out of range, or can't be parsed, then an exception will be thrown.
 
Method Summary
 java.math.BigInteger bigIntegerValue()
          Return the value of this VeryLong as a BigInteger object.
static VeryLong coerce(java.math.BigInteger value)
          Strips off excess bits (the sign will be preserved), if any, and returns the remaining BigInteger presented as a VeryLong.
 int compareTo(Object o)
          Behaves like compareTo(VeryLong) unless the Object is not a VeryLong.  The result is positive if the first is greater, negative if the second is greater, and 0 if the two are equal.
 int compareTo(VeryLong n)
          Compare two VeryLongs numerically by comparing their VeryLong values.  The result is positive if the first is greater, negative if the second is greater, and 0 if the two are equal.
 double doubleValue()
          Return the value of this VeryLong as a double.
 boolean equals(Object obj)
          Returns true if obj is an instance of VeryLong and represents the same VeryLong value.
 float floatValue()
          Return the value of this VeryLong as a float.
 int hashCode()
          Return a hashcode representing this Object.
 int intValue()
          Return the value of this VeryLong as an integer.
 long longValue()
          Return the value of this VeryLong as a long integer.
 VeryLong negate()
          Returns a VeryLong whose value is (-this).
static VeryLong parseVeryLong(String s)
          Converts the specified String into a VeryLong, presented as a VeryLong because Java doesn't have a primitive VeryLong type.  This function assumes a radix of 10.
static VeryLong parseVeryLong(String s, int radix)
          Converts the specified String into a VeryLong, presented as a VeryLong because Java doesn't have a primitive VeryLong type, using the specified radix (base).  The string must not be null or empty.  It may begin with an optional minus sign ("-"), which will negate the answer, provided that there are also valid digits.  Each digit is parsed as if by Character.digit(d, radix), and must be in the range 0 to radix - 1.  Finally, the result must be within MIN_VALUE to MAX_VALUE, inclusive.  Unlike Double.parseDouble, you may not have a leading plus sign ("+").
 short shortValue()
          Return the value of this VeryLong as a short.
 byte[] toByteArray()
          Return the value of this VeryLong as a byte[] array.
 String toString()
          Converts the VeryLong value to a String and assumes a radix of 10.
 String toString(int radix)
          Converts the VeryLong value to a String, using the specified radix.
static String toString(VeryLong veryLong)
          Converts the VeryLong to a String and assumes a radix of 10.
static VeryLong valueOf(String s)
          Creates a new VeryLong object using the String and assuming a radix of 10.
static VeryLong valueOf(String s, int radix)
          Creates a new VeryLong object using the String and specified radix (base).
 
Methods inherited from class Number
byteValue
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_VALUE

public static final java.math.BigInteger MAX_VALUE
A constant holding the maximum value a VeryLong can represent; 170141183460469231731687303715884105727 (or 2127 -1).


MIN_VALUE

public static final java.math.BigInteger MIN_VALUE
A constant holding the minimum value a VaryLong can represent; -170141183460469231731687303715884105728 (or -2127).


SIZE

public static final int SIZE
The number of bits needed to represent a VeryLong.

See Also:
Constant Field Values

SIZE8

public static final int SIZE8
The number of bytes needed to represent a VeryLong.

See Also:
Constant Field Values

VERSION

public static final String VERSION
Version number of this Package (read-only).

See Also:
Constant Field Values
Constructor Detail

VeryLong

public VeryLong(java.math.BigInteger b)
Create a VeryLong object representing the converted value of the BigInteger argument.  If the value is out of range, then an exception will be thrown.

Parameters:
b - the BigInteger object to convert
Throws:
NumberFormatException - if the BigInteger is out of range

VeryLong

public VeryLong(byte[] value)
Create a VeryLong object representing the value of the byte argument.

Parameters:
value - the byte array representing the value to use
Throws:
NumberFormatException - if value is out of range

VeryLong

public VeryLong(int value)
Create a VeryLong object representing the value of the int argument.

Parameters:
value - the value to use

VeryLong

public VeryLong(String s)
Create a VeryLong object representing the parsed value of the String argument.  If the value is out of range, or can't be parsed, then an exception will be thrown.

Parameters:
s - the string to convert
Throws:
NumberFormatException - if the string does not contain a VeryLong value
See Also:
valueOf(String)

VeryLong

public VeryLong(String s,
                int radix)
Create a VeryLong object representing the parsed value of the String argument in the specified radix.  If the value is out of range, or can't be parsed, then an exception will be thrown.

Parameters:
s - the string to convert
radix - radix (base) to be used in interpreting
Throws:
NumberFormatException - if the string does not contain a VeryLong value
See Also:
valueOf(String)
Method Detail

bigIntegerValue

public java.math.BigInteger bigIntegerValue()
Return the value of this VeryLong as a BigInteger object.

Returns:
the BigInteger value

coerce

public static VeryLong coerce(java.math.BigInteger value)
Strips off excess bits (the sign will be preserved), if any, and returns the remaining BigInteger presented as a VeryLong.

Parameters:
value - The byte value
Returns:
the BigInteger represented as a VeryLong

compareTo

public int compareTo(Object o)
Behaves like compareTo(VeryLong) unless the Object is not a VeryLong.  The result is positive if the first is greater, negative if the second is greater, and 0 if the two are equal.

Specified by:
compareTo in interface Comparable
Parameters:
o - the Object to compare
Returns:
the comparison
Throws:
ClassCastException - if the argument is not a VeryLong

compareTo

public int compareTo(VeryLong n)
Compare two VeryLongs numerically by comparing their VeryLong values.  The result is positive if the first is greater, negative if the second is greater, and 0 if the two are equal.

Parameters:
n - the VeryLong to compare
Returns:
the comparison

doubleValue

public double doubleValue()
Return the value of this VeryLong as a double.

Specified by:
doubleValue in class Number
Returns:
the double value

equals

public boolean equals(Object obj)
Returns true if obj is an instance of VeryLong and represents the same VeryLong value.

Overrides:
equals in class Object
Parameters:
obj - the object to compare
Returns:
whether these Objects are semantically equal

floatValue

public float floatValue()
Return the value of this VeryLong as a float.

Specified by:
floatValue in class Number
Returns:
the float value (higher bits may be truncated)

hashCode

public int hashCode()
Return a hashcode representing this Object.

Overrides:
hashCode in class Object
Returns:
this Object's hash code

intValue

public int intValue()
Return the value of this VeryLong as an integer.

Specified by:
intValue in class Number
Returns:
the int value (higher bits may be truncated)

longValue

public long longValue()
Return the value of this VeryLong as a long integer.

Specified by:
longValue in class Number
Returns:
the long integer value (higher bits may be truncated)

negate

public VeryLong negate()
Returns a VeryLong whose value is (-this).

Returns:
-this

parseVeryLong

public static VeryLong parseVeryLong(String s)
Converts the specified String into a VeryLong, presented as a VeryLong because Java doesn't have a primitive VeryLong type.  This function assumes a radix of 10.

Parameters:
s - the String to convert
Returns:
the String argument converted to a VeryLong, represented as a VeryLong
Throws:
NumberFormatException - if s cannot be parsed as a VeryLong

parseVeryLong

public static VeryLong parseVeryLong(String s,
                                     int radix)
Converts the specified String into a VeryLong, presented as a VeryLong because Java doesn't have a primitive VeryLong type, using the specified radix (base).  The string must not be null or empty.  It may begin with an optional minus sign ("-"), which will negate the answer, provided that there are also valid digits.  Each digit is parsed as if by Character.digit(d, radix), and must be in the range 0 to radix - 1.  Finally, the result must be within MIN_VALUE to MAX_VALUE, inclusive.  Unlike Double.parseDouble, you may not have a leading plus sign ("+").

Parameters:
s - the String to convert
radix - the radix (base) to use in the conversion
Returns:
the String argument converted to a VeryLong, represented as a VeryLong
Throws:
NumberFormatException - if s cannot be parsed as a VeryLong

shortValue

public short shortValue()
Return the value of this VeryLong as a short.

Overrides:
shortValue in class Number
Returns:
the short integer value (higher bits may be truncated)

toByteArray

public byte[] toByteArray()
Return the value of this VeryLong as a byte[] array.

Returns:
the byte[] array

toString

public String toString()
Converts the VeryLong value to a String and assumes a radix of 10.

Overrides:
toString in class Object
Returns:
the String representation of this VeryLong.
See Also:
BigInteger.toString()

toString

public String toString(int radix)
Converts the VeryLong value to a String, using the specified radix.

Parameters:
radix - radix of the String representation
Returns:
the String representation of this VeryLong.
See Also:
BigInteger.toString()

toString

public static String toString(VeryLong veryLong)
Converts the VeryLong to a String and assumes a radix of 10.

Parameters:
veryLong - the BigInteger representing a VeryLong to convert to String
Returns:
the String representation of the argument
Throws:
NumberFormatException - if value is out of range

valueOf

public static VeryLong valueOf(String s)
Creates a new VeryLong object using the String and assuming a radix of 10.

Parameters:
s - the String to convert
Returns:
the new VeryLong
Throws:
NumberFormatException - if s cannot be parsed as a VeryLong
See Also:
VeryLong(String), parseVeryLong(String, int)

valueOf

public static VeryLong valueOf(String s,
                               int radix)
Creates a new VeryLong object using the String and specified radix (base).

Parameters:
s - the String to convert
radix - the radix (base) to convert with
Returns:
the new VeryLong
Throws:
NumberFormatException - if s cannot be parsed as a nybble
See Also:
parseVeryLong(String, int)