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.

Since:

2.2

See also:

Constructors

MutableBoolean()

Constructs a new MutableBoolean with the default value of false.

MutableBoolean(boolean value)

Constructs a new MutableBoolean with the specified value.

MutableBoolean(Boolean value)

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:

NullPointerException – Thrown if the object is null.

Methods

boolean

booleanValue()

Returns the value of this MutableBoolean as a boolean.

int

compareTo(MutableBoolean other)

Compares this mutable to another in ascending order.

boolean

equals(Object obj)

Compares this object to the specified object.

Boolean

getValue()

Deprecated. Gets the value as a Boolean instance.

int

hashCode()

Returns a suitable hash code for this mutable.

boolean

isFalse()

Tests whether the current value is false.

boolean

isTrue()

Tests whether the current value is true.

void

setFalse()

Sets the value to false.

void

setTrue()

Sets the value to true.

void

setValue(boolean value)

Sets the value.

void

setValue(Boolean value)

Sets the value from any Boolean instance.

Boolean

toBoolean()

Gets this mutable as an instance of Boolean.

String

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.

public int compareTo(MutableBoolean other)[source]

Compares this mutable to another in ascending order.

Specified by:

compareTo in interface Comparable

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

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.

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.

@Deprecated public Boolean getValue()[source]

Deprecated: Use Mutable.get().

Gets the value as a Boolean instance.

Specified by:

getValue in interface Mutable

Returns:

The value as a Boolean, never null.

public int hashCode()[source]

Returns a suitable hash code for this mutable.

Overrides:

hashCode in class Object

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

public void setValue(Boolean value)[source]

Sets the value from any Boolean instance.

Specified by:

setValue in interface Mutable

Parameters:

value – The value to set, not null

Throws:

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

public String toString()[source]

Returns the String value of this mutable.

Overrides:

toString in class Object

Returns:

The mutable value as a string