blob: fff26c6fef383c8825c83093a3a0cdf312b8f693 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
package cgeo.geocaching.sorting;
import cgeo.geocaching.Geocache;
import org.apache.commons.lang3.StringUtils;
/**
* sorts caches by geo code, therefore effectively sorting by cache age
*
*/
public class GeocodeComparator extends AbstractCacheComparator {
@Override
protected boolean canCompare(Geocache cache1, Geocache cache2) {
return StringUtils.isNotBlank(cache1.getGeocode())
&& StringUtils.isNotBlank(cache2.getGeocode());
}
@Override
protected int compareCaches(final Geocache cache1, final Geocache cache2) {
final int lengthDiff = cache1.getGeocode().length() - cache2.getGeocode().length();
return lengthDiff != 0 ? lengthDiff : cache1.getGeocode().compareToIgnoreCase(cache2.getGeocode());
}
}
|