From 00b36f16e4768da7b252f31089ce1cfd19b2c2c6 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Thu, 31 Jan 2013 07:30:23 +0100 Subject: refactoring: simplify cache type checks --- main/src/cgeo/geocaching/enumerations/CacheType.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'main/src/cgeo/geocaching/enumerations') 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; + } } -- cgit v1.1