On this page

MutableBoolean

public class org.apache.commons.lang3.mutable.MutableBoolean implements Mutable<Boolean>, Serializable, Comparable<MutableBoolean>[source]

A mutable boolean wrapper.

This class was created before the introduction of the java.util.concurrent.atomic package and the AtomicBoolean class.

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

See also:
Since:

2.2

Constructors

MutableBoolean()

Constructs a new MutableBoolean with the default value of false.

MutableBoolean(boolean)

Constructs a new MutableBoolean with the specified value.

MutableBoolean(Boolean)

Constructs a new MutableBoolean with the specified value.

public MutableBoolean()[source]

Constructs a new MutableBoolean with the default value of false.

public MutableBoolean(boolean value)[source]

Constructs a new MutableBoolean with the specified value.

Parameters:

value – The initial value to store

public MutableBoolean(Boolean value)[source]

Constructs a new MutableBoolean with the specified value.

Parameters:

value – The initial value to store, not null

Throws:

java.lang.NullPointerException – Thrown if the object is null.

Methods

booleanValue()

Returns the value of this MutableBoolean as a boolean.

compareTo(MutableBoolean)

Compares this mutable to another in ascending order.

equals(Object)

Compares this object to the specified object.

getValue()

Deprecated. Gets the value as a Boolean instance.

hashCode()

Returns a suitable hash code for this mutable.

isFalse()

Tests whether the current value is false.

isTrue()

Tests whether the current value is true.

setFalse()

Sets the value to false.

setTrue()

Sets the value to true.

setValue(boolean)

Sets the value.

setValue(Boolean)

Sets the value from any Boolean instance.

toBoolean()

Gets this mutable as an instance of Boolean.

toString()

Returns the String value of this mutable.

public boolean booleanValue()[source]

Returns the value of this MutableBoolean as a boolean.

Returns:

The boolean value represented by this object.

@Override public int compareTo(MutableBoolean other)[source]

Compares this mutable to another in ascending order.

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

@Override public boolean equals(Object obj)[source]

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.

Parameters:

obj – The object to compare with, null returns false

Returns:

true if the objects are the same; false otherwise.

@Deprecated @Override public Boolean getValue()[source]

Deprecated: Use #get().

Gets the value as a Boolean instance.

Returns:

The value as a Boolean, never null.

@Override public int hashCode()[source]

Returns a suitable hash code for this mutable.

Returns:

The hash code returned by Boolean.TRUE or Boolean.FALSE

public boolean isFalse()[source]

Tests whether the current value is false.

Returns:

true if the current value is false

Since:

2.5

public boolean isTrue()[source]

Tests whether the current value is true.

Returns:

true if the current value is true

Since:

2.5

public void setFalse()[source]

Sets the value to false.

Since:

3.3

public void setTrue()[source]

Sets the value to true.

Since:

3.3

public void setValue(boolean value)[source]

Sets the value.

Parameters:

value – The value to set

@Override public void setValue(Boolean value)[source]

Sets the value from any Boolean instance.

Parameters:

value – The value to set, not null

Throws:

java.lang.NullPointerException – Thrown if the object is null.

public Boolean toBoolean()[source]

Gets this mutable as an instance of Boolean.

Returns:

A Boolean instance containing the value from this mutable, never null

Since:

2.5

@Override public String toString()[source]

Returns the String value of this mutable.

Returns:

The mutable value as a string