long primitives that interpret values as
unsigned (that is, any negative value x is treated as the positive value 2^64 + x). The methods for which signedness is not an issue are in Longs, as well as
signed versions of methods for which signedness is an issue.
In addition, this class provides several static methods for converting a long to a
String and a String to a long that treat the long as an unsigned
number.
Users of these utilities must be extremely careful not to mix up signed and unsigned
long values. When possible, it is recommended that the UnsignedLong wrapper class
be used, at a small efficiency penalty, to enforce the distinction in the type system.
See the Guava User Guide article on unsigned primitive utilities.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static enum | |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| public static final long |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static int | Returns: a negative value ifa is less than b; a positive value if a is
greater than b; or zero if they are equalthe first unsigned a, long long to comparethe second unsigned b)long to compareCompares the two specified |
| public static long | |
| public static long | divide(long
the dividend (numerator) dividend, long the divisor (denominator) divisor)Returns dividend / divisor, where the dividend and divisor are treated as unsigned 64-bit quantities. |
| private static long | flip(long a)
A (self-inverse) bijection which converts the ordering on unsigned longs to the ordering on
longs, that is, |
| public static String | |
| public static Comparator | lexicographicalComparator()
Returns a comparator that compares two arrays of unsigned |
| public static long | |
| public static long | |
| public static long | parseUnsignedLong(String string)
Returns the unsigned |
| public static long | parseUnsignedLong(String
the string containing the unsigned string, int long representation to be parsed.the radix to use while parsing radix)stringReturns the unsigned |
| public static long | remainder(long
the dividend (numerator) dividend, long the divisor (denominator) divisor)Returns dividend % divisor, where the dividend and divisor are treated as unsigned 64-bit quantities. |
| public static void | |
| public static void | sort(long[] array, int fromIndex, int toIndex)
Sorts the array between |
| public static void | sortDescending(long[] array)
Sorts the elements of |
| public static void | sortDescending(long[] array, int fromIndex, int toIndex)
Sorts the elements of |
| public static String | |
| public static String | toString(long
the value to convert to a string. x, int the radix to use while working with radix)xReturns a string representation of |
| MAX_VALUE | back to summary |
|---|---|
| public static final long MAX_VALUE | |
| UnsignedLongs | back to summary |
|---|---|
| private UnsignedLongs() | |
| compare | back to summary |
|---|---|
| public static int compare(long a, long b) Compares the two specified Java 8+ users: use
| |
| decode | back to summary |
|---|---|
| public static long decode(String stringValue) Returns the unsigned Accepts a decimal, hexadecimal, or octal number given by specifying the following prefix:
| |
| divide | back to summary |
|---|---|
| public static long divide(long dividend, long divisor) Returns dividend / divisor, where the dividend and divisor are treated as unsigned 64-bit quantities. Java 8+ users: use
| |
| flip | back to summary |
|---|---|
| private static long flip(long a) A (self-inverse) bijection which converts the ordering on unsigned longs to the ordering on
longs, that is, | |
| join | back to summary |
|---|---|
| public static String join(String separator, long... array) Returns a string containing the supplied unsigned
| |
| lexicographicalComparator | back to summary |
|---|---|
| public static Comparator Returns a comparator that compares two arrays of unsigned The returned comparator is inconsistent with | |
| max | back to summary |
|---|---|
| public static long max(long... array) Returns the greatest value present in
| |
| min | back to summary |
|---|---|
| public static long min(long... array) Returns the least value present in
| |
| parseUnsignedLong | back to summary |
|---|---|
| public static long parseUnsignedLong(String string) Returns the unsigned Java 8+ users: use
| |
| parseUnsignedLong | back to summary |
|---|---|
| public static long parseUnsignedLong(String string, int radix) Returns the unsigned Java 8+ users: use
| |
| remainder | back to summary |
|---|---|
| public static long remainder(long dividend, long divisor) Returns dividend % divisor, where the dividend and divisor are treated as unsigned 64-bit quantities. Java 8+ users: use
| |
| sort | back to summary |
|---|---|
| public static void sort(long[] array) Sorts the array, treating its elements as unsigned 64-bit integers.
| |
| sort | back to summary |
|---|---|
| public static void sort(long[] array, int fromIndex, int toIndex) Sorts the array between
| |
| sortDescending | back to summary |
|---|---|
| public static void sortDescending(long[] array) Sorts the elements of
| |
| sortDescending | back to summary |
|---|---|
| public static void sortDescending(long[] array, int fromIndex, int toIndex) Sorts the elements of
| |
| toString | back to summary |
|---|---|
| public static String toString(long x) Returns a string representation of x, where x is treated as unsigned. Java 8+ users: use | |
| toString | back to summary |
|---|---|
| public static String toString(long x, int radix) Returns a string representation of Java 8+ users: use
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final UnsignedLongs. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public int | compare(long[]
the first object to be compared. left, long[] the second object to be compared. right)Implements java. |
| public String | toString()
Overrides java. |
| public static UnsignedLongs. | |
| public static UnsignedLongs. |
| INSTANCE | back to summary |
|---|---|
| public static final UnsignedLongs. | |
| LexicographicalComparator | back to summary |
|---|---|
| private LexicographicalComparator() | |
| compare | back to summary |
|---|---|
| public int compare(long[] left, long[] right) Implements java. Doc from java. Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
The implementor must ensure that
The implementor must also ensure that the relation is transitive:
Finally, the implementor must ensure that
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists. | |
| valueOf | back to summary |
|---|---|
| public static UnsignedLongs. | |
| values | back to summary |
|---|---|
| public static UnsignedLongs. | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final int[] | |
| pack-priv static final long[] | |
| pack-priv static final int[] |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv static boolean | overflowInParse(long current, int digit, int radix)
Returns true if (current * radix) + digit is a number too large to be represented by an unsigned long. |
| maxSafeDigits | back to summary |
|---|---|
| pack-priv static final int[] maxSafeDigits | |
| maxValueDivs | back to summary |
|---|---|
| pack-priv static final long[] maxValueDivs | |
| maxValueMods | back to summary |
|---|---|
| pack-priv static final int[] maxValueMods | |
| ParseOverflowDetection | back to summary |
|---|---|
| private ParseOverflowDetection() | |
| overflowInParse | back to summary |
|---|---|
| pack-priv static boolean overflowInParse(long current, int digit, int radix) Returns true if (current * radix) + digit is a number too large to be represented by an unsigned long. This is useful for detecting overflow while parsing a string representation of a number. Does not verify whether supplied radix is valid, passing an invalid radix will give undefined results or an ArrayIndexOutOfBoundsException. | |