Package com.igormaznitsa.jbbp.utils
Class JBBPIntCounter
java.lang.Object
java.lang.Number
com.igormaznitsa.jbbp.utils.JBBPIntCounter
- All Implemented Interfaces:
Serializable
The Class implements a simple thread unsafe integer counter.
- Since:
- 1.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionThe Constructor to initialize the counter by 0.JBBPIntCounter(int startValue) The Constructor to initialize the counter by an integer value. -
Method Summary
Modifier and TypeMethodDescriptionvoiddec()Decrease the counter.intDecrement the counter and return the decremented value.doublefloatintget()Get the counter value.intgetAndAdd(int value) Get the current counter value and add a value after the return.intGet the counter value and decrement the counter after result return.intGet the counter value and increment the counter after result return.voidinc()Increase the counter.intIncrement the counter and get the incremented result.intintValue()longvoidset(int value) Set the value for the counter.Methods inherited from class java.lang.Number
byteValue, shortValue
-
Constructor Details
-
JBBPIntCounter
public JBBPIntCounter()The Constructor to initialize the counter by 0. -
JBBPIntCounter
public JBBPIntCounter(int startValue) The Constructor to initialize the counter by an integer value.- Parameters:
startValue- the start integer value for the counter
-
-
Method Details
-
set
public void set(int value) Set the value for the counter.- Parameters:
value- the new value for the counter
-
inc
public void inc()Increase the counter. -
dec
public void dec()Decrease the counter. -
getAndIncrement
public int getAndIncrement()Get the counter value and increment the counter after result return.- Returns:
- the value before increment.
-
incrementAndGet
public int incrementAndGet()Increment the counter and get the incremented result.- Returns:
- the value after increment
-
getAndDecrement
public int getAndDecrement()Get the counter value and decrement the counter after result return.- Returns:
- the value before decrement
-
decrementAndGet
public int decrementAndGet()Decrement the counter and return the decremented value.- Returns:
- the decremented value
-
get
public int get()Get the counter value.- Returns:
- the current counter value
-
getAndAdd
public int getAndAdd(int value) Get the current counter value and add a value after the return.- Parameters:
value- a value to be added to the counter- Returns:
- the counter before addition
-
intValue
public int intValue() -
longValue
public long longValue() -
floatValue
public float floatValue()- Specified by:
floatValuein classNumber
-
doubleValue
public double doubleValue()- Specified by:
doubleValuein classNumber
-