Top Description Fields Constructors Methods
org.apache.commons.lang3.mutable

public Class MutableBoolean

extends Object
implements Mutable<Boolean>, Serializable, Comparable<MutableBoolean>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable, java.io.Serializable, org.apache.commons.lang3.mutable.Mutable, java.util.function.Supplier
Imports
java.io.Serializable, java.util.concurrent.atomic.AtomicBoolean, org.apache.commons.lang3.BooleanUtils

A mutable boolean wrapper.

This class was created before the introduction of the 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
Boolean, AtomicBoolean

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Required for serialization support.

private boolean
value

The mutable value.

Constructor Summary

AccessConstructor and Description
public
MutableBoolean()

Constructs a new MutableBoolean with the default value of false.

public
MutableBoolean(final boolean
the initial value to store
value
)

Constructs a new MutableBoolean with the specified value.

public
MutableBoolean(final Boolean
the initial value to store, not null
value
)

Constructs a new MutableBoolean with the specified value.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

the boolean value represented by this object.
booleanValue
()

Returns the value of this MutableBoolean as a boolean.

public int

Returns:

negative if this is less, zero if equal, positive if greater where false is less than true
compareTo
(final MutableBoolean
the other mutable to compare to, not null
other
)

Implements java.lang.Comparable.compareTo.

Compares this mutable to another in ascending order.

public boolean

Returns:

true if the objects are the same; false otherwise.
equals
(final Object
the object to compare with, null returns false
obj
)

Overrides java.lang.Object.equals.

Compares this object to the specified object.

public Boolean

Returns:

the value as a Boolean, never null.
getValue
()

Implements org.apache.commons.lang3.mutable.Mutable.getValue.

Deprecated Use get().

Gets the value as a Boolean instance.

public int

Returns:

the hash code returned by Boolean.TRUE or Boolean.FALSE
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a suitable hash code for this mutable.

public boolean

Returns:

true if the current value is false
isFalse
()

Checks if the current value is false.

public boolean

Returns:

true if the current value is true
isTrue
()

Checks if the current value is true.

public void
setFalse()

Sets the value to false.

public void
setTrue()

Sets the value to true.

public void
setValue(final boolean
the value to set
value
)

Implements org.apache.commons.lang3.mutable.Mutable.setValue.

Sets the value.

public void
setValue(final Boolean
the value to set, not null
value
)

Implements org.apache.commons.lang3.mutable.Mutable.setValue.

Sets the value from any Boolean instance.

public Boolean

Returns:

a Boolean instance containing the value from this mutable, never null
toBoolean
()

Gets this mutable as an instance of Boolean.

public String

Returns:

the mutable value as a string
toString
()

Overrides java.lang.Object.toString.

Returns the String value of this mutable.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Required for serialization support.

See Also
java.io.Serializable
valueback to summary
private boolean value

The mutable value.

Constructor Detail

MutableBooleanback to summary
public MutableBoolean()

Constructs a new MutableBoolean with the default value of false.

MutableBooleanback to summary
public MutableBoolean(final boolean value)

Constructs a new MutableBoolean with the specified value.

Parameters
value:boolean

the initial value to store

MutableBooleanback to summary
public MutableBoolean(final Boolean value)

Constructs a new MutableBoolean with the specified value.

Parameters
value:Boolean

the initial value to store, not null

Exceptions
NullPointerException:
if the object is null

Method Detail

booleanValueback to summary
public boolean booleanValue()

Returns the value of this MutableBoolean as a boolean.

Returns:boolean

the boolean value represented by this object.

compareToback to summary
public int compareTo(final MutableBoolean other)

Implements java.lang.Comparable.compareTo.

Compares this mutable to another in ascending order.

Parameters
other:MutableBoolean

the other mutable to compare to, not null

Returns:int

negative if this is less, zero if equal, positive if greater where false is less than true

Annotations
@Override
equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

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:Object

the object to compare with, null returns false

Returns:boolean

true if the objects are the same; false otherwise.

Annotations
@Override
getValueback to summary
public Boolean getValue()

Implements org.apache.commons.lang3.mutable.Mutable.getValue.

Deprecated

Use get().

Gets the value as a Boolean instance.

Returns:Boolean

the value as a Boolean, never null.

Annotations
@Deprecated
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a suitable hash code for this mutable.

Returns:int

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

Annotations
@Override
isFalseback to summary
public boolean isFalse()

Checks if the current value is false.

Returns:boolean

true if the current value is false

Since
2.5
isTrueback to summary
public boolean isTrue()

Checks if the current value is true.

Returns:boolean

true if the current value is true

Since
2.5
setFalseback to summary
public void setFalse()

Sets the value to false.

Since
3.3
setTrueback to summary
public void setTrue()

Sets the value to true.

Since
3.3
setValueback to summary
public void setValue(final boolean value)

Implements org.apache.commons.lang3.mutable.Mutable.setValue.

Sets the value.

Parameters
value:boolean

the value to set

setValueback to summary
public void setValue(final Boolean value)

Implements org.apache.commons.lang3.mutable.Mutable.setValue.

Sets the value from any Boolean instance.

Parameters
value:Boolean

the value to set, not null

Annotations
@Override
Exceptions
NullPointerException:
if the object is null
toBooleanback to summary
public Boolean toBoolean()

Gets this mutable as an instance of Boolean.

Returns:Boolean

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

Since
2.5
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns the String value of this mutable.

Returns:String

the mutable value as a string

Annotations
@Override