Class FloatValue
This class extends Value<Float> and provides a convenient way to pass mutable
float references to lambdas, inner classes, or methods.
Notes:
- This class is not thread-safe.
Example:
See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FloatValuecreate()Creates a new float value initialized to0.0f .booleanis(float other, float precision) Checks if the current value equals the specified value within the given precision.booleanisAny(float precision, float... values) Checks if the current value matches any of the specified values within the given precision.static FloatValueCreates a new float value with the specified initial value.
-
Constructor Details
-
FloatValue
Constructor.- Parameters:
value- The initial value.
-
-
Method Details
-
create
Creates a new float value initialized to0.0f .Example:
FloatValue
value = FloatValue.create ();assertEquals (0.0f,value .get());- Returns:
- A new float value.
-
of
Creates a new float value with the specified initial value.Example:
FloatValue
value = FloatValue.of (3.14f);assertEquals (3.14f,value .get());- Parameters:
value- The initial value.- Returns:
- A new float value.
-
is
Checks if the current value equals the specified value within the given precision.This method handles
null values safely and performs precision-based equality comparison using absolute difference. The comparison returnstrue if the absolute difference between the two values is less than or equal to the specified precision.Example:
FloatValue
value = FloatValue.of (3.14f);assertTrue (value .is(3.14f, 0.01f));// Exact match within 0.01 assertTrue (value .is(3.15f, 0.02f));// Within 0.02 assertFalse (value .is(3.15f, 0.001f));// Not within 0.001 // Handles null values FloatValueempty = FloatValue.create ();empty .set(null );assertFalse (empty .is(3.14f, 0.01f));// Null doesn't match any value // Precision-based comparison FloatValuepi = FloatValue.of (3.14159f);assertTrue (pi .is(3.14f, 0.002f));// Within 0.002 precision - Parameters:
other- The value to compare with.precision- The maximum allowed difference for equality. Must be non-negative.- Returns:
true if the absolute difference between the values is less than or equal to precision.- Throws:
IllegalArgumentException- if precision is negative.
-
isAny
Checks if the current value matches any of the specified values within the given precision.This method handles
null values safely and performs precision-based equality comparison for each value using absolute difference.Example:
FloatValue
value = FloatValue.of (3.14f);assertTrue (value .isAny(0.01f, 2.5f, 3.15f, 5.0f));// Matches 3.15f within 0.01 assertFalse (value .isAny(0.001f, 1.0f, 2.0f, 5.0f));// No match within 0.001 // Empty array returns false assertFalse (value .isAny(0.01f));- Parameters:
precision- The maximum allowed difference for equality. Must be non-negative and is the first parameter.values- The values to compare to.- Returns:
true if the current value matches any of the specified values within the precision.- Throws:
IllegalArgumentException- if precision is negative.
-