aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorMichael Keppler <bananeweizen@gmx.de>2013-12-25 08:35:23 +0100
committerMichael Keppler <bananeweizen@gmx.de>2013-12-25 08:35:23 +0100
commit85c55996229f67b013f6e076826a42d9d830baeb (patch)
treeb574e9551a58db131b747110f0fb456d05b6f810 /main
parent7cdf30c21ad29c0b51e3a2e44f86932e981817a0 (diff)
downloadcgeo-85c55996229f67b013f6e076826a42d9d830baeb.zip
cgeo-85c55996229f67b013f6e076826a42d9d830baeb.tar.gz
cgeo-85c55996229f67b013f6e076826a42d9d830baeb.tar.bz2
fix #3473: GCVote on non GC caches
Diffstat (limited to 'main')
-rw-r--r--main/src/cgeo/geocaching/gcvote/GCVote.java31
1 files changed, 22 insertions, 9 deletions
diff --git a/main/src/cgeo/geocaching/gcvote/GCVote.java b/main/src/cgeo/geocaching/gcvote/GCVote.java
index b245aa9..fd4b914 100644
--- a/main/src/cgeo/geocaching/gcvote/GCVote.java
+++ b/main/src/cgeo/geocaching/gcvote/GCVote.java
@@ -11,8 +11,10 @@ import cgeo.geocaching.utils.MatcherWrapper;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.eclipse.jdt.annotation.NonNull;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -219,19 +221,12 @@ public final class GCVote {
return result != null && result.trim().equalsIgnoreCase("ok");
}
- public static void loadRatings(final ArrayList<Geocache> caches) {
+ public static void loadRatings(final @NonNull ArrayList<Geocache> caches) {
if (!Settings.isRatingWanted()) {
return;
}
- final ArrayList<String> geocodes = new ArrayList<String>(caches.size());
- for (final Geocache cache : caches) {
- String geocode = cache.getGeocode();
- if (StringUtils.isNotBlank(geocode)) {
- geocodes.add(geocode);
- }
- }
-
+ final ArrayList<String> geocodes = getVotableGeocodes(caches);
if (geocodes.isEmpty()) {
return;
}
@@ -256,6 +251,24 @@ public final class GCVote {
}
}
+ /**
+ * Get geocodes of all the caches, which can be used with GCVote. Non-GC caches will be filtered out.
+ *
+ * @param caches
+ * @return
+ */
+ private static @NonNull
+ ArrayList<String> getVotableGeocodes(final @NonNull Collection<Geocache> caches) {
+ final ArrayList<String> geocodes = new ArrayList<String>(caches.size());
+ for (final Geocache cache : caches) {
+ String geocode = cache.getGeocode();
+ if (StringUtils.isNotBlank(geocode) && cache.supportsGCVote()) {
+ geocodes.add(geocode);
+ }
+ }
+ return geocodes;
+ }
+
public static boolean isValidRating(final float rating) {
return rating >= MIN_RATING && rating <= MAX_RATING;
}