Class MutableInt

java.lang.Object
org.klojang.util.MutableInt

public final class MutableInt extends Object
The mutable-integer class.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiates a MutableInt with an initial value of 0 (zero).
    MutableInt(int value)
    Instantiates a MutableInt with the specified initial value.
    Instantiates a MutableInt initialized to the current value of another instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    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.
    Computes a new value for this instance using the current value as input
    int
    Computes a new value for this instance using the current value as input
    Returns a copy of this MutableInt.
    int
    Decrements the value by one and returns the original value (before decrementing).
    boolean
    Returns true if obj is a MutableInt containing the same int value as this MutableInt, false otherwise.
    boolean
    equalTo(int j)
    Corresponds to the == (equals) operation.
    boolean
    Corresponds to the == (equals) operation.
    int
    get()
    Returns the current value of this MutableInt.
    boolean
    greaterThan(int j)
    Corresponds to the > (greater than) operation.
    boolean
    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
    Returns the current value of this instance
    int
    Increments the value by one and returns the original value (before incrementing).
    boolean
    lessThan(int j)
    Corresponds to the < (less than) operation.
    boolean
    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.
    Subtracts the specified value to the current value and returns the new value.
    boolean
    notEquals(int j)
    Corresponds to the != (not equals) operation.
    boolean
    Corresponds to the != (not equals) operation.
    static MutableInt
    of(int value)
     
    int
    Decrements the value by one and returns the new value (after decrementing).
    int
    Increments the value by one and returns the new value (after incrementing).
    int
    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.
    Subtracts the specified value to the current value and returns the new value.
    Returns the string representation of the current value.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • MutableInt

      public MutableInt()
      Instantiates a MutableInt with an initial value of 0 (zero).
    • MutableInt

      public MutableInt(int value)
      Instantiates a MutableInt with the specified initial value.
      Parameters:
      value - the initial value of this instance
    • MutableInt

      public MutableInt(MutableInt other)
      Instantiates a MutableInt initialized to the current value of another instance.
      Parameters:
      other - the instance used to initialize this instance.
  • Method Details

    • of

      public static MutableInt of(int value)
    • get

      public int get()
      Returns the current value of this MutableInt.
      Returns:
      the current value of this MutableInt
    • copy

      public MutableInt copy()
      Returns a copy of this MutableInt.
      Returns:
      a copy of this MutableInt
    • 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

      public MutableInt add(MutableInt other)
      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

      public MutableInt subtract(MutableInt other)
      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

      public MutableInt multiply(MutableInt other)
      Subtracts the specified value to the current value and returns the new value.
      Parameters:
      other - the value to subtract
      Returns:
      the new value
    • computeInt

      public int computeInt(IntUnaryOperator operator)
      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

      public MutableInt compute(IntUnaryOperator operator)
      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

      public MutableInt set(MutableInt other)
      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

      public boolean equalTo(MutableInt other)
      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

      public boolean notEquals(MutableInt other)
      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

      public boolean greaterThan(MutableInt other)
      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

      public boolean lessThan(MutableInt other)
      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

      public boolean gte(MutableInt other)
      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

      public boolean lte(MutableInt other)
      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

      public int hashCode()
      Returns the current value of this instance
      Overrides:
      hashCode in class Object
      Returns:
      the current value of this instance
    • equals

      public boolean equals(Object obj)
      Returns true if obj is a MutableInt containing the same int value as this MutableInt, false otherwise.
      Overrides:
      equals in class Object
      Parameters:
      obj - the value to compare this instance with
      Returns:
      Whether this MutableInt is equal to the specified value
    • toString

      public String toString()
      Returns the string representation of the current value.
      Overrides:
      toString in class Object
      Returns:
      the string representation of the current value