Class AlphanumComparator
java.lang.Object
net.okapia.osid.torrefacto.util.AlphanumComparator
- All Implemented Interfaces:
Comparator<String>
Compares strings so that embedded runs of digits sort by numeric
value rather than character by character:
"z2" sorts before
"z10", and "file9" before "file10". Each
string is split into alternating chunks of digits and non-digits;
digit chunks are compared as numbers and the remaining chunks are
compared with a delegate comparator (natural string order by
default).
This is Dave Koelle's Alphanum algorithm; see
http://www.DaveKoelle.com.-
Constructor Summary
ConstructorsConstructorDescriptionConstructs anAlphanumComparatorthat orders non-numeric chunks in natural string order.AlphanumComparator(Comparator<String> comparator) Constructs anAlphanumComparatorthat orders non-numeric chunks with the given comparator. -
Method Summary
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Comparator
equals, max, min, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
AlphanumComparator
public AlphanumComparator()Constructs anAlphanumComparatorthat orders non-numeric chunks in natural string order. -
AlphanumComparator
Constructs anAlphanumComparatorthat orders non-numeric chunks with the given comparator.- Parameters:
comparator- the comparator for non-numeric chunks
-
-
Method Details
-
compare
Compares two strings by the alphanum rule.- Specified by:
comparein interfaceComparator<String>- Parameters:
s1- the first strings2- the second string- Returns:
- a negative integer, zero, or a positive integer as
s1sorts before, equal to, or afters2
-