Class MutableBoolean

java.lang.Object
org.apache.commons.lang3.mutable.MutableBoolean
All Implemented Interfaces:
Serializable, Comparable<MutableBoolean>, Mutable<Boolean>

A mutable boolean wrapper.

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

Since:
2.2
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new MutableBoolean with the default value of false.
    MutableBoolean(boolean value)
    Constructs a new MutableBoolean with the specified value.
    Constructs a new MutableBoolean with the specified value.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns the value of this MutableBoolean as a boolean.
    int
    Compares this mutable to another in ascending order.
    boolean
    Compares this object to the specified object.
    Gets the value as a Boolean instance.
    int
    Returns a suitable hash code for this mutable.
    boolean
    Checks if the current value is false.
    boolean
    Checks if the current value is true.
    void
    Sets the value to false.
    void
    Sets the value to true.
    void
    setValue(boolean value)
    Sets the value.
    void
    Sets the value from any Boolean instance.
    Gets this mutable as an instance of Boolean.
    Returns the String value of this mutable.

    Methods inherited from class java.lang.Object

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

    • MutableBoolean

      public MutableBoolean()
      Constructs a new MutableBoolean with the default value of false.
    • MutableBoolean

      public MutableBoolean(boolean value)
      Constructs a new MutableBoolean with the specified value.
      Parameters:
      value - the initial value to store
    • MutableBoolean

      public MutableBoolean(Boolean value)
      Constructs a new MutableBoolean with the specified value.
      Parameters:
      value - the initial value to store, not null
      Throws:
      NullPointerException - if the object is null
  • Method Details

    • booleanValue

      public boolean booleanValue()
      Returns the value of this MutableBoolean as a boolean.
      Returns:
      the boolean value represented by this object.
    • 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.
    • getValue

      public Boolean getValue()
      Gets the value as a Boolean instance.
      Specified by:
      getValue in interface Mutable<Boolean>
      Returns:
      the value as a Boolean, never null
    • hashCode

      public int hashCode()
      Returns a suitable hash code for this mutable.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code returned by Boolean.TRUE or Boolean.FALSE
    • isFalse

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

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

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

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

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

      public void setValue(Boolean value)
      Sets the value from any Boolean instance.
      Specified by:
      setValue in interface Mutable<Boolean>
      Parameters:
      value - the value to set, not null
      Throws:
      NullPointerException - if the object is null
    • toBoolean

      public Boolean toBoolean()
      Gets this mutable as an instance of Boolean.
      Returns:
      a Boolean instance containing the value from this mutable, never null
      Since:
      2.5
    • toString

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