Class MutableBoolean

java.lang.Object
com.landawn.abacus.util.MutableBoolean
All Implemented Interfaces:
Mutable, Serializable, Comparable<MutableBoolean>

public final class MutableBoolean extends Object implements Mutable, Serializable, Comparable<MutableBoolean>

Note: it's copied from Apache Commons Lang developed at The Apache Software Foundation (http://www.apache.org/), or under the Apache License 2.0. The methods copied from other products/frameworks may be modified in this class.

A mutable boolean wrapper.

Note that as MutableBoolean does not extend Boolean, it is not treated by String.format as a Boolean parameter.

MutableBoolean is NOT thread-safe.

Since:
2.2
Version:
$Id: MutableBoolean.java 1669791 2015-03-28 15:22:59Z britter $
See Also:
  • Method Details

    • of

      public static MutableBoolean of(boolean value)
      Parameters:
      value -
      Returns:
    • value

      public boolean value()
      Returns:
    • getValue

      @Deprecated public boolean getValue()
      Deprecated.
      replace by value().
      Gets the value as a Boolean instance.
      Returns:
    • setValue

      public void setValue(boolean value)
      Sets the value.
      Parameters:
      value - the value to set
    • getAndSet

      public boolean getAndSet(boolean value)
      Gets the and set.
      Parameters:
      value -
      Returns:
    • setAndGet

      public boolean setAndGet(boolean value)
      Sets the and get.
      Parameters:
      value -
      Returns:
    • getAndInvert

      public boolean getAndInvert()
      Gets the and invert.
      Returns:
    • invertAndGet

      public boolean invertAndGet()
      Invert and get.
      Returns:
    • setIf

      public <E extends Exception> boolean setIf(boolean newValue, Throwables.BooleanPredicate<E> predicate) throws E
      Set with the specified new value and returns true if predicate returns true. Otherwise just return false without setting the value to new value.
      Type Parameters:
      E -
      Parameters:
      newValue -
      predicate - - test the current value.
      Returns:
      Throws:
      E - the e
    • setFalse

      public void setFalse()
      Sets the value to true.
      Since:
      3.3
    • setTrue

      public void setTrue()
      Sets the value to false.
      Since:
      3.3
    • isTrue

      public boolean isTrue()
      Checks if the current value is true.
      Returns:
      true if the current value is true
      Since:
      2.5
    • isFalse

      public boolean isFalse()
      Checks if the current value is false.
      Returns:
      true if the current value is false
      Since:
      2.5
    • invert

      public void invert()
      Invert.
    • compareTo

      public int compareTo(MutableBoolean other)
      Compares this mutable to another in ascending order.
      Specified by:
      compareTo in interface Comparable<MutableBoolean>
      Parameters:
      other - the other mutable to compare to, not null
      Returns:
      negative if this is less, zero if equal, positive if greater where false is less than true
    • equals

      public boolean equals(Object obj)
      Compares this object to the specified object. The result is true if and only if the argument is not null and is an MutableBoolean object that contains the same boolean value as this object.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare with, null returns false
      Returns:
      true if the objects are the same; false otherwise.
    • hashCode

      public int hashCode()
      Returns a suitable hash code for this mutable.
      Overrides:
      hashCode in class Object
      Returns:
    • toString

      public String toString()
      Returns the String value of this mutable.
      Overrides:
      toString in class Object
      Returns: