aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/sorting/GeocodeComparator.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/cgeo/geocaching/sorting/GeocodeComparator.java')
-rw-r--r--src/cgeo/geocaching/sorting/GeocodeComparator.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/cgeo/geocaching/sorting/GeocodeComparator.java b/src/cgeo/geocaching/sorting/GeocodeComparator.java
new file mode 100644
index 0000000..dd16f08
--- /dev/null
+++ b/src/cgeo/geocaching/sorting/GeocodeComparator.java
@@ -0,0 +1,26 @@
+package cgeo.geocaching.sorting;
+
+import cgeo.geocaching.cgCache;
+
+/**
+ * sorts caches by GC code, therefore effectively sorting by cache age
+ *
+ */
+public class GeocodeComparator extends AbstractCacheComparator {
+
+ @Override
+ protected boolean canCompare(cgCache cache1, cgCache cache2) {
+ return cache1.geocode != null && cache1.geocode.length() > 0
+ && cache2.geocode != null && cache2.geocode.length() > 0;
+ }
+
+ @Override
+ protected int compareCaches(cgCache cache1, cgCache cache2) {
+ if (cache1.geocode.length() > cache2.geocode.length()) {
+ return 1;
+ } else if (cache2.geocode.length() > cache1.geocode.length()) {
+ return -1;
+ }
+ return cache1.geocode.compareToIgnoreCase(cache2.geocode);
+ }
+}