Package org.moeaframework.util
Class NumericStringComparator
java.lang.Object
org.moeaframework.util.NumericStringComparator
- All Implemented Interfaces:
Comparator<String>
Sorts strings containing numeric values.
The string is split into sections that contain numeric and non-numeric characters, with each section sorted
independently. Numeric sections are sorted by their natural order (e.g., 1, 2, 3
), whereas non-numeric
are sorted lexicographically. The following table demonstrates the difference:
Regular Sort Numeric Sort ------------ ------------ Value1 Value1 Value10 Value2 Value11 Value10 Value2 Value11 Value20 Value20 Value21 Value21
-
Constructor Summary
-
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
NumericStringComparator
public NumericStringComparator()Creates a new numeric string comparator.
-
-
Method Details
-
compare
- Specified by:
compare
in interfaceComparator<String>
-