public final class VeryLong
extends Number
implements Comparable
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.
| Modifier and Type | Field and Description |
|---|---|
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 and Description |
|---|
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. |
| Modifier and Type | Method and Description |
|---|---|
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). |
public static final java.math.BigInteger MAX_VALUE
VeryLong can represent;
170141183460469231731687303715884105727 (or 2127 -1).public static final java.math.BigInteger MIN_VALUE
VaryLong can represent;
-170141183460469231731687303715884105728 (or -2127).public static final int SIZE
VeryLong.public static final int SIZE8
VeryLong.public static final String VERSION
public VeryLong(java.math.BigInteger b)
VeryLong object representing the converted value of
the BigInteger argument. If the value is out of range,
then an exception will be thrown.b - the BigInteger object to convertNumberFormatException - if the BigInteger is out of rangepublic VeryLong(byte[] value)
VeryLong object representing the value of the
byte argument.value - the byte array representing the value to useNumberFormatException - if value is out of rangepublic VeryLong(int value)
VeryLong object representing the value of the
int argument.value - the value to usepublic VeryLong(String s)
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.s - the string to convertNumberFormatException - if the string does not contain a VeryLong valuevalueOf(String)public VeryLong(String s,
int radix)
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.s - the string to convertradix - radix (base) to be used in interpretingNumberFormatException - if the string does not contain a VeryLong valuevalueOf(String)public java.math.BigInteger bigIntegerValue()
VeryLong as a BigInteger
object.public static VeryLong coerce(java.math.BigInteger value)
value - The byte valuepublic int compareTo(Object o)
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.compareTo in interface Comparableo - the Object to compareClassCastException - if the argument is not a
VeryLongpublic int compareTo(VeryLong n)
VeryLong
values. The result is positive if the first is greater, negative if
the second is greater, and 0 if the two are equal.n - the VeryLong to comparepublic double doubleValue()
VeryLong as a double.doubleValue in class Numberpublic boolean equals(Object obj)
true if obj is an instance of
VeryLong and represents the same VeryLong value.equals in class Objectobj - the object to comparepublic float floatValue()
VeryLong as a float.floatValue in class Numberpublic int hashCode()
hashCode in class Objectpublic int intValue()
VeryLong as an integer.intValue in class Numberpublic long longValue()
VeryLong as a long
integer.longValue in class Numberpublic VeryLong negate()
public static VeryLong parseVeryLong(String s)
String into a VeryLong,
presented as a VeryLong because Java doesn't have a primitive VeryLong
type. This function assumes a radix of 10.s - the String to convertString argument converted to a
VeryLong, represented as a VeryLongNumberFormatException - if s cannot be parsed as a
VeryLongpublic static VeryLong parseVeryLong(String s, int radix)
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 ("+").s - the String to convertradix - the radix (base) to use in the conversionString argument converted to a
VeryLong, represented as a VeryLongNumberFormatException - if s cannot be parsed as a
VeryLongpublic short shortValue()
VeryLong as a short.shortValue in class Numberpublic byte[] toByteArray()
VeryLong as a byte[]
array.public String toString()
VeryLong value to a String and
assumes a radix of 10.toString in class ObjectString representation of this VeryLong.BigInteger.toString()public String toString(int radix)
VeryLong value to a String, using
the specified radix.radix - radix of the String representationString representation of this VeryLong.BigInteger.toString()public static String toString(VeryLong veryLong)
VeryLong to a String and assumes a
radix of 10.veryLong - the BigInteger representing a VeryLong to
convert to StringString representation of the argumentNumberFormatException - if value is out of rangepublic static VeryLong valueOf(String s)
VeryLong object using the String
and assuming a radix of 10.s - the String to convertVeryLongNumberFormatException - if s cannot be parsed as a
VeryLongVeryLong(String),
parseVeryLong(String, int)public static VeryLong valueOf(String s, int radix)
VeryLong object using the String
and specified radix (base).s - the String to convertradix - the radix (base) to convert withVeryLongNumberFormatException - if s cannot be parsed as a
nybbleparseVeryLong(String, int)