|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.rhq.core.util.sort.HumaneStringComparator
public class HumaneStringComparator
A comparator for Strings that imposes a more "human" order on Strings. Modeled on the way the Mac OS X Finder orders file names, it breaks the Strings into segments of non-numbers and numbers (e.g. Foo123Bar into 'Foo', 123, 'Bar') and compares the segments from each String one at a time.
The following rules are applied when comparing segments:
If two Strings are identical after analyzing them in a segment-at-time manner then lhs.compareTo(rhs) will be invoked to ensure that the result provided by the comparator is reflexive (i.e. compare(x,y) = -compare(y,x)) and agrees with String.equals() in all cases.
As an example, the following list of Strings is presented in the order in which the comparator will sort them:
| Field Summary | |
|---|---|
static HumaneStringComparator |
DEFAULT
A default instance of the comparator that can be used without instantiating a new copy every time one is needed. |
| Constructor Summary | |
|---|---|
HumaneStringComparator()
|
|
| Method Summary | |
|---|---|
int |
compare(String lhs,
String rhs)
The implementation of the Comparable interface method that compares two Strings. |
protected int |
compareNumberSegments(String lhs,
String rhs)
Converts the two Strings to doubles and then compares then numerically by invoking Double.compareTo() |
protected int |
compareStringSegments(String lhs,
String rhs)
Compares the left hand String to the right hand String case-insensitively by invoking lhs.compareToIgnoreCase(rhs). |
| 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 |
| Field Detail |
|---|
public static final HumaneStringComparator DEFAULT
| Constructor Detail |
|---|
public HumaneStringComparator()
| Method Detail |
|---|
public int compare(String lhs,
String rhs)
compare in interface Comparator<String>lhs - the first of two Strings to comparerhs - the second of two Strings to compare
protected int compareNumberSegments(String lhs,
String rhs)
protected int compareStringSegments(String lhs,
String rhs)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||