Package jodd.util
Class NaturalOrderComparator<T>
java.lang.Object
jodd.util.NaturalOrderComparator<T>
- All Implemented Interfaces:
Serializable,Comparator<T>
Probably the best natural strings comparator.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final char[]protected final booleanprotected final booleanprotected final boolean -
Constructor Summary
ConstructorsConstructorDescriptionNaturalOrderComparator(boolean ignoreCase, boolean ignoreAccents, boolean skipSpaces) -
Method Summary
Modifier and TypeMethodDescriptionprivate static charSafecharAtthat returns 0 when ndx is out of boundaries.intprotected int[]compareDigits(String str1, int ndx1, String str2, int ndx2) Compare digits at certain position in two strings.private charfixAccent(char c) Fixes accent char.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
ACCENT_CHARS
private static final char[] ACCENT_CHARS -
ignoreCase
protected final boolean ignoreCase -
ignoreAccents
protected final boolean ignoreAccents -
skipSpaces
protected final boolean skipSpaces
-
-
Constructor Details
-
NaturalOrderComparator
public NaturalOrderComparator() -
NaturalOrderComparator
public NaturalOrderComparator(boolean ignoreCase, boolean ignoreAccents, boolean skipSpaces)
-
-
Method Details
-
compareDigits
Compare digits at certain position in two strings. The longest run of digits wins. That aside, the greatest value wins.- Returns:
- if numbers are different, only 1 element is returned.
-
compare
- Specified by:
comparein interfaceComparator<T>
-
fixAccent
private char fixAccent(char c) Fixes accent char. -
charAt
SafecharAtthat returns 0 when ndx is out of boundaries.
-