Class MutableInt
java.lang.Object
org.klojang.util.MutableInt
The mutable-integer class.
-
Constructor Summary
ConstructorsConstructorDescriptionInstantiates aMutableInt
with an initial value of 0 (zero).MutableInt
(int value) Instantiates aMutableInt
with the specified initial value.MutableInt
(MutableInt other) Instantiates aMutableInt
initialized to the current value of another instance. -
Method Summary
Modifier and TypeMethodDescriptionint
add
(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 inputint
computeInt
(IntUnaryOperator operator) Computes a new value for this instance using the current value as inputcopy()
Returns a copy of thisMutableInt
.int
Decrements the value by one and returns the original value (before decrementing).boolean
Returns true ifobj
is aMutableInt
containing the sameint
value as thisMutableInt
,false otherwise
.boolean
equalTo
(int j) Corresponds to the==
(equals) operation.boolean
equalTo
(MutableInt other) Corresponds to the==
(equals) operation.int
get()
Returns the current value of thisMutableInt
.boolean
greaterThan
(int j) Corresponds to the>
(greater than) operation.boolean
greaterThan
(MutableInt other) Corresponds to the>
(greater than) operation.boolean
gte
(int j) Corresponds to the>=
(greater or equal) operation.boolean
gte
(MutableInt other) Corresponds to the>=
(greater or equal) operation.int
hashCode()
Returns the current value of this instanceint
Increments the value by one and returns the original value (before incrementing).boolean
lessThan
(int j) Corresponds to the<
(less than) operation.boolean
lessThan
(MutableInt other) Corresponds to the<
(less than) operation.boolean
lte
(int j) Corresponds to the<=
(less or equal) operation.boolean
lte
(MutableInt other) Corresponds to the<=
(less or equal) operation.int
multiply
(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.boolean
notEquals
(int j) Corresponds to the!=
(not equals) operation.boolean
notEquals
(MutableInt other) Corresponds to the!=
(not equals) operation.static MutableInt
of
(int value) int
oneDown()
Decrements the value by one and returns the new value (after decrementing).int
oneUp()
Increments the value by one and returns the new value (after incrementing).int
reset()
Sets the value to 0 (zero).int
set
(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.int
subtract
(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 aMutableInt
with an initial value of 0 (zero). -
MutableInt
public MutableInt(int value) Instantiates aMutableInt
with the specified initial value.- Parameters:
value
- the initial value of this instance
-
MutableInt
Instantiates aMutableInt
initialized 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:
true
if equal,false
otherwise
-
equalTo
Corresponds to the==
(equals) operation.- Parameters:
other
- the value to compare this instance with- Returns:
true
if equal,false
otherwise
-
notEquals
public boolean notEquals(int j) Corresponds to the!=
(not equals) operation.- Parameters:
j
- the value to compare this instance with- Returns:
true
if not equal,false
otherwise
-
notEquals
Corresponds to the!=
(not equals) operation.- Parameters:
other
- the value to compare this instance with- Returns:
true
if equal,false
otherwise
-
greaterThan
public boolean greaterThan(int j) Corresponds to the>
(greater than) operation.- Parameters:
j
- the value to compare this instance with- Returns:
true
if this instance has a value greater than the specified value,false
otherwise
-
greaterThan
Corresponds to the>
(greater than) operation.- Parameters:
other
- the value to compare this instance with- Returns:
true
if this instance has a value greater than the specified value,false
otherwise
-
lessThan
public boolean lessThan(int j) Corresponds to the<
(less than) operation.- Parameters:
j
- the value to compare this instance with- Returns:
true
if this instance has a value less than the specified value,false
otherwise
-
lessThan
Corresponds to the<
(less than) operation.- Parameters:
other
- the value to compare this instance with- Returns:
true
if this instance has a value less than the specified value,false
otherwise
-
gte
public boolean gte(int j) Corresponds to the>=
(greater or equal) operation.- Parameters:
j
- the value to compare this instance with- Returns:
true
if this instance has a value greater than, or equal to the specified value,false
otherwise
-
gte
Corresponds to the>=
(greater or equal) operation.- Parameters:
other
- the value to compare this instance with- Returns:
true
if this instance has a value greater than, or equal to the specified value,false
otherwise
-
lte
public boolean lte(int j) Corresponds to the<=
(less or equal) operation.- Parameters:
j
- the value to compare this instance with- Returns:
true
if this instance has a value less than, or equal to the specified value,false
otherwise
-
lte
Corresponds to the<=
(less or equal) operation.- Parameters:
other
- the value to compare this instance with- Returns:
true
if this instance has a value less than, or equal to the specified value,false
otherwise
-
reset
public int reset()Sets the value to 0 (zero).- Returns:
- 0 (zero)
-
hashCode
-
equals
-
toString
-