Package org.agrona.collections
Class MutableLong
java.lang.Object
java.lang.Number
org.agrona.collections.MutableLong
- All Implemented Interfaces:
Serializable,Comparable<MutableLong>
Holder for a long value that is mutable. Useful for being a counter in a
Map or for passing by
reference.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.MutableLong(long value) Creates an instance with a value. -
Method Summary
Modifier and TypeMethodDescriptionlongaddAndGet(long delta) Add thedeltaand get the value.byteReturn value asbyte.static intcompare(long lhs, long rhs) Compare two long values.intcompareTo(MutableLong that) voidDecrement the value.longDecrement and get the value.doubleReturn value asdouble.booleanfloatReturn value asfloat.longget()Get the value.longgetAndAdd(long delta) Get the value and adddeltato it.longGet the value and decrement it.longGet and increment the value.inthashCode()voidIncrement the value.longIncrement and return the value.intintValue()Return value asint.longReturn value aslong.voidset(long value) Set the value.shortReturn value asshort.toString()
-
Field Details
-
value
public long valueThe value. Default value is0.
-
-
Constructor Details
-
MutableLong
public MutableLong()Default constructor. -
MutableLong
public MutableLong(long value) Creates an instance with a value.- Parameters:
value- to assign.
-
-
Method Details
-
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 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 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 adddeltato it.- Parameters:
delta- to add.- Returns:
- the value before the change.
-
addAndGet
public long addAndGet(long 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<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
0iflhs == rhs; a value less than0iflhs < rhs; and a value greater than0iflhs > rhs
-