Package dev.brachtendorf.mutable
Class MutableLong
- java.lang.Object
-
- java.lang.Number
-
- dev.brachtendorf.mutable.MutableLong
-
- All Implemented Interfaces:
Mutable<Long>,Serializable,Comparable<MutableLong>
public class MutableLong extends Number implements Mutable<Long>, Comparable<MutableLong>
Mutable class wrapper for long values. Mutable classes are useful in lambda expressions or anonymous classes which want to alter the content of a variable but are limited to final or effective final variables. Be aware that the hashcode changes if the value is updated resulting in the object not being retrievable in hash collections.- Since:
- 1.0.0 com.github.kilianB
- Author:
- Kilian
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description MutableLong()Create a mutable Long with an initial value of 0LMutableLong(long initialValue)Create a mutable Long.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(MutableLong o)LongdecrementAndGet()Decrement the internal value and return the result.doubledoubleValue()booleanequals(Object obj)floatfloatValue()LonggetAndDecrement()Return the internal value and decrement it afterwards.LonggetAndIncrement()Return the internal value and increment it afterwards.LonggetValue()Get an object encapsulating the current valueinthashCode()LongincrementAndGet()Increment the internal value and return the result.intintValue()longlongValue()voidsetValue(long newValue)Set the internal field to the new valuevoidsetValue(Long newValue)Set the internal field to the new value-
Methods inherited from class java.lang.Number
byteValue, shortValue
-
-
-
-
Method Detail
-
compareTo
public int compareTo(MutableLong o)
- Specified by:
compareToin interfaceComparable<MutableLong>
-
getValue
public Long getValue()
Description copied from interface:MutableGet an object encapsulating the current value
-
setValue
public void setValue(Long newValue)
Description copied from interface:MutableSet the internal field to the new value
-
setValue
public void setValue(long newValue)
Set the internal field to the new value- Parameters:
newValue- the new value- Since:
- 1.2.0 com.github.kilianB
-
floatValue
public float floatValue()
- Specified by:
floatValuein classNumber
-
doubleValue
public double doubleValue()
- Specified by:
doubleValuein classNumber
-
getAndIncrement
public Long getAndIncrement()
Return the internal value and increment it afterwards.- Returns:
- the value of the internal field before performing the increment operation.
- Since:
- 1.2.0 com.github.kilianB
-
incrementAndGet
public Long incrementAndGet()
Increment the internal value and return the result.- Returns:
- the new value after after performing the increment operation.
- Since:
- 1.2.0 com.github.kilianB
-
getAndDecrement
public Long getAndDecrement()
Return the internal value and decrement it afterwards.- Returns:
- the value of the internal field before performing the decrement operation.
- Since:
- 1.2.0 com.github.kilianB
-
decrementAndGet
public Long decrementAndGet()
Decrement the internal value and return the result.- Returns:
- the new value after after performing the decrement operation.
- Since:
- 1.2.0 com.github.kilianB
-
-