public class NaturalStringComparator extends Object implements Serializable, Comparator<String>
Strings that results is a more
natural ordering than the default ordering outlined by the Java Specification. This
method takes into account the numeric ordering of both initial and internal strings of
digits. For instance, using the list {"10", "5", "20"} as an example, Java's default
comparison would sort it as {"10", "20", "5"} whereas this comparator will sort it as
{"5", "10", "20"}. As a second example, consider the list {"file200.txt",
"file1.txt", "file80.txt"}. The default Java behavior would be to sort the list as
{"file1.txt", "file200.txt", "file80.txt"} while this comparator will sort the list as
{"file1.txt", "file80.txt", "file200.txt"}.long to process each numeric String
segment. As such, the maximum number portion processable by this comparator is 2^63 - 1
or 9,223,372,036,854,775,807 (without the commas, of course).null as the lowest possible String
followed by the empty string ("") followed by all other Strings.
| Constructor and Description |
|---|
NaturalStringComparator() |
| Modifier and Type | Method and Description |
|---|---|
int |
compare(String string1,
String string2)
Compares its two arguments for order.
|
static NaturalStringComparator |
getInstance() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitequalspublic static NaturalStringComparator getInstance()
public int compare(String string1, String string2)
Strings defined by this class.compare in interface Comparator<String>string1 - the first String to be comparedstring2 - the second String to be comparedComparator.compare(java.lang.Object, java.lang.Object)Copyright © 2013 The Kuali Foundation. All Rights Reserved.