Class AlphanumComparator
java.lang.Object
de.gurkenlabs.litiengine.util.AlphanumComparator
- All Implemented Interfaces:
Comparator<String>
This is an updated version with enhancements made by Daniel Migowski, Andre Bogus, and David Koelle. Updated by David Koelle in 2017.
To use this class: Use the static "sort" method from the java.util.Collections class: Collections.sort(your list, new AlphanumComparator());
-
Constructor Summary
Constructors -
Method Summary
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 Details
-
AlphanumComparator
public AlphanumComparator()
-
-
Method Details
-
compare
Compares two strings using the Alphanum algorithm. This method compares two strings by breaking them into chunks of numeric and non-numeric characters and comparing these chunks numerically and lexicographically.- Specified by:
compare
in interfaceComparator<String>
- Parameters:
s1
- the first string to compares2
- the second string to compare- Returns:
- a negative integer, zero, or a positive integer as the first string is less than, equal to, or greater than the second string
-
compareTo
Compares two strings using the Alphanum algorithm. This method compares two strings by breaking them into chunks of numeric and non-numeric characters and comparing these chunks numerically and lexicographically.- Parameters:
s1
- the first string to compares2
- the second string to compare- Returns:
- a negative integer, zero, or a positive integer as the first string is less than, equal to, or greater than the second string
-