Package de.undercouch.citeproc.helper
Class AlphanumComparator
- java.lang.Object
-
- de.undercouch.citeproc.helper.AlphanumComparator
-
- All Implemented Interfaces:
Comparator<CharSequence>
public class AlphanumComparator extends Object implements Comparator<CharSequence>
Performs locale-sensitive comparison of
Strings with numbers to produce a natural order that appears logical to humans.Examples:
compare("Hello", "Hello") = 0 compare("10", "2") = 1 compare("10th", "2nd") = 1 compare("File 10", "File 2") = 1 compare("Manana", "MaƱana") = -1The implementation is loosely based on the Alphanum algorithm by Dave Koelle and the Java implementation released under the MIT license. However, it has been extended to use a
Collatorfor locale-sensitive comparison, and it is also able to compare arbitrarily large numbers.- Author:
- Michel Kraemer
-
-
Constructor Summary
Constructors Constructor Description AlphanumComparator(Locale locale)Create a new comparator for the given locale
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompare(CharSequence a, CharSequence b)-
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 Detail
-
AlphanumComparator
public AlphanumComparator(Locale locale)
Create a new comparator for the given locale- Parameters:
locale- the locale
-
-
Method Detail
-
compare
public int compare(CharSequence a, CharSequence b)
- Specified by:
comparein interfaceComparator<CharSequence>
-
-