int primitives that interpret values as
unsigned (that is, any negative value x is treated as the positive value 2^32 + x). The methods for which signedness is not an issue are in Ints, as well as
signed versions of methods for which signedness is an issue.
In addition, this class provides several static methods for converting an int to a
String and a String to an int that treat the int as an unsigned
number.
Users of these utilities must be extremely careful not to mix up signed and unsigned
int values. When possible, it is recommended that the UnsignedInteger 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 |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final long |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static int | Returns: theint value that, when treated as unsigned, equals valuea value between 0 and 232-1 inclusive value)Returns the |
| 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, int int to comparethe second unsigned b)int to compareCompares the two specified |
| public static int | |
| public static int | divide(int
the dividend (numerator) dividend, int the divisor (denominator) divisor)Returns dividend / divisor, where the dividend and divisor are treated as unsigned 32-bit quantities. |
| pack-priv static int | |
| public static String | |
| public static Comparator | lexicographicalComparator()
Returns a comparator that compares two arrays of unsigned |
| public static int | |
| public static int | |
| public static int | |
| public static int | parseUnsignedInt(String
the string containing the unsigned integer representation to be parsed. string, int radix)Returns the unsigned |
| public static int | remainder(int
the dividend (numerator) dividend, int the divisor (denominator) divisor)Returns dividend % divisor, where the dividend and divisor are treated as unsigned 32-bit quantities. |
| public static int | Returns: 2^32 - 1 if value >= 2^32, 0 if value <= 0, and value cast to int otherwiseany value)long valueReturns the |
| public static void | |
| public static void | sort(int[] array, int fromIndex, int toIndex)
Sorts the array between |
| public static void | sortDescending(int[] array)
Sorts the elements of |
| public static void | sortDescending(int[] array, int fromIndex, int toIndex)
Sorts the elements of |
| public static long | |
| public static String | |
| public static String | toString(int
the value to convert to a string. x, int the radix to use while working with radix)xReturns a string representation of |
| INT_MASK | back to summary |
|---|---|
| pack-priv static final long INT_MASK | |
| UnsignedInts | back to summary |
|---|---|
| private UnsignedInts() | |
| checkedCast | back to summary |
|---|---|
| public static int checkedCast(long value) Returns the
| |
| compare | back to summary |
|---|---|
| public static int compare(int a, int b) Compares the two specified Java 8+ users: use
| |
| decode | back to summary |
|---|---|
| public static int 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 int divide(int dividend, int divisor) Returns dividend / divisor, where the dividend and divisor are treated as unsigned 32-bit quantities. Java 8+ users: use
| |
| flip | back to summary |
|---|---|
| pack-priv static int flip(int value) | |
| join | back to summary |
|---|---|
| public static String join(String separator, int... 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 int max(int... array) Returns the greatest value present in
| |
| min | back to summary |
|---|---|
| public static int min(int... array) Returns the least value present in
| |
| parseUnsignedInt | back to summary |
|---|---|
| public static int parseUnsignedInt(String s) Returns the unsigned Java 8+ users: use
| |
| parseUnsignedInt | back to summary |
|---|---|
| public static int parseUnsignedInt(String string, int radix) Returns the unsigned Java 8+ users: use
| |
| remainder | back to summary |
|---|---|
| public static int remainder(int dividend, int divisor) Returns dividend % divisor, where the dividend and divisor are treated as unsigned 32-bit quantities. Java 8+ users: use
| |
| saturatedCast | back to summary |
|---|---|
| public static int saturatedCast(long value) Returns the
| |
| sort | back to summary |
|---|---|
| public static void sort(int[] array) Sorts the array, treating its elements as unsigned 32-bit integers.
| |
| sort | back to summary |
|---|---|
| public static void sort(int[] array, int fromIndex, int toIndex) Sorts the array between
| |
| sortDescending | back to summary |
|---|---|
| public static void sortDescending(int[] array) Sorts the elements of
| |
| sortDescending | back to summary |
|---|---|
| public static void sortDescending(int[] array, int fromIndex, int toIndex) Sorts the elements of
| |
| toLong | back to summary |
|---|---|
| public static long toLong(int value) Returns the value of the given Java 8+ users: use | |
| toString | back to summary |
|---|---|
| public static String toString(int 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(int x, int radix) Returns a string representation of Java 8+ users: use
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final UnsignedInts. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public int | compare(int[]
the first object to be compared. left, int[] the second object to be compared. right)Implements java. |
| public String | toString()
Overrides java. |
| public static UnsignedInts. | |
| public static UnsignedInts. |
| INSTANCE | back to summary |
|---|---|
| public static final UnsignedInts. | |
| LexicographicalComparator | back to summary |
|---|---|
| private LexicographicalComparator() | |
| compare | back to summary |
|---|---|
| public int compare(int[] left, int[] 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 UnsignedInts. | |
| values | back to summary |
|---|---|
| public static UnsignedInts. | |