Top Description Fields Constructors Methods
com.google.common.primitives

public final Class UnsignedInteger

extends Number
implements Comparable<UnsignedInteger>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Annotations
@GwtCompatible
emulated:true
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull, com.google.common.primitives.UnsignedInts.INT_MASK, .UnsignedInts.compare, .UnsignedInts.toLong

A wrapper class for unsigned int values, supporting arithmetic operations.

In some cases, when speed is more important than code readability, it may be faster simply to treat primitive int values as unsigned, using the methods from UnsignedInts.

See the Guava User Guide article on unsigned primitive utilities.

Author
Louis Wasserman
Since
11.0

Field Summary

Modifier and TypeField and Description
public static final UnsignedInteger
public static final UnsignedInteger
private final int
public static final UnsignedInteger

Constructor Summary

AccessConstructor and Description
private
UnsignedInteger(int value)

Method Summary

Modifier and TypeMethod and Description
public BigInteger
bigIntegerValue()

Returns the value of this UnsignedInteger as a BigInteger.

public int
compareTo(UnsignedInteger
the object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

Compares this unsigned integer to another unsigned integer.
public UnsignedInteger
dividedBy(UnsignedInteger val)

Returns the result of dividing this by val.

public double
doubleValue()

Implements abstract java.lang.Number.doubleValue.

Returns the value of this UnsignedInteger as a float, analogous to a widening primitive conversion from int to double, and correctly rounded.
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public float
floatValue()

Implements abstract java.lang.Number.floatValue.

Returns the value of this UnsignedInteger as a float, analogous to a widening primitive conversion from int to float, and correctly rounded.
public static UnsignedInteger
fromIntBits(int bits)

Returns an UnsignedInteger corresponding to a given bit representation.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public int
intValue()

Implements abstract java.lang.Number.intValue.

Returns the value of this UnsignedInteger as an int.
public long
longValue()

Implements abstract java.lang.Number.longValue.

Returns the value of this UnsignedInteger as a long.
public UnsignedInteger
minus(UnsignedInteger val)

Returns the result of subtracting this and val.

public UnsignedInteger
mod(UnsignedInteger val)

Returns this mod val.

public UnsignedInteger
plus(UnsignedInteger val)

Returns the result of adding this and val.

public UnsignedInteger
times(UnsignedInteger val)

Returns the result of multiplying this and val.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the UnsignedInteger value, in base 10.
public String
toString(int radix)

Returns a string representation of the UnsignedInteger value, in base radix.

public static UnsignedInteger
valueOf(long value)

Returns an UnsignedInteger that is equal to value, if possible.

public static UnsignedInteger
valueOf(BigInteger value)

Returns a UnsignedInteger representing the same value as the specified BigInteger.

public static UnsignedInteger
valueOf(String string)

Returns an UnsignedInteger holding the value of the specified String, parsed as an unsigned int value.

public static UnsignedInteger
valueOf(String string, int radix)

Returns an UnsignedInteger holding the value of the specified String, parsed as an unsigned int value in the specified radix.

Inherited from java.lang.Number:
byteValueshortValue

Field Detail

MAX_VALUEback to summary
public static final UnsignedInteger MAX_VALUE
ONEback to summary
public static final UnsignedInteger ONE
valueback to summary
private final int value
ZEROback to summary
public static final UnsignedInteger ZERO

Constructor Detail

UnsignedIntegerback to summary
private UnsignedInteger(int value)

Method Detail

bigIntegerValueback to summary
public BigInteger bigIntegerValue()

Returns the value of this UnsignedInteger as a BigInteger.

compareToback to summary
public int compareTo(UnsignedInteger other)

Implements java.lang.Comparable.compareTo.

Compares this unsigned integer to another unsigned integer. Returns 0 if they are equal, a negative number if this < other, and a positive number if this > other.

Parameters
other:UnsignedInteger

Doc from java.lang.Comparable.compareTo.

the object to be compared.

Returns:int

Doc from java.lang.Comparable.compareTo.

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
dividedByback to summary
public UnsignedInteger dividedBy(UnsignedInteger val)

Returns the result of dividing this by val.

Exceptions
ArithmeticException:
if val is zero
Since
14.0
doubleValueback to summary
public double doubleValue()

Implements abstract java.lang.Number.doubleValue.

Returns the value of this UnsignedInteger as a float, analogous to a widening primitive conversion from int to double, and correctly rounded.

Returns:double

Doc from java.lang.Number.doubleValue.

the numeric value represented by this object after conversion to type double.

Annotations
@Override
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
floatValueback to summary
public float floatValue()

Implements abstract java.lang.Number.floatValue.

Returns the value of this UnsignedInteger as a float, analogous to a widening primitive conversion from int to float, and correctly rounded.

Returns:float

Doc from java.lang.Number.floatValue.

the numeric value represented by this object after conversion to type float.

Annotations
@Override
fromIntBitsback to summary
public static UnsignedInteger fromIntBits(int bits)

Returns an UnsignedInteger corresponding to a given bit representation. The argument is interpreted as an unsigned 32-bit value. Specifically, the sign bit of bits is interpreted as a normal bit, and all other bits are treated as usual.

If the argument is nonnegative, the returned result will be equal to bits, otherwise, the result will be equal to 2^32 + bits.

To represent unsigned decimal constants, consider valueOf(long) instead.

Since
14.0
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
intValueback to summary
public int intValue()

Implements abstract java.lang.Number.intValue.

Returns the value of this UnsignedInteger as an int. This is an inverse operation to fromIntBits.

Note that if this UnsignedInteger holds a value >= 2^31, the returned value will be equal to this - 2^32.

Returns:int

Doc from java.lang.Number.intValue.

the numeric value represented by this object after conversion to type int.

Annotations
@Override
longValueback to summary
public long longValue()

Implements abstract java.lang.Number.longValue.

Returns the value of this UnsignedInteger as a long.

Returns:long

Doc from java.lang.Number.longValue.

the numeric value represented by this object after conversion to type long.

Annotations
@Override
minusback to summary
public UnsignedInteger minus(UnsignedInteger val)

Returns the result of subtracting this and val. If the result would be negative, returns the low 32 bits of the result.

Since
14.0
modback to summary
public UnsignedInteger mod(UnsignedInteger val)

Returns this mod val.

Exceptions
ArithmeticException:
if val is zero
Since
14.0
plusback to summary
public UnsignedInteger plus(UnsignedInteger val)

Returns the result of adding this and val. If the result would have more than 32 bits, returns the low 32 bits of the result.

Since
14.0
timesback to summary
public UnsignedInteger times(UnsignedInteger val)

Returns the result of multiplying this and val. If the result would have more than 32 bits, returns the low 32 bits of the result.

Annotations
@J2ktIncompatible
@GwtIncompatible
Since
14.0
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of the UnsignedInteger value, in base 10.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override
toStringback to summary
public String toString(int radix)

Returns a string representation of the UnsignedInteger value, in base radix. If radix < Character.MIN_RADIX or radix > Character.MAX_RADIX, the radix 10 is used.

valueOfback to summary
public static UnsignedInteger valueOf(long value)

Returns an UnsignedInteger that is equal to value, if possible. The inverse operation of longValue().

valueOfback to summary
public static UnsignedInteger valueOf(BigInteger value)

Returns a UnsignedInteger representing the same value as the specified BigInteger. This is the inverse operation of bigIntegerValue().

Exceptions
IllegalArgumentException:
if value is negative or value >= 2^32
valueOfback to summary
public static UnsignedInteger valueOf(String string)

Returns an UnsignedInteger holding the value of the specified String, parsed as an unsigned int value.

Exceptions
NumberFormatException:
if the string does not contain a parsable unsigned int value
valueOfback to summary
public static UnsignedInteger valueOf(String string, int radix)

Returns an UnsignedInteger holding the value of the specified String, parsed as an unsigned int value in the specified radix.

Exceptions
NumberFormatException:
if the string does not contain a parsable unsigned int value