Package uk.ac.ebi.utils.collections
Class AlphaNumComparator<T>
java.lang.Object
uk.ac.ebi.utils.collections.AlphaNumComparator<T>
- All Implemented Interfaces:
Comparator<T>
The Alphanum Algorithm is an improved sorting algorithm for strings
containing numbers. Instead of sorting numbers in ASCII order like
a standard sort, this algorithm sorts numbers in numeric order.
The Alphanum Algorithm is discussed at http://www.DaveKoelle.com
This is an updated version with enhancements made by Daniel Migowski, Andre Bogus, and David Koelle.
To convert to use Templates (Java 1.5+): - Change "implements Comparator" to "implements Comparator" - Change
"compare(Object o1, Object o2)" to "compare(String s1, String s2)" - Remove the type checking and casting in
compare().
To use this class: for example, use the static "sort" method from the
for examples.
Collections class:
Collections.sort(your list, new AlphanumComparator()); See
invalid reference
AlphaNumComparatorTest
Notes
- null is considered lower than anything else.
- "Item 3" comes before "Item 01", when you have zero-padding, it is taken into account.
-
Constructor Summary
Constructors -
Method Summary
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
-
Constructor Details
-
AlphaNumComparator
public AlphaNumComparator(boolean isCaseSensitive) Default is true -
AlphaNumComparator
public AlphaNumComparator()Default is true
-
-
Method Details
-
compare
- Specified by:
comparein interfaceComparator<T>
-