aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/sorting/VoteComparator.java
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2011-07-23 21:52:13 +0200
committerBananeweizen <bananeweizen@gmx.de>2011-07-23 21:52:13 +0200
commit0454ba218fd2d9add5c663c9799b80b59a259eff (patch)
treeccabf3e3be73210fdfa4cb39633731e84122f16d /src/cgeo/geocaching/sorting/VoteComparator.java
parent6d33eb1f7022544c145400845a4f084f1610ffa8 (diff)
downloadcgeo-0454ba218fd2d9add5c663c9799b80b59a259eff.zip
cgeo-0454ba218fd2d9add5c663c9799b80b59a259eff.tar.gz
cgeo-0454ba218fd2d9add5c663c9799b80b59a259eff.tar.bz2
move all comparators to a new package
extract interface and common implementation details of sorting
Diffstat (limited to 'src/cgeo/geocaching/sorting/VoteComparator.java')
-rw-r--r--src/cgeo/geocaching/sorting/VoteComparator.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/cgeo/geocaching/sorting/VoteComparator.java b/src/cgeo/geocaching/sorting/VoteComparator.java
new file mode 100644
index 0000000..0039c7c
--- /dev/null
+++ b/src/cgeo/geocaching/sorting/VoteComparator.java
@@ -0,0 +1,39 @@
+package cgeo.geocaching.sorting;
+
+import cgeo.geocaching.cgCache;
+
+/**
+ * sorts caches by the users own voting (if available at all)
+ *
+ * @author bananeweizen
+ *
+ */
+public class VoteComparator extends AbstractCacheComparator {
+
+ @Override
+ protected boolean canCompare(cgCache cache1, cgCache cache2) {
+ return true;
+ }
+
+ @Override
+ protected int compareCaches(cgCache cache1, cgCache cache2) {
+ // if there is no vote available, put that cache at the end of the list
+ float vote1 = 0;
+ if (cache1.myVote != null) {
+ vote1 = cache1.myVote;
+ }
+
+ float vote2 = 0;
+ if (cache2.myVote != null) {
+ vote2 = cache2.myVote;
+ }
+
+ // compare
+ if (vote1 < vote2) {
+ return 1;
+ } else if (vote2 < vote1) {
+ return -1;
+ }
+ return 0;
+ }
+}