Class MutableLong

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<MutableLong>

    public class MutableLong
    extends java.lang.Number
    implements java.lang.Comparable<MutableLong>
    Holder for a long value that is mutable. Useful for being a counter in a Map or for passing by reference.
    • Field Detail

      • value

        public long value
        The value. Default value is 0.
    • Constructor Detail

      • MutableLong

        public MutableLong()
        Default constructor.
      • MutableLong

        public MutableLong​(long value)
        Creates an instance with a value.
        Parameters:
        value - to assign.
    • Method Detail

      • get

        public long get()
        Get the value.
        Returns:
        the value.
      • set

        public void set​(long value)
        Set the value.
        Parameters:
        value - to be assigned.
      • byteValue

        public byte byteValue()
        Return value as byte.
        Overrides:
        byteValue in class java.lang.Number
        Returns:
        value as byte.
      • shortValue

        public short shortValue()
        Return value as short.
        Overrides:
        shortValue in class java.lang.Number
        Returns:
        value as short.
      • intValue

        public int intValue()
        Return value as int.
        Specified by:
        intValue in class java.lang.Number
        Returns:
        value as int.
      • longValue

        public long longValue()
        Return value as long.
        Specified by:
        longValue in class java.lang.Number
        Returns:
        value as long.
      • floatValue

        public float floatValue()
        Return value as float.
        Specified by:
        floatValue in class java.lang.Number
        Returns:
        value as float.
      • doubleValue

        public double doubleValue()
        Return value as double.
        Specified by:
        doubleValue in class java.lang.Number
        Returns:
        value as double.
      • increment

        public void increment()
        Increment the value.
      • incrementAndGet

        public long incrementAndGet()
        Increment and return the value.
        Returns:
        the value after increment.
      • getAndIncrement

        public long getAndIncrement()
        Get and increment the value.
        Returns:
        the value before increment.
      • decrement

        public void decrement()
        Decrement the value.
      • decrementAndGet

        public long decrementAndGet()
        Decrement and get the value.
        Returns:
        value after the decrement.
      • getAndDecrement

        public long getAndDecrement()
        Get the value and decrement it.
        Returns:
        the value before the decrement.
      • getAndAdd

        public long getAndAdd​(long delta)
        Get the value and add delta to it.
        Parameters:
        delta - to add.
        Returns:
        the value before the change.
      • addAndGet

        public long addAndGet​(long delta)
        Add the delta and get the value.
        Parameters:
        delta - to add.
        Returns:
        the value after the change.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • compareTo

        public int compareTo​(MutableLong that)
        Specified by:
        compareTo in interface java.lang.Comparable<MutableLong>
      • compare

        public static int compare​(long lhs,
                                  long rhs)
        Compare two long values. Calling this method is equivalent to calling:
             Long.compare(lhs, rhs);
         
        Parameters:
        lhs - first value.
        rhs - second value.
        Returns:
        the value 0 if lhs == rhs; a value less than 0 if lhs < rhs; and a value greater than 0 if lhs > rhs