Package org.agrona.collections
Class MutableInteger
- java.lang.Object
-
- java.lang.Number
-
- org.agrona.collections.MutableInteger
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<MutableInteger>
public class MutableInteger extends java.lang.Number implements java.lang.Comparable<MutableInteger>
Holder for an int value that is mutable. Useful for being a counter in aMap
or for passing by reference.
-
-
Field Summary
Fields Modifier and Type Field Description private static long
serialVersionUID
int
value
The value.
-
Constructor Summary
Constructors Constructor Description MutableInteger()
Default constructor.MutableInteger(int value)
Creates an instance with a value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
addAndGet(int delta)
Add thedelta
and get the value.byte
byteValue()
Return value asbyte
.static int
compare(int lhs, int rhs)
Compare two values.int
compareTo(MutableInteger that)
void
decrement()
Decrement the value.int
decrementAndGet()
Decrement and get the value.double
doubleValue()
Return value asdouble
.boolean
equals(java.lang.Object o)
float
floatValue()
Return value asfloat
.int
get()
Get the value.int
getAndAdd(int delta)
Get the value and adddelta
to it.int
getAndDecrement()
Get the value and decrement it.int
getAndIncrement()
Get and increment the value.int
hashCode()
void
increment()
Increment the value.int
incrementAndGet()
Increment and return the value.int
intValue()
Return value asint
.long
longValue()
Return value aslong
.void
set(int value)
Set the value.short
shortValue()
Return value asshort
.java.lang.String
toString()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
value
public int value
The value. Default value is0
.
-
-
Method Detail
-
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
.- Overrides:
byteValue
in classjava.lang.Number
- Returns:
- value as
byte
.
-
shortValue
public short shortValue()
Return value asshort
.- Overrides:
shortValue
in classjava.lang.Number
- Returns:
- value as
short
.
-
intValue
public int intValue()
Return value asint
.- Specified by:
intValue
in classjava.lang.Number
- Returns:
- value as
int
.
-
longValue
public long longValue()
Return value aslong
.- Specified by:
longValue
in classjava.lang.Number
- Returns:
- value as
long
.
-
floatValue
public float floatValue()
Return value asfloat
.- Specified by:
floatValue
in classjava.lang.Number
- Returns:
- value as
float
.
-
doubleValue
public double doubleValue()
Return value asdouble
.- Specified by:
doubleValue
in classjava.lang.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 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
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
compareTo
public int compareTo(MutableInteger that)
- Specified by:
compareTo
in interfacejava.lang.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 thanrhs
or positive value otherwise.
-
-