Hello
,
what should I do to use the
find() method on a SimpleSortingList instance?
I have a
SimpleSortingList of Stations, which look like this:
public
Station {
private String name;
//....
//....something other
//....
public String getName() { return this.name; }
//....
}
I created a comparator:
private class
StationNameComparator implements
Comparator {
public int compare(Object o1, Object o2) {if (o1 == null || o2 == null) {return 0;
}
String n1 = ((Station)o1).getName().toLowerCase();
String n2 = ((Station)o2).getName().toLowerCase();
return n1.compareTo(n2);
}
}
so the sorting should work:
public void
sortStationList() {
stationList.setSortComparator(new StationNameComparator());
stationList.reSort();
}
But what should I do to get
find work? I need to find a Station according to some string in it's name (for example, I give a string "ri" and I get a station with a name "Paris").
According to the BlackBerry rim API the find() method returns:
If an object matching the given key exists in the vector (
as determined by the comparator), the index of the matching element in the vector is returned. If a matching object could not be found, then -(insertionPoint + 1) is returned.
But what should I define in the comparator to get this to work with the Station names?
Please help me with this, thanks.