Class MutableInt

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

public final class MutableInt extends Object
The ubiquitous 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
    boolean
    eq(int j)
    Corresponds to the == (equals) operation.
    boolean
    eq(MutableInt other)
    Corresponds to the == (equals) operation.
    boolean
    Returns true if obj is a MutableInt, Integer, Short or Byte with the same value as this MutableInt, false otherwise.
    int
    get()
    Returns the current value of this MutableInt.
    boolean
    gt(int j)
    Corresponds to the > (greater than) operation.
    boolean
    gt(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
    Returns the current value of this instance
    boolean
    lt(int j)
    Corresponds to the < (less than) operation.
    boolean
    lt(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
    minIs(int j)
    Corresponds to the -= (minus-is) operation.
    int
    Corresponds to the -= (minus-is) operation.
    int
    mm()
    Corresponds to the -- postfix operator (i--).
    int
    mmi()
    Corresponds to the -- prefix operator (--i).
    boolean
    ne(int j)
    Corresponds to the != (not equals) operation.
    boolean
    ne(MutableInt other)
    Corresponds to the != (not equals) operation.
    int
    plusIs(int j)
    Corresponds to the += operation.
    int
    Corresponds to the += operation.
    int
    pp()
    Corresponds to the ++ postfix operator (i++).
    int
    ppi()
    Corresponds to the ++ prefix operator (++i).
    int
    Sets the value to 0 (zero).
    int
    set(int j)
    Corresponds to the assignment operation (i = j).
    int
    set(MutableInt other)
    Corresponds to the assignment operation (i = j).
    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

    • get

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

      public int pp()
      Corresponds to the ++ postfix operator (i++).
      Returns:
      The original value (before incrementation)
    • ppi

      public int ppi()
      Corresponds to the ++ prefix operator (++i).
      Returns:
      The incremented value (after incrementation)
    • mm

      public int mm()
      Corresponds to the -- postfix operator (i--).
      Returns:
      The original value
    • mmi

      public int mmi()
      Corresponds to the -- prefix operator (--i).
      Returns:
      The decremented value
    • plusIs

      public int plusIs(int j)
      Corresponds to the += operation.
      Parameters:
      j - The value to add
      Returns:
      The new value
    • plusIs

      public int plusIs(MutableInt other)
      Corresponds to the += operation.
      Parameters:
      other - The value the add
      Returns:
      The new value
    • minIs

      public int minIs(int j)
      Corresponds to the -= (minus-is) operation.
      Parameters:
      j - The value to subtract
      Returns:
      The new value
    • minIs

      public int minIs(MutableInt other)
      Corresponds to the -= (minus-is) operation.
      Parameters:
      other - The value to subtract
      Returns:
      The new value
    • set

      public int set(int j)
      Corresponds to the assignment operation (i = j).
      Parameters:
      j - The value to assign to this MutableInt
      Returns:
      The new value
    • set

      public int set(MutableInt other)
      Corresponds to the assignment operation (i = j).
      Parameters:
      other - The value to assign to this MutableInt
      Returns:
      The new value
    • eq

      public boolean eq(int j)
      Corresponds to the == (equals) operation.
      Parameters:
      j - The value to compare this instance with
      Returns:
      true if equal, false otherwise
    • eq

      public boolean eq(MutableInt other)
      Corresponds to the == (equals) operation.
      Parameters:
      other - The value to compare this instance with
      Returns:
      true if equal, false otherwise
    • ne

      public boolean ne(int j)
      Corresponds to the != (not equals) operation.
      Parameters:
      j - The value to compare this instance with
      Returns:
      true if not equal, false otherwise
    • ne

      public boolean ne(MutableInt other)
      Corresponds to the != (not equals) operation.
      Parameters:
      other - The value to compare this instance with
      Returns:
      true if equal, false otherwise
    • gt

      public boolean gt(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
    • gt

      public boolean gt(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
    • lt

      public boolean lt(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
    • lt

      public boolean lt(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, Integer, Short or Byte with the same 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