|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object PIRL.Conductor.String_Vector_Comparator
public class String_Vector_Comparator
A String_Vector_Comparator implements the Comparator interface to sort Lists of Objects.
It is particularly useful, for example, in sorting a set of results from a Database query. Use an instance of this class as the Comparator in the Collections.sort(List, Comparator) static method, which actually does the sorting. The Objects to be compared are assumed to be Lists. The Objects at the specified index of each List are converted to Strings. If these Strings can be parsed as Doubles then these are compared numerically. Otherwise the Strings are are compared lexicographically.
Field Summary | |
---|---|
static String |
ID
Class identification name with source code version and date. |
Constructor Summary | |
---|---|
String_Vector_Comparator()
Construct a String_Vector_Comparator that will compare index zero of the Lists. |
|
String_Vector_Comparator(int index)
Construct a String_Vector_Comparator using a sepecified index for the Lists to be compared . |
Method Summary | |
---|---|
int |
compare(Object list_0,
Object list_1)
Compare two Lists. |
int |
Index()
Get the List index to be compared . |
String_Vector_Comparator |
Index(int index)
Set the List index to be compared . |
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 String ID
Constructor Detail |
---|
public String_Vector_Comparator(int index)
compared
.
index
- The List index to be compared.public String_Vector_Comparator()
compare
index zero of the Lists.
Method Detail |
---|
public String_Vector_Comparator Index(int index)
compared
.
index
- The List index to be compared.
IllegalArgumentException
- If the index is negative.public int Index()
compared
.
Index(int)
public int compare(Object list_0, Object list_1)
The objects at each List's Index
entry are first
checked for being null. If both are null, 0 is returned; if only
the first is null, -1 is returned; if only the second is null, 1
is returned.
Non-null list entries are converted to a Strings. If these Strings can be converted to Doubles, then they are compared numerically using Double.compareTo. Otherwise they are compared lexicographically using String compareTo.
compare
in interface Comparator
list_0
- The first List for comparison.list_1
- The second List for comparison.
Index
entry is less than, equal to,
or greater than the second List Index
entry.
IllegalArgumentException
- If the arguments are not Lists.
ArrayIndexOutOfBoundsException
- If the arguments do not
have at least Index
+ 1 entries.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |