I am trying to sort a vector with mulitple keys. I can do it with one key by using a Comparator with the following code:
class CompTypeComparator implements Comparator {
public int compare(Object o1, Object o2) {
int j1 = ((CompType)o1).j;
int j2 = ((CompType)o2).j;
return (j1 < j2 ? -1 : (j1 == j2 ? 0 : 1));
}
}
I can even do it on two keys with the following code using the CompareTon where Name is a vector containing a first and last name.
public int compareTo(Object o)
{
Name n = (Name)o;
int lastCmp = lastName.compareTo(n.lastName);
System.out.println(lastName + "/" + n.lastName + "/" + lastCmp);
return (lastCmp!=0 ? lastCmp : firstName.compareTo(n.firstName));
}
How would I use one of these models, or any other, to sort 3 or more strings (keys) i.e. first, mi, and last name?
Thanks in advance.
Jeff Sulman
class CompTypeComparator implements Comparator {
public int compare(Object o1, Object o2) {
int j1 = ((CompType)o1).j;
int j2 = ((CompType)o2).j;
return (j1 < j2 ? -1 : (j1 == j2 ? 0 : 1));
}
}
I can even do it on two keys with the following code using the CompareTon where Name is a vector containing a first and last name.
public int compareTo(Object o)
{
Name n = (Name)o;
int lastCmp = lastName.compareTo(n.lastName);
System.out.println(lastName + "/" + n.lastName + "/" + lastCmp);
return (lastCmp!=0 ? lastCmp : firstName.compareTo(n.firstName));
}
How would I use one of these models, or any other, to sort 3 or more strings (keys) i.e. first, mi, and last name?
Thanks in advance.
Jeff Sulman