Package org.agrona.collections
Class MutableInteger
java.lang.Object
java.lang.Number
org.agrona.collections.MutableInteger
- All Implemented Interfaces:
Serializable,Comparable<MutableInteger>
Holder for an int value that is mutable. Useful for being a counter in a
Map or for passing by
reference.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.MutableInteger(int value) Creates an instance with a value. -
Method Summary
Modifier and TypeMethodDescriptionintaddAndGet(int delta) Add thedeltaand get the value.byteReturn value asbyte.static intcompare(int lhs, int rhs) Compare two values.intcompareTo(MutableInteger that) voidDecrement the value.intDecrement and get the value.doubleReturn value asdouble.booleanfloatReturn value asfloat.intget()Get the value.intgetAndAdd(int delta) Get the value and adddeltato it.intGet the value and decrement it.intGet and increment the value.inthashCode()voidIncrement the value.intIncrement and return the value.intintValue()Return value asint.longReturn value aslong.voidset(int value) Set the value.shortReturn value asshort.toString()
-
Field Details
-
value
public int valueThe value. Default value is0.
-
-
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 asbyte. -
shortValue
public short shortValue()Return value asshort.- Overrides:
shortValuein classNumber- Returns:
- value as
short.
-
intValue
public int intValue()Return value asint. -
longValue
public long longValue()Return value aslong. -
floatValue
public float floatValue()Return value asfloat.- Specified by:
floatValuein classNumber- Returns:
- value as
float.
-
doubleValue
public double doubleValue()Return value asdouble.- Specified by:
doubleValuein classNumber- 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 adddeltato it.- Parameters:
delta- to add.- Returns:
- the value before the change.
-
addAndGet
public int addAndGet(int delta) Add thedeltaand get the value.- Parameters:
delta- to add.- Returns:
- the value after the change.
-
equals
-
hashCode
public int hashCode() -
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<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
lhsis less thanrhsor positive value otherwise.
-