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 SummaryFields Modifier and Type Field Description static UnsignedLongMAX_VALUEstatic UnsignedLongONEstatic UnsignedLongZERO
 - 
Method SummaryAll 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- 
ZEROpublic static final UnsignedLong ZERO 
 - 
ONEpublic static final UnsignedLong ONE 
 - 
MAX_VALUEpublic static final UnsignedLong MAX_VALUE 
 
- 
 - 
Method Detail- 
fromLongBitspublic 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- if- valueis 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- if- valueis negative or- value >= 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 unsigned- longvalue
 
 - 
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 unsigned- longvalue, or- radixis not between- Character.MIN_RADIXand- Character.MAX_RADIX
 
 - 
pluspublic 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
 
 - 
minuspublic 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
 
 - 
timespublic 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
 
 - 
dividedBypublic UnsignedLong dividedBy(UnsignedLong val) Returns the result of dividing this byval.- Since:
- 14.0
 
 - 
modpublic UnsignedLong mod(UnsignedLong val) Returns this moduloval.- Since:
- 14.0
 
 - 
intValuepublic int intValue() Returns the value of thisUnsignedLongas anint.- Specified by:
- intValuein class- java.lang.Number
 
 - 
longValuepublic 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 class- java.lang.Number
 
 - 
floatValuepublic float floatValue() Returns the value of thisUnsignedLongas afloat, analogous to a widening primitive conversion fromlongtofloat, and correctly rounded.- Specified by:
- floatValuein class- java.lang.Number
 
 - 
doubleValuepublic double doubleValue() Returns the value of thisUnsignedLongas adouble, analogous to a widening primitive conversion fromlongtodouble, and correctly rounded.- Specified by:
- doubleValuein class- java.lang.Number
 
 - 
bigIntegerValuepublic java.math.BigInteger bigIntegerValue() Returns the value of thisUnsignedLongas aBigInteger.
 - 
compareTopublic int compareTo(UnsignedLong o) - Specified by:
- compareToin interface- java.lang.Comparable<UnsignedLong>
 
 - 
hashCodepublic int hashCode() - Overrides:
- hashCodein class- java.lang.Object
 
 - 
equalspublic boolean equals(@CheckForNull java.lang.Object obj) - Overrides:
- equalsin class- java.lang.Object
 
 - 
toStringpublic java.lang.String toString() Returns a string representation of theUnsignedLongvalue, in base 10.- Overrides:
- toStringin class- java.lang.Object
 
 - 
toStringpublic java.lang.String toString(int radix) Returns a string representation of theUnsignedLongvalue, in baseradix. Ifradix < Character.MIN_RADIXorradix > Character.MAX_RADIX, the radix10is used.
 
- 
 
-