Package org.apache.wiki.util.comparators
Class HumanComparator
java.lang.Object
org.apache.wiki.util.comparators.HumanComparator
- All Implemented Interfaces:
Comparator<String>
A comparator that sorts Strings using "human" ordering, including decimal
ordering. Only works for languages where every character is lexicographically
distinct and correctly unicode ordered (e.g. English). Other languages should use
CollatedHumanComparator
. Pretty efficient but still slower than
String.compareTo().-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor which does nothing.HumanComparator
(HumanComparator.CharType[] sortOrder) Constructor specifying all the character type order. -
Method Summary
Modifier and TypeMethodDescriptionint
static Comparator<String>
Returns a singleton comparator that implements the default behaviour.void
setSortOrder
(HumanComparator.CharType[] sortOrder) Set the order in which letters, numbers and everything else is presented.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
-
Field Details
-
DEFAULT_HUMAN_COMPARATOR
-
-
Constructor Details
-
HumanComparator
public HumanComparator()Default constructor which does nothing. Here because it has a non-default constructor. -
HumanComparator
Constructor specifying all the character type order.- Parameters:
sortOrder
- see setSortOrder
-
-
Method Details
-
getInstance
Returns a singleton comparator that implements the default behaviour.- Returns:
- the singleton comparator.
-
compare
- Specified by:
compare
in interfaceComparator<String>
-
getSortOrder
-
setSortOrder
Set the order in which letters, numbers and everything else is presented. Default is other, digits and then letters. For example, the strings "abb", "a1b" and "a b" will sort in the order "a b", "a1b" then "abb" by default.- Parameters:
sortOrder
- Must be an array ofCharType
containing exactly 3 elements each of which must be distinct.- Throws:
IllegalArgumentException
- if being called on the result ofHumanStringComparator.getInstance()
orsortOrder
is not exactly 3 differentCharType
.
-