java.lang.Object
java.text.Collator
org.jhotdraw8.base.text.NaturalSortCollator
- All Implemented Interfaces:
Cloneable,Comparator<Object>
Collator for sorting numbers that are embedded in Strings as if they were
a single numeric character.
This collator strives to match the collation rules used by the Mac OS X Finder and of Mac OS X file dialogs.
If we wanted to match the OS X collation rules exactly, we would have to implement the rules for all languages supported by Mac OS X and Java. To reduce the amount of work needed for implementing these rules, the OSXCollator changes the collation rules returned by java.text.Collator.getInstance() to do the following:
- Space characters are treated as primary collation differences
- Hyphen characters are treated as primary collation differences
- Sequence of digits (characters '0' through '9') is treated as a single collation object. The current implementation supports sequences of up to 999 characters length.
- Author:
- Werner Randelshofer
-
Field Summary
Fields inherited from class java.text.Collator
CANONICAL_DECOMPOSITION, FULL_DECOMPOSITION, IDENTICAL, NO_DECOMPOSITION, PRIMARY, SECONDARY, TERTIARY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintstatic <T> @NonNull Comparator<T> booleangetCollationKey(@NonNull String source) inthashCode()Methods inherited from class java.text.Collator
clone, compare, equals, getAvailableLocales, getDecomposition, getInstance, getInstance, getStrength, setDecomposition, setStrengthMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
NaturalSortCollator
public NaturalSortCollator()Creates a new instance. -
NaturalSortCollator
-
-
Method Details
-
comparing
public static <T> @NonNull Comparator<T> comparing(@NonNull Function<? super T, String> keyExtractor) -
compare
-
equals
- Specified by:
equalsin interfaceComparator<Object>- Overrides:
equalsin classCollator
-
getCollationKey
- Specified by:
getCollationKeyin classCollator
-
hashCode
public int hashCode()
-