Class NaturalSortCollator

java.lang.Object
java.text.Collator
org.jhotdraw8.base.text.NaturalSortCollator
All Implemented Interfaces:
Cloneable, Comparator<Object>

public class NaturalSortCollator extends Collator
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.
If java.text.Collator.getInstance() does not return an instance of java.text.RuleBasedCollator, then the returned collator is used, and only sequences of digits are changed to match the collation rules of Mac OS X.
Author:
Werner Randelshofer