Class 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 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.

    Since:
    11.0
    See Also:
    Serialized Form
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.math.BigInteger bigIntegerValue()
      Returns the value of this UnsignedLong as a BigInteger.
      int compareTo​(UnsignedLong o)  
      UnsignedLong dividedBy​(UnsignedLong val)
      Returns the result of dividing this by val.
      double doubleValue()
      Returns the value of this UnsignedLong as a double, analogous to a widening primitive conversion from long to double, and correctly rounded.
      boolean equals​(java.lang.Object obj)  
      float floatValue()
      Returns the value of this UnsignedLong as a float, analogous to a widening primitive conversion from long to float, and correctly rounded.
      static UnsignedLong fromLongBits​(long bits)
      Returns an UnsignedLong corresponding to a given bit representation.
      int hashCode()  
      int intValue()
      Returns the value of this UnsignedLong as an int.
      long longValue()
      Returns the value of this UnsignedLong as a long.
      UnsignedLong minus​(UnsignedLong val)
      Returns the result of subtracting this and val.
      UnsignedLong mod​(UnsignedLong val)
      Returns this modulo val.
      UnsignedLong plus​(UnsignedLong val)
      Returns the result of adding this and val.
      UnsignedLong times​(UnsignedLong val)
      Returns the result of multiplying this and val.
      java.lang.String toString()
      Returns a string representation of the UnsignedLong value, in base 10.
      java.lang.String toString​(int radix)
      Returns a string representation of the UnsignedLong value, in base radix.
      static UnsignedLong valueOf​(long value)
      Returns an UnsignedLong representing the same value as the specified long.
      static UnsignedLong valueOf​(java.lang.String string)
      Returns an UnsignedLong holding the value of the specified String, parsed as an unsigned long value.
      static UnsignedLong valueOf​(java.lang.String string, int radix)
      Returns an UnsignedLong holding the value of the specified String, parsed as an unsigned long value in the specified radix.
      static UnsignedLong valueOf​(java.math.BigInteger value)
      Returns a UnsignedLong representing the same value as the specified BigInteger.
      • Methods inherited from class java.lang.Number

        byteValue, shortValue
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • fromLongBits

        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
      • valueOf

        public static UnsignedLong valueOf​(long value)
        Returns an UnsignedLong representing the same value as the specified long.
        Throws:
        java.lang.IllegalArgumentException - if value is negative
        Since:
        14.0
      • valueOf

        public static UnsignedLong valueOf​(java.math.BigInteger value)
        Returns a UnsignedLong representing the same value as the specified BigInteger. This is the inverse operation of bigIntegerValue().
        Throws:
        java.lang.IllegalArgumentException - if value is negative or value >= 2^64
      • valueOf

        public static UnsignedLong valueOf​(java.lang.String string)
        Returns an UnsignedLong holding the value of the specified String, parsed as an unsigned long value.
        Throws:
        java.lang.NumberFormatException - if the string does not contain a parsable unsigned long value
      • valueOf

        public static UnsignedLong valueOf​(java.lang.String string,
                                           int radix)
        Returns an UnsignedLong holding the value of the specified String, parsed as an unsigned long value in the specified radix.
        Throws:
        java.lang.NumberFormatException - if the string does not contain a parsable unsigned long value, or radix is not between Character.MIN_RADIX and Character.MAX_RADIX
      • plus

        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
      • minus

        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
      • times

        @CheckReturnValue
        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
      • dividedBy

        @CheckReturnValue
        public UnsignedLong dividedBy​(UnsignedLong val)
        Returns the result of dividing this by val.
        Since:
        14.0
      • intValue

        public int intValue()
        Returns the value of this UnsignedLong as an int.
        Specified by:
        intValue in class java.lang.Number
      • longValue

        public long longValue()
        Returns the value of this UnsignedLong as a long. This is an inverse operation to fromLongBits(long).

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

        Specified by:
        longValue in class java.lang.Number
      • floatValue

        public float floatValue()
        Returns the value of this UnsignedLong as a float, analogous to a widening primitive conversion from long to float, and correctly rounded.
        Specified by:
        floatValue in class java.lang.Number
      • doubleValue

        public double doubleValue()
        Returns the value of this UnsignedLong as a double, analogous to a widening primitive conversion from long to double, and correctly rounded.
        Specified by:
        doubleValue in class java.lang.Number
      • bigIntegerValue

        public java.math.BigInteger bigIntegerValue()
        Returns the value of this UnsignedLong as a BigInteger.
      • compareTo

        public int compareTo​(UnsignedLong o)
        Specified by:
        compareTo in interface java.lang.Comparable<UnsignedLong>
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(@Nullable
                              java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Returns a string representation of the UnsignedLong value, in base 10.
        Overrides:
        toString in class java.lang.Object
      • toString

        public java.lang.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.