Class MutableInt
java.lang.Object
org.klojang.util.MutableInt
The mutable-integer class.
-
Constructor Summary
ConstructorsConstructorDescriptionInstantiates aMutableIntwith an initial value of 0 (zero).MutableInt(int value) Instantiates aMutableIntwith the specified initial value.MutableInt(MutableInt other) Instantiates aMutableIntinitialized to the current value of another instance. -
Method Summary
Modifier and TypeMethodDescriptionintadd(int j) Adds the specified value to the current value and returns the new value.add(MutableInt other) Adds the specified value to the current value and returns the new value.compute(IntUnaryOperator operator) Computes a new value for this instance using the current value as inputintcomputeInt(IntUnaryOperator operator) Computes a new value for this instance using the current value as inputcopy()Returns a copy of thisMutableInt.intDecrements the value by one and returns the original value (before decrementing).booleanReturns true ifobjis aMutableIntcontaining the sameintvalue as thisMutableInt,false otherwise.booleanequalTo(int j) Corresponds to the==(equals) operation.booleanequalTo(MutableInt other) Corresponds to the==(equals) operation.intget()Returns the current value of thisMutableInt.booleangreaterThan(int j) Corresponds to the>(greater than) operation.booleangreaterThan(MutableInt other) Corresponds to the>(greater than) operation.booleangte(int j) Corresponds to the>=(greater or equal) operation.booleangte(MutableInt other) Corresponds to the>=(greater or equal) operation.inthashCode()Returns the current value of this instanceintIncrements the value by one and returns the original value (before incrementing).booleanlessThan(int j) Corresponds to the<(less than) operation.booleanlessThan(MutableInt other) Corresponds to the<(less than) operation.booleanlte(int j) Corresponds to the<=(less or equal) operation.booleanlte(MutableInt other) Corresponds to the<=(less or equal) operation.intmultiply(int j) Subtracts the specified value to the current value and returns the new value.multiply(MutableInt other) Subtracts the specified value to the current value and returns the new value.booleannotEquals(int j) Corresponds to the!=(not equals) operation.booleannotEquals(MutableInt other) Corresponds to the!=(not equals) operation.static MutableIntof(int value) intoneDown()Decrements the value by one and returns the new value (after decrementing).intoneUp()Increments the value by one and returns the new value (after incrementing).intreset()Sets the value to 0 (zero).intset(int j) Overwrites the current value with the specified value and returns the new value.set(MutableInt other) Overwrites the current value with the specified value and returns the new value.intsubtract(int j) Subtracts the specified value to the current value and returns the new value.subtract(MutableInt other) Subtracts the specified value to the current value and returns the new value.toString()Returns the string representation of the current value.
-
Constructor Details
-
MutableInt
public MutableInt()Instantiates aMutableIntwith an initial value of 0 (zero). -
MutableInt
public MutableInt(int value) Instantiates aMutableIntwith the specified initial value.- Parameters:
value- the initial value of this instance
-
MutableInt
Instantiates aMutableIntinitialized to the current value of another instance.- Parameters:
other- the instance used to initialize this instance.
-
-
Method Details
-
of
-
get
public int get()Returns the current value of thisMutableInt.- Returns:
- the current value of this
MutableInt
-
copy
-
increment
public int increment()Increments the value by one and returns the original value (before incrementing). Corresponds to the ++ postfix operator.- Returns:
- the original value
-
oneUp
public int oneUp()Increments the value by one and returns the new value (after incrementing). Corresponds to the ++ prefix operator.- Returns:
- the new value
-
decrement
public int decrement()Decrements the value by one and returns the original value (before decrementing). Corresponds to the -- postfix operator.- Returns:
- the original value
-
oneDown
public int oneDown()Decrements the value by one and returns the new value (after decrementing). Corresponds to the -- prefix operator.- Returns:
- the new value
-
add
public int add(int j) Adds the specified value to the current value and returns the new value.- Parameters:
j- the value to add- Returns:
- the new value
-
add
Adds the specified value to the current value and returns the new value.- Parameters:
other- the value the add- Returns:
- the new value
-
subtract
public int subtract(int j) Subtracts the specified value to the current value and returns the new value.- Parameters:
j- the value to subtract- Returns:
- the new value
-
subtract
Subtracts the specified value to the current value and returns the new value.- Parameters:
other- the value to subtract- Returns:
- the new value
-
multiply
public int multiply(int j) Subtracts the specified value to the current value and returns the new value.- Parameters:
j- the value to subtract- Returns:
- the new value
-
multiply
Subtracts the specified value to the current value and returns the new value.- Parameters:
other- the value to subtract- Returns:
- the new value
-
computeInt
Computes a new value for this instance using the current value as input- Parameters:
operator- a function that computes a new value based on the current value- Returns:
- the new value
-
compute
Computes a new value for this instance using the current value as input- Parameters:
operator- a function that computes a new value based on the current value- Returns:
- the new value
-
set
public int set(int j) Overwrites the current value with the specified value and returns the new value.- Parameters:
j- the new value- Returns:
- the new value
-
set
Overwrites the current value with the specified value and returns the new value.- Parameters:
other- the new value- Returns:
- the new value
-
equalTo
public boolean equalTo(int j) Corresponds to the==(equals) operation.- Parameters:
j- the value to compare this instance with- Returns:
trueif equal,falseotherwise
-
equalTo
Corresponds to the==(equals) operation.- Parameters:
other- the value to compare this instance with- Returns:
trueif equal,falseotherwise
-
notEquals
public boolean notEquals(int j) Corresponds to the!=(not equals) operation.- Parameters:
j- the value to compare this instance with- Returns:
trueif not equal,falseotherwise
-
notEquals
Corresponds to the!=(not equals) operation.- Parameters:
other- the value to compare this instance with- Returns:
trueif equal,falseotherwise
-
greaterThan
public boolean greaterThan(int j) Corresponds to the>(greater than) operation.- Parameters:
j- the value to compare this instance with- Returns:
trueif this instance has a value greater than the specified value,falseotherwise
-
greaterThan
Corresponds to the>(greater than) operation.- Parameters:
other- the value to compare this instance with- Returns:
trueif this instance has a value greater than the specified value,falseotherwise
-
lessThan
public boolean lessThan(int j) Corresponds to the<(less than) operation.- Parameters:
j- the value to compare this instance with- Returns:
trueif this instance has a value less than the specified value,falseotherwise
-
lessThan
Corresponds to the<(less than) operation.- Parameters:
other- the value to compare this instance with- Returns:
trueif this instance has a value less than the specified value,falseotherwise
-
gte
public boolean gte(int j) Corresponds to the>=(greater or equal) operation.- Parameters:
j- the value to compare this instance with- Returns:
trueif this instance has a value greater than, or equal to the specified value,falseotherwise
-
gte
Corresponds to the>=(greater or equal) operation.- Parameters:
other- the value to compare this instance with- Returns:
trueif this instance has a value greater than, or equal to the specified value,falseotherwise
-
lte
public boolean lte(int j) Corresponds to the<=(less or equal) operation.- Parameters:
j- the value to compare this instance with- Returns:
trueif this instance has a value less than, or equal to the specified value,falseotherwise
-
lte
Corresponds to the<=(less or equal) operation.- Parameters:
other- the value to compare this instance with- Returns:
trueif this instance has a value less than, or equal to the specified value,falseotherwise
-
reset
public int reset()Sets the value to 0 (zero).- Returns:
- 0 (zero)
-
hashCode
-
equals
-
toString
-