aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2013-01-31 07:30:23 +0100
committerBananeweizen <bananeweizen@gmx.de>2013-01-31 07:30:23 +0100
commit00b36f16e4768da7b252f31089ce1cfd19b2c2c6 (patch)
treec23db4a657680331eab1d67c87ea52eb1ef38708
parenta47c952b407762d145636f2a867e2e47cf85c24d (diff)
downloadcgeo-00b36f16e4768da7b252f31089ce1cfd19b2c2c6.zip
cgeo-00b36f16e4768da7b252f31089ce1cfd19b2c2c6.tar.gz
cgeo-00b36f16e4768da7b252f31089ce1cfd19b2c2c6.tar.bz2
refactoring: simplify cache type checks
-rw-r--r--main/src/cgeo/geocaching/CacheCache.java2
-rw-r--r--main/src/cgeo/geocaching/SearchResult.java2
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCMap.java2
-rw-r--r--main/src/cgeo/geocaching/enumerations/CacheType.java17
-rw-r--r--tests/src/cgeo/geocaching/enumerations/CacheTypeTest.java11
5 files changed, 31 insertions, 3 deletions
diff --git a/main/src/cgeo/geocaching/CacheCache.java b/main/src/cgeo/geocaching/CacheCache.java
index e027a8a..4b68728 100644
--- a/main/src/cgeo/geocaching/CacheCache.java
+++ b/main/src/cgeo/geocaching/CacheCache.java
@@ -87,7 +87,7 @@ public class CacheCache {
Log.e("CacheCache.getInViewport: got cache with null coordinates: " + cache.getGeocode());
continue;
}
- if ((CacheType.ALL == cacheType || cache.getType() == cacheType) && viewport.contains(cache)) {
+ if (cacheType.contains(cache) && viewport.contains(cache)) {
geocodes.add(cache.getGeocode());
}
}
diff --git a/main/src/cgeo/geocaching/SearchResult.java b/main/src/cgeo/geocaching/SearchResult.java
index 9a2b3f7..557234a 100644
--- a/main/src/cgeo/geocaching/SearchResult.java
+++ b/main/src/cgeo/geocaching/SearchResult.java
@@ -197,7 +197,7 @@ public class SearchResult implements Parcelable {
// Is there any reason to exclude the cache from the list?
final boolean excludeCache = (excludeDisabled && cache.isDisabled()) ||
(excludeMine && (cache.isOwner() || cache.isFound())) ||
- (cacheType != CacheType.ALL && cacheType != cache.getType());
+ (!cacheType.contains(cache));
if (!excludeCache) {
result.addCache(cache);
cachesForVote.add(cache);
diff --git a/main/src/cgeo/geocaching/connector/gc/GCMap.java b/main/src/cgeo/geocaching/connector/gc/GCMap.java
index 3b8dc1e..20739db 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCMap.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCMap.java
@@ -226,7 +226,7 @@ public class GCMap {
if (Settings.isExcludeDisabledCaches() && cache.isDisabled()) {
exclude = true;
}
- if (Settings.getCacheType() != CacheType.ALL && Settings.getCacheType() != cache.getType() && cache.getType() != CacheType.UNKNOWN) { // workaround for BM
+ if (!Settings.getCacheType().contains(cache) && cache.getType() != CacheType.UNKNOWN) { // workaround for BM
exclude = true;
}
if (!exclude) {
diff --git a/main/src/cgeo/geocaching/enumerations/CacheType.java b/main/src/cgeo/geocaching/enumerations/CacheType.java
index 88bded2..528d3fa 100644
--- a/main/src/cgeo/geocaching/enumerations/CacheType.java
+++ b/main/src/cgeo/geocaching/enumerations/CacheType.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.enumerations;
+import cgeo.geocaching.ICache;
import cgeo.geocaching.R;
import cgeo.geocaching.cgeoapplication;
@@ -94,4 +95,20 @@ public enum CacheType {
public String toString() {
return getL10n();
}
+
+ /**
+ * Whether this type contains the given cache.
+ *
+ * @param cache
+ * @return true if this is the ALL type or if this type equals the type of the cache.
+ */
+ public boolean contains(ICache cache) {
+ if (cache == null) {
+ return false;
+ }
+ if (this == ALL) {
+ return true;
+ }
+ return cache.getType() == this;
+ }
}
diff --git a/tests/src/cgeo/geocaching/enumerations/CacheTypeTest.java b/tests/src/cgeo/geocaching/enumerations/CacheTypeTest.java
index 21e97c0..fec7652 100644
--- a/tests/src/cgeo/geocaching/enumerations/CacheTypeTest.java
+++ b/tests/src/cgeo/geocaching/enumerations/CacheTypeTest.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.enumerations;
+import cgeo.geocaching.cgCache;
+
import android.test.AndroidTestCase;
import java.util.Locale;
@@ -35,4 +37,13 @@ public class CacheTypeTest extends AndroidTestCase {
assertEquals(type, CacheType.getByPattern(type.pattern.toUpperCase(Locale.US)));
}
}
+
+ public static void testContainsCache() throws Exception {
+ final cgCache traditional = new cgCache();
+ traditional.setType(CacheType.TRADITIONAL);
+
+ assertTrue(CacheType.ALL.contains(traditional));
+ assertTrue(CacheType.TRADITIONAL.contains(traditional));
+ assertFalse(CacheType.MYSTERY.contains(traditional));
+ }
}