Package com.google.common.primitives
Class UnsignedLong
- java.lang.Object
-
- java.lang.Number
-
- com.google.common.primitives.UnsignedLong
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<UnsignedLong>
@GwtCompatible(serializable=true) public final class UnsignedLong extends java.lang.Number implements java.lang.Comparable<UnsignedLong>, java.io.Serializable
A wrapper class for unsignedlongvalues, supporting arithmetic operations.In some cases, when speed is more important than code readability, it may be faster simply to treat primitive
longvalues as unsigned, using the methods fromUnsignedLongs.See the Guava User Guide article on unsigned primitive utilities.
- Since:
- 11.0
- Author:
- Louis Wasserman, Colin Evans
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static UnsignedLongMAX_VALUEstatic UnsignedLongONEstatic UnsignedLongZERO
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.math.BigIntegerbigIntegerValue()Returns the value of thisUnsignedLongas aBigInteger.intcompareTo(UnsignedLong o)UnsignedLongdividedBy(UnsignedLong val)Returns the result of dividing this byval.doubledoubleValue()Returns the value of thisUnsignedLongas adouble, analogous to a widening primitive conversion fromlongtodouble, and correctly rounded.booleanequals(java.lang.Object obj)floatfloatValue()Returns the value of thisUnsignedLongas afloat, analogous to a widening primitive conversion fromlongtofloat, and correctly rounded.static UnsignedLongfromLongBits(long bits)Returns anUnsignedLongcorresponding to a given bit representation.inthashCode()intintValue()Returns the value of thisUnsignedLongas anint.longlongValue()Returns the value of thisUnsignedLongas along.UnsignedLongminus(UnsignedLong val)Returns the result of subtracting this andval.UnsignedLongmod(UnsignedLong val)Returns this moduloval.UnsignedLongplus(UnsignedLong val)Returns the result of adding this andval.UnsignedLongtimes(UnsignedLong val)Returns the result of multiplying this andval.java.lang.StringtoString()Returns a string representation of theUnsignedLongvalue, in base 10.java.lang.StringtoString(int radix)Returns a string representation of theUnsignedLongvalue, in baseradix.static UnsignedLongvalueOf(long value)Returns anUnsignedLongrepresenting the same value as the specifiedlong.static UnsignedLongvalueOf(java.lang.String string)Returns anUnsignedLongholding the value of the specifiedString, parsed as an unsignedlongvalue.static UnsignedLongvalueOf(java.lang.String string, int radix)Returns anUnsignedLongholding the value of the specifiedString, parsed as an unsignedlongvalue in the specified radix.static UnsignedLongvalueOf(java.math.BigInteger value)Returns aUnsignedLongrepresenting the same value as the specifiedBigInteger.
-
-
-
Field Detail
-
ZERO
public static final UnsignedLong ZERO
-
ONE
public static final UnsignedLong ONE
-
MAX_VALUE
public static final UnsignedLong MAX_VALUE
-
-
Method Detail
-
fromLongBits
public static UnsignedLong fromLongBits(long bits)
Returns anUnsignedLongcorresponding to a given bit representation. The argument is interpreted as an unsigned 64-bit value. Specifically, the sign bit ofbitsis 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 to2^64 + bits.To represent decimal constants less than
2^63, considervalueOf(long)instead.- Since:
- 14.0
-
valueOf
@CanIgnoreReturnValue public static UnsignedLong valueOf(long value)
Returns anUnsignedLongrepresenting the same value as the specifiedlong.- Throws:
java.lang.IllegalArgumentException- ifvalueis negative- Since:
- 14.0
-
valueOf
@CanIgnoreReturnValue public static UnsignedLong valueOf(java.math.BigInteger value)
Returns aUnsignedLongrepresenting the same value as the specifiedBigInteger. This is the inverse operation ofbigIntegerValue().- Throws:
java.lang.IllegalArgumentException- ifvalueis negative orvalue >= 2^64
-
valueOf
@CanIgnoreReturnValue public static UnsignedLong valueOf(java.lang.String string)
Returns anUnsignedLongholding the value of the specifiedString, parsed as an unsignedlongvalue.- Throws:
java.lang.NumberFormatException- if the string does not contain a parsable unsignedlongvalue
-
valueOf
@CanIgnoreReturnValue public static UnsignedLong valueOf(java.lang.String string, int radix)
Returns anUnsignedLongholding the value of the specifiedString, parsed as an unsignedlongvalue in the specified radix.- Throws:
java.lang.NumberFormatException- if the string does not contain a parsable unsignedlongvalue, orradixis not betweenCharacter.MIN_RADIXandCharacter.MAX_RADIX
-
plus
public UnsignedLong plus(UnsignedLong val)
Returns the result of adding this andval. If the result would have more than 64 bits, returns the low 64 bits of the result.- Since:
- 14.0
-
minus
public UnsignedLong minus(UnsignedLong val)
Returns the result of subtracting this andval. If the result would have more than 64 bits, returns the low 64 bits of the result.- Since:
- 14.0
-
times
public UnsignedLong times(UnsignedLong val)
Returns the result of multiplying this andval. If the result would have more than 64 bits, returns the low 64 bits of the result.- Since:
- 14.0
-
dividedBy
public UnsignedLong dividedBy(UnsignedLong val)
Returns the result of dividing this byval.- Since:
- 14.0
-
mod
public UnsignedLong mod(UnsignedLong val)
Returns this moduloval.- Since:
- 14.0
-
intValue
public int intValue()
Returns the value of thisUnsignedLongas anint.- Specified by:
intValuein classjava.lang.Number
-
longValue
public long longValue()
Returns the value of thisUnsignedLongas along. This is an inverse operation tofromLongBits(long).Note that if this
UnsignedLongholds a value>= 2^63, the returned value will be equal tothis - 2^64.- Specified by:
longValuein classjava.lang.Number
-
floatValue
public float floatValue()
Returns the value of thisUnsignedLongas afloat, analogous to a widening primitive conversion fromlongtofloat, and correctly rounded.- Specified by:
floatValuein classjava.lang.Number
-
doubleValue
public double doubleValue()
Returns the value of thisUnsignedLongas adouble, analogous to a widening primitive conversion fromlongtodouble, and correctly rounded.- Specified by:
doubleValuein classjava.lang.Number
-
bigIntegerValue
public java.math.BigInteger bigIntegerValue()
Returns the value of thisUnsignedLongas aBigInteger.
-
compareTo
public int compareTo(UnsignedLong o)
- Specified by:
compareToin interfacejava.lang.Comparable<UnsignedLong>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(@CheckForNull java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
Returns a string representation of theUnsignedLongvalue, in base 10.- Overrides:
toStringin classjava.lang.Object
-
toString
public java.lang.String toString(int radix)
Returns a string representation of theUnsignedLongvalue, in baseradix. Ifradix < Character.MIN_RADIXorradix > Character.MAX_RADIX, the radix10is used.
-
-