Package com.google.common.primitives
Class UnsignedInteger
- java.lang.Object
- 
- java.lang.Number
- 
- com.google.common.primitives.UnsignedInteger
 
 
- 
- All Implemented Interfaces:
- java.io.Serializable,- java.lang.Comparable<UnsignedInteger>
 
 @GwtCompatible(emulated=true) public final class UnsignedInteger extends java.lang.Number implements java.lang.Comparable<UnsignedInteger> A wrapper class for unsignedintvalues, supporting arithmetic operations.In some cases, when speed is more important than code readability, it may be faster simply to treat primitive intvalues as unsigned, using the methods fromUnsignedInts.See the Guava User Guide article on unsigned primitive utilities. - Since:
- 11.0
- Author:
- Louis Wasserman
- See Also:
- Serialized Form
 
- 
- 
Field SummaryFields Modifier and Type Field Description static UnsignedIntegerMAX_VALUEstatic UnsignedIntegerONEstatic UnsignedIntegerZERO
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.math.BigIntegerbigIntegerValue()Returns the value of thisUnsignedIntegeras aBigInteger.intcompareTo(UnsignedInteger other)Compares this unsigned integer to another unsigned integer.UnsignedIntegerdividedBy(UnsignedInteger val)Returns the result of dividing this byval.doubledoubleValue()Returns the value of thisUnsignedIntegeras afloat, analogous to a widening primitive conversion frominttodouble, and correctly rounded.booleanequals(java.lang.Object obj)floatfloatValue()Returns the value of thisUnsignedIntegeras afloat, analogous to a widening primitive conversion frominttofloat, and correctly rounded.static UnsignedIntegerfromIntBits(int bits)Returns anUnsignedIntegercorresponding to a given bit representation.inthashCode()intintValue()Returns the value of thisUnsignedIntegeras anint.longlongValue()Returns the value of thisUnsignedIntegeras along.UnsignedIntegerminus(UnsignedInteger val)Returns the result of subtracting this andval.UnsignedIntegermod(UnsignedInteger val)Returns this modval.UnsignedIntegerplus(UnsignedInteger val)Returns the result of adding this andval.UnsignedIntegertimes(UnsignedInteger val)Returns the result of multiplying this andval.java.lang.StringtoString()Returns a string representation of theUnsignedIntegervalue, in base 10.java.lang.StringtoString(int radix)Returns a string representation of theUnsignedIntegervalue, in baseradix.static UnsignedIntegervalueOf(long value)Returns anUnsignedIntegerthat is equal tovalue, if possible.static UnsignedIntegervalueOf(java.lang.String string)Returns anUnsignedIntegerholding the value of the specifiedString, parsed as an unsignedintvalue.static UnsignedIntegervalueOf(java.lang.String string, int radix)Returns anUnsignedIntegerholding the value of the specifiedString, parsed as an unsignedintvalue in the specified radix.static UnsignedIntegervalueOf(java.math.BigInteger value)Returns aUnsignedIntegerrepresenting the same value as the specifiedBigInteger.
 
- 
- 
- 
Field Detail- 
ZEROpublic static final UnsignedInteger ZERO 
 - 
ONEpublic static final UnsignedInteger ONE 
 - 
MAX_VALUEpublic static final UnsignedInteger MAX_VALUE 
 
- 
 - 
Method Detail- 
fromIntBitspublic static UnsignedInteger fromIntBits(int bits) Returns anUnsignedIntegercorresponding to a given bit representation. The argument is interpreted as an unsigned 32-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^32 + bits.To represent unsigned decimal constants, consider valueOf(long)instead.- Since:
- 14.0
 
 - 
valueOfpublic static UnsignedInteger valueOf(long value) Returns anUnsignedIntegerthat is equal tovalue, if possible. The inverse operation oflongValue().
 - 
valueOfpublic static UnsignedInteger valueOf(java.math.BigInteger value) Returns aUnsignedIntegerrepresenting the same value as the specifiedBigInteger. This is the inverse operation ofbigIntegerValue().- Throws:
- java.lang.IllegalArgumentException- if- valueis negative or- value >= 2^32
 
 - 
valueOfpublic static UnsignedInteger valueOf(java.lang.String string) Returns anUnsignedIntegerholding the value of the specifiedString, parsed as an unsignedintvalue.- Throws:
- java.lang.NumberFormatException- if the string does not contain a parsable unsigned- intvalue
 
 - 
valueOfpublic static UnsignedInteger valueOf(java.lang.String string, int radix) Returns anUnsignedIntegerholding the value of the specifiedString, parsed as an unsignedintvalue in the specified radix.- Throws:
- java.lang.NumberFormatException- if the string does not contain a parsable unsigned- intvalue
 
 - 
pluspublic UnsignedInteger plus(UnsignedInteger val) Returns the result of adding this andval. If the result would have more than 32 bits, returns the low 32 bits of the result.- Since:
- 14.0
 
 - 
minuspublic UnsignedInteger minus(UnsignedInteger val) Returns the result of subtracting this andval. If the result would be negative, returns the low 32 bits of the result.- Since:
- 14.0
 
 - 
times@GwtIncompatible public UnsignedInteger times(UnsignedInteger val) Returns the result of multiplying this andval. If the result would have more than 32 bits, returns the low 32 bits of the result.- Since:
- 14.0
 
 - 
dividedBypublic UnsignedInteger dividedBy(UnsignedInteger val) Returns the result of dividing this byval.- Throws:
- java.lang.ArithmeticException- if- valis zero
- Since:
- 14.0
 
 - 
modpublic UnsignedInteger mod(UnsignedInteger val) Returns this modval.- Throws:
- java.lang.ArithmeticException- if- valis zero
- Since:
- 14.0
 
 - 
intValuepublic int intValue() Returns the value of thisUnsignedIntegeras anint. This is an inverse operation tofromIntBits(int).Note that if this UnsignedIntegerholds a value>= 2^31, the returned value will be equal tothis - 2^32.- Specified by:
- intValuein class- java.lang.Number
 
 - 
longValuepublic long longValue() Returns the value of thisUnsignedIntegeras along.- Specified by:
- longValuein class- java.lang.Number
 
 - 
floatValuepublic float floatValue() Returns the value of thisUnsignedIntegeras afloat, analogous to a widening primitive conversion frominttofloat, and correctly rounded.- Specified by:
- floatValuein class- java.lang.Number
 
 - 
doubleValuepublic double doubleValue() Returns the value of thisUnsignedIntegeras afloat, analogous to a widening primitive conversion frominttodouble, and correctly rounded.- Specified by:
- doubleValuein class- java.lang.Number
 
 - 
bigIntegerValuepublic java.math.BigInteger bigIntegerValue() Returns the value of thisUnsignedIntegeras aBigInteger.
 - 
compareTopublic int compareTo(UnsignedInteger other) Compares this unsigned integer to another unsigned integer. Returns0if they are equal, a negative number ifthis < other, and a positive number ifthis > other.- Specified by:
- compareToin interface- java.lang.Comparable<UnsignedInteger>
 
 - 
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 theUnsignedIntegervalue, in base 10.- Overrides:
- toStringin class- java.lang.Object
 
 - 
toStringpublic java.lang.String toString(int radix) Returns a string representation of theUnsignedIntegervalue, in baseradix. Ifradix < Character.MIN_RADIXorradix > Character.MAX_RADIX, the radix10is used.
 
- 
 
-