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

public Class MutableFloat

extends Number
implements Comparable<MutableFloat>, Mutable<Number>
Class Inheritance
All Implemented Interfaces
org.apache.commons.lang3.mutable.Mutable, java.util.function.Supplier, java.lang.Comparable
Imports
java.util.concurrent.atomic.DoubleAccumulator, .DoubleAdder

A mutable float wrapper.

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

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

Since
2.1
See Also
Float, DoubleAccumulator, DoubleAdder

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Hides java.lang.Number.serialVersionUID.

Required for serialization support.
private float
value

The mutable value.

Constructor Summary

AccessConstructor and Description
public
MutableFloat()

Constructs a new MutableFloat with the default value of zero.

public
MutableFloat(final float
the initial value to store.
value
)

Constructs a new MutableFloat with the specified value.

public
MutableFloat(final Number
the initial value to store, not null.
value
)

Constructs a new MutableFloat with the specified value.

public
MutableFloat(final String
the string to parse, not null.
value
)

Constructs a new MutableFloat parsing the given string.

Method Summary

Modifier and TypeMethod and Description
public void
add(final float
the value to add, not null.
operand
)

Adds a value to the value of this instance.

public void
add(final Number
the value to add, not null.
operand
)

Adds a value to the value of this instance.

public float

Returns:

the value associated with this instance after adding the operand.
addAndGet
(final float
the quantity to add, not null.
operand
)

Increments this instance's value by operand; this method returns the value associated with the instance immediately after the addition operation.

public float

Returns:

the value associated with this instance after adding the operand.
addAndGet
(final Number
the quantity to add, not null.
operand
)

Increments this instance's value by operand; this method returns the value associated with the instance immediately after the addition operation.

public int

Returns:

negative if this is less, zero if equal, positive if greater.
compareTo
(final MutableFloat
the other mutable to compare to, not null.
other
)

Implements java.lang.Comparable.compareTo.

Compares this mutable to another in ascending order.

public void
decrement()

Decrements the value.

public float

Returns:

the value associated with the instance after it is decremented.
decrementAndGet
()

Decrements this instance's value by 1; this method returns the value associated with the instance immediately after the decrement operation.

public double

Returns:

the numeric value represented by this object after conversion to type double.
doubleValue
()

Implements abstract java.lang.Number.doubleValue.

Returns the value of this MutableFloat as a double.

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 against some other object.

public float

Returns:

the numeric value represented by this object after conversion to type float.
floatValue
()

Implements abstract java.lang.Number.floatValue.

Returns the value of this MutableFloat as a float.

public float

Returns:

the value associated with this instance immediately before the operand was added.
getAndAdd
(final float
the quantity to add, not null.
operand
)

Increments this instance's value by operand; this method returns the value associated with the instance immediately prior to the addition operation.

public float

Returns:

the value associated with this instance immediately before the operand was added.
getAndAdd
(final Number
the quantity to add, not null.
operand
)

Increments this instance's value by operand; this method returns the value associated with the instance immediately prior to the addition operation.

public float

Returns:

the value associated with the instance before it was decremented.
getAndDecrement
()

Decrements this instance's value by 1; this method returns the value associated with the instance immediately prior to the decrement operation.

public float

Returns:

the value associated with the instance before it was incremented.
getAndIncrement
()

Increments this instance's value by 1; this method returns the value associated with the instance immediately prior to the increment operation.

public Float

Returns:

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

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

Deprecated Use get().

Gets the value as a Float instance.

public int

Returns:

a suitable hash code.
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a suitable hash code for this mutable.

public void
increment()

Increments the value.

public float

Returns:

the value associated with the instance after it is incremented.
incrementAndGet
()

Increments this instance's value by 1; this method returns the value associated with the instance immediately after the increment operation.

public int

Returns:

the numeric value represented by this object after conversion to type int.
intValue
()

Implements abstract java.lang.Number.intValue.

Returns the value of this MutableFloat as an int.

public boolean

Returns:

true if infinite
isInfinite
()

Checks whether the float value is infinite.

public boolean

Returns:

true if NaN.
isNaN
()

Checks whether the float value is the special NaN value.

public long

Returns:

the numeric value represented by this object after conversion to type long.
longValue
()

Implements abstract java.lang.Number.longValue.

Returns the value of this MutableFloat as a long.

public void
setValue(final float
the value to set.
value
)

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

Sets the value.

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

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

Sets the value from any Number instance.

public void
subtract(final float
the value to subtract.
operand
)

Subtracts a value from the value of this instance.

public void
subtract(final Number
the value to subtract, not null.
operand
)

Subtracts a value from the value of this instance.

public Float

Returns:

a Float instance containing the value from this mutable, never null.
toFloat
()

Gets this mutable as an instance of Float.

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.Number:
byteValueshortValue

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.lang.Number.serialVersionUID.

Required for serialization support.

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

The mutable value.

Constructor Detail

MutableFloatback to summary
public MutableFloat()

Constructs a new MutableFloat with the default value of zero.

MutableFloatback to summary
public MutableFloat(final float value)

Constructs a new MutableFloat with the specified value.

Parameters
value:float

the initial value to store.

MutableFloatback to summary
public MutableFloat(final Number value)

Constructs a new MutableFloat with the specified value.

Parameters
value:Number

the initial value to store, not null.

Exceptions
NullPointerException:
if the object is null.
MutableFloatback to summary
public MutableFloat(final String value)

Constructs a new MutableFloat parsing the given string.

Parameters
value:String

the string to parse, not null.

Exceptions
NumberFormatException:
if the string cannot be parsed into a float, see Float#parseFloat(String).
Since
2.5

Method Detail

addback to summary
public void add(final float operand)

Adds a value to the value of this instance.

Parameters
operand:float

the value to add, not null.

Since
2.2
addback to summary
public void add(final Number operand)

Adds a value to the value of this instance.

Parameters
operand:Number

the value to add, not null.

Exceptions
NullPointerException:
if the object is null.
Since
2.2
addAndGetback to summary
public float addAndGet(final float operand)

Increments this instance's value by operand; this method returns the value associated with the instance immediately after the addition operation. This method is not thread safe.

Parameters
operand:float

the quantity to add, not null.

Returns:float

the value associated with this instance after adding the operand.

Since
3.5
addAndGetback to summary
public float addAndGet(final Number operand)

Increments this instance's value by operand; this method returns the value associated with the instance immediately after the addition operation. This method is not thread safe.

Parameters
operand:Number

the quantity to add, not null.

Returns:float

the value associated with this instance after adding the operand.

Exceptions
NullPointerException:
if operand is null.
Since
3.5
compareToback to summary
public int compareTo(final MutableFloat other)

Implements java.lang.Comparable.compareTo.

Compares this mutable to another in ascending order.

Parameters
other:MutableFloat

the other mutable to compare to, not null.

Returns:int

negative if this is less, zero if equal, positive if greater.

Annotations
@Override
decrementback to summary
public void decrement()

Decrements the value.

Since
2.2
decrementAndGetback to summary
public float decrementAndGet()

Decrements this instance's value by 1; this method returns the value associated with the instance immediately after the decrement operation. This method is not thread safe.

Returns:float

the value associated with the instance after it is decremented.

Since
3.5
doubleValueback to summary
public double doubleValue()

Implements abstract java.lang.Number.doubleValue.

Returns the value of this MutableFloat as a double.

Returns:double

the numeric value represented by this object after conversion to type double.

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

Overrides java.lang.Object.equals.

Compares this object against some other object. The result is true if and only if the argument is not null and is a Float object that represents a float that has the identical bit pattern to the bit pattern of the float represented by this object. For this purpose, two float values are considered to be the same if and only if the method Float#floatToIntBits(float)returns the same int value when applied to each.

Note that in most cases, for two instances of class Float,f1 and f2, the value of f1.equals(f2) is true if and only if:

f1.floatValue() == f2.floatValue()

also has the value true. However, there are two exceptions:

  • If f1 and f2 both represent Float.NaN, then the equals method returns true, even though Float.NaN == Float.NaN has the value false.
  • If f1 represents +0.0f while f2 represents -0.0f, or vice versa, the equal test has the value false, even though 0.0f == -0.0f has the value true.

This definition allows hashtables to operate properly.

Parameters
obj:Object

the object to compare with, null returns false.

Returns:boolean

true if the objects are the same; false otherwise.

Annotations
@Override
See Also
Float#floatToIntBits(float)
floatValueback to summary
public float floatValue()

Implements abstract java.lang.Number.floatValue.

Returns the value of this MutableFloat as a float.

Returns:float

the numeric value represented by this object after conversion to type float.

Annotations
@Override
getAndAddback to summary
public float getAndAdd(final float operand)

Increments this instance's value by operand; this method returns the value associated with the instance immediately prior to the addition operation. This method is not thread safe.

Parameters
operand:float

the quantity to add, not null.

Returns:float

the value associated with this instance immediately before the operand was added.

Since
3.5
getAndAddback to summary
public float getAndAdd(final Number operand)

Increments this instance's value by operand; this method returns the value associated with the instance immediately prior to the addition operation. This method is not thread safe.

Parameters
operand:Number

the quantity to add, not null.

Returns:float

the value associated with this instance immediately before the operand was added.

Exceptions
NullPointerException:
if operand is null.
Since
3.5
getAndDecrementback to summary
public float getAndDecrement()

Decrements this instance's value by 1; this method returns the value associated with the instance immediately prior to the decrement operation. This method is not thread safe.

Returns:float

the value associated with the instance before it was decremented.

Since
3.5
getAndIncrementback to summary
public float getAndIncrement()

Increments this instance's value by 1; this method returns the value associated with the instance immediately prior to the increment operation. This method is not thread safe.

Returns:float

the value associated with the instance before it was incremented.

Since
3.5
getValueback to summary
public Float getValue()

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

Deprecated

Use get().

Gets the value as a Float instance.

Returns:Float

the value as a Float, 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

a suitable hash code.

Annotations
@Override
incrementback to summary
public void increment()

Increments the value.

Since
2.2
incrementAndGetback to summary
public float incrementAndGet()

Increments this instance's value by 1; this method returns the value associated with the instance immediately after the increment operation. This method is not thread safe.

Returns:float

the value associated with the instance after it is incremented.

Since
3.5
intValueback to summary
public int intValue()

Implements abstract java.lang.Number.intValue.

Returns the value of this MutableFloat as an int.

Returns:int

the numeric value represented by this object after conversion to type int.

Annotations
@Override
isInfiniteback to summary
public boolean isInfinite()

Checks whether the float value is infinite.

Returns:boolean

true if infinite

isNaNback to summary
public boolean isNaN()

Checks whether the float value is the special NaN value.

Returns:boolean

true if NaN.

longValueback to summary
public long longValue()

Implements abstract java.lang.Number.longValue.

Returns the value of this MutableFloat as a long.

Returns:long

the numeric value represented by this object after conversion to type long.

Annotations
@Override
setValueback to summary
public void setValue(final float value)

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

Sets the value.

Parameters
value:float

the value to set.

setValueback to summary
public void setValue(final Number value)

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

Sets the value from any Number instance.

Parameters
value:Number

the value to set, not null.

Annotations
@Override
Exceptions
NullPointerException:
if the object is null.
subtractback to summary
public void subtract(final float operand)

Subtracts a value from the value of this instance.

Parameters
operand:float

the value to subtract.

Since
2.2
subtractback to summary
public void subtract(final Number operand)

Subtracts a value from the value of this instance.

Parameters
operand:Number

the value to subtract, not null.

Exceptions
NullPointerException:
if the object is null.
Since
2.2
toFloatback to summary
public Float toFloat()

Gets this mutable as an instance of Float.

Returns:Float

a Float instance containing the value from this mutable, never null.

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