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 TypeMethodDescriptionint
addAndGet
(int delta) Add thedelta
and get the value.byte
Return value asbyte
.static int
compare
(int lhs, int rhs) Compare two values.int
compareTo
(MutableInteger that) void
Decrement the value.int
Decrement and get the value.double
Return value asdouble
.boolean
float
Return value asfloat
.int
get()
Get the value.int
getAndAdd
(int delta) Get the value and adddelta
to it.int
Get the value and decrement it.int
Get and increment the value.int
hashCode()
void
Increment the value.int
Increment and return the value.int
intValue()
Return value asint
.long
Return value aslong
.void
set
(int value) Set the value.short
Return value asshort
.toString()
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
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:
shortValue
in 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:
floatValue
in classNumber
- Returns:
- value as
float
.
-
doubleValue
public double doubleValue()Return value asdouble
.- Specified by:
doubleValue
in 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 adddelta
to it.- Parameters:
delta
- to add.- Returns:
- the value before the change.
-
addAndGet
public int addAndGet(int delta) Add thedelta
and get the value.- Parameters:
delta
- to add.- Returns:
- the value after the change.
-
equals
-
hashCode
public int hashCode() -
toString
-
compareTo
- Specified by:
compareTo
in 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
lhs
is less thanrhs
or positive value otherwise.
-