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

public final Class UnsignedLong

extends Number
implements Comparable<UnsignedLong>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Comparable
Annotations
@GwtCompatible
serializable:true
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull

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

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

See the Guava User Guide article on unsigned primitive utilities.

Authors
Louis Wasserman, Colin Evans
Since
11.0

Field Summary

Modifier and TypeField and Description
public static final UnsignedLong
public static final UnsignedLong
private static final long
private final long
public static final UnsignedLong

Constructor Summary

AccessConstructor and Description
private
UnsignedLong(long value)

Method Summary

Modifier and TypeMethod and Description
public BigInteger
bigIntegerValue()

Returns the value of this UnsignedLong as a BigInteger.

public int
compareTo(UnsignedLong
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
public UnsignedLong
dividedBy(UnsignedLong val)

Returns the result of dividing this by val.

public double
doubleValue()

Implements abstract java.lang.Number.doubleValue.

Returns the value of this UnsignedLong as a double, analogous to a widening primitive conversion from long 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 UnsignedLong as a float, analogous to a widening primitive conversion from long to float, and correctly rounded.
public static UnsignedLong
fromLongBits(long bits)

Returns an UnsignedLong corresponding to a given bit representation.

public int
hashCode()

Overrides java.lang.Object.hashCode.

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

Implements abstract java.lang.Number.intValue.

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

Implements abstract java.lang.Number.longValue.

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

Returns the result of subtracting this and val.

public UnsignedLong
mod(UnsignedLong val)

Returns this modulo val.

public UnsignedLong
plus(UnsignedLong val)

Returns the result of adding this and val.

public UnsignedLong
times(UnsignedLong val)

Returns the result of multiplying this and val.

public String
toString()

Overrides java.lang.Object.toString.

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

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

public static UnsignedLong
valueOf(long value)

Returns an UnsignedLong representing the same value as the specified long.

public static UnsignedLong
valueOf(BigInteger value)

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

public static UnsignedLong
valueOf(String string)

Returns an UnsignedLong holding the value of the specified String, parsed as an unsigned long value.

public static UnsignedLong
valueOf(String string, int radix)

Returns an UnsignedLong holding the value of the specified String, parsed as an unsigned long value in the specified radix.

Inherited from java.lang.Number:
byteValueshortValue

Field Detail

MAX_VALUEback to summary
public static final UnsignedLong MAX_VALUE
ONEback to summary
public static final UnsignedLong ONE
UNSIGNED_MASKback to summary
private static final long UNSIGNED_MASK
valueback to summary
private final long value
ZEROback to summary
public static final UnsignedLong ZERO

Constructor Detail

UnsignedLongback to summary
private UnsignedLong(long value)

Method Detail

bigIntegerValueback to summary
public BigInteger bigIntegerValue()

Returns the value of this UnsignedLong as a BigInteger.

compareToback to summary
public int compareTo(UnsignedLong o)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
o:UnsignedLong

the object to be compared.

Returns:int

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 UnsignedLong dividedBy(UnsignedLong val)

Returns the result of dividing this by val.

Since
14.0
doubleValueback to summary
public double doubleValue()

Implements abstract java.lang.Number.doubleValue.

Returns the value of this UnsignedLong as a double, analogous to a widening primitive conversion from long 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 UnsignedLong as a float, analogous to a widening primitive conversion from long 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
fromLongBitsback to summary
public static UnsignedLong fromLongBits(long bits)

Returns an UnsignedLong corresponding to a given bit representation. The argument is interpreted as an unsigned 64-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^64 + bits.

To represent decimal constants less than 2^63, 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 the 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 UnsignedLong as an int.

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 UnsignedLong as a long. This is an inverse operation to fromLongBits.

Note that if this UnsignedLong holds a value >= 2^63, the returned value will be equal to this - 2^64.

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 UnsignedLong minus(UnsignedLong val)

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

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

Returns this modulo val.

Since
14.0
plusback to summary
public UnsignedLong plus(UnsignedLong val)

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

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

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

Since
14.0
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of the UnsignedLong 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 UnsignedLong value, in base radix. If radix < Character.MIN_RADIX or radix > Character.MAX_RADIX, the radix 10 is used.

valueOfback to summary
public static UnsignedLong valueOf(long value)

Returns an UnsignedLong representing the same value as the specified long.

Annotations
@CanIgnoreReturnValue
Exceptions
IllegalArgumentException:
if value is negative
Since
14.0
valueOfback to summary
public static UnsignedLong valueOf(BigInteger value)

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

Annotations
@CanIgnoreReturnValue
Exceptions
IllegalArgumentException:
if value is negative or value >= 2^64
valueOfback to summary
public static UnsignedLong valueOf(String string)

Returns an UnsignedLong holding the value of the specified String, parsed as an unsigned long value.

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

Returns an UnsignedLong holding the value of the specified String, parsed as an unsigned long value in the specified radix.

Annotations
@CanIgnoreReturnValue
Exceptions
NumberFormatException:
if the string does not contain a parsable unsigned long value, or radix is not between Character#MIN_RADIX and Character#MAX_RADIX