Class MutableInteger

java.lang.Object
java.lang.Number
org.agrona.collections.MutableInteger
All Implemented Interfaces:
Serializable, Comparable<MutableInteger>

public class MutableInteger extends Number implements Comparable<MutableInteger>
Holder for an int value that is mutable. Useful for being a counter in a Map or for passing by reference.
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • value

      public int value
      The value. Default value is 0.
  • Constructor Details

    • MutableInteger

      public MutableInteger()
      Default constructor.
    • MutableInteger

      public MutableInteger(int value)
      Creates an instance with a value.
      Parameters:
      value - to assign.
  • Method Details

    • get

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

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

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

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

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

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

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

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

      public void increment()
      Increment the value.
    • incrementAndGet

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

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

      public void decrement()
      Decrement the value.
    • decrementAndGet

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

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

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

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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

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

      public int compareTo(MutableInteger that)
      Specified by:
      compareTo in interface Comparable<MutableInteger>
    • compare

      public static int compare(int lhs, int rhs)
      Compare two values. Invoking this method is equivalent to:
           Integer.compare(lhs, rhs);
       
      Parameters:
      lhs - first value to compare.
      rhs - second value to compare.
      Returns:
      zero if values are equal, negative value if lhs is less than rhs or positive value otherwise.