Package io.github.connellite.util
Record Class NumberUtils.FloatComparator
java.lang.Object
java.lang.Record
io.github.connellite.util.NumberUtils.FloatComparator
- All Implemented Interfaces:
Comparator<Float>
- Enclosing class:
- NumberUtils
public static record NumberUtils.FloatComparator(float epsilon)
extends Record
implements Comparator<Float>
Comparator for
Float values with epsilon-based equality.
Values whose difference is within epsilon are treated as equal (compare returns 0).-
Constructor Summary
ConstructorsConstructorDescriptionCreates comparator with default epsilon (1e-6).FloatComparator(float epsilon) Creates comparator with custom epsilon. -
Method Summary
Modifier and TypeMethodDescriptionintfloatepsilon()Returns the value of theepsilonrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.final StringtoString()Returns a string representation of this record class.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
FloatComparator
public FloatComparator()Creates comparator with default epsilon (1e-6). -
FloatComparator
public FloatComparator(float epsilon) Creates comparator with custom epsilon.- Parameters:
epsilon- allowed absolute difference (must be non-negative and finite)
-
-
Method Details
-
compare
- Specified by:
comparein interfaceComparator<Float>
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.- Specified by:
equalsin interfaceComparator<Float>- Specified by:
equalsin classRecord- Parameters:
o- the object with which to compare- Returns:
trueif this object is the same as theoargument;falseotherwise.
-
epsilon
public float epsilon()Returns the value of theepsilonrecord component.- Returns:
- the value of the
epsilonrecord component
-