diff options
author | blafoo <github@blafoo.de> | 2012-02-08 00:44:27 +0100 |
---|---|---|
committer | blafoo <github@blafoo.de> | 2012-02-08 00:44:27 +0100 |
commit | 0679e76ce7da5640cbeedbeff008624052b83991 (patch) | |
tree | 3a8385e8f0b31b85691b1400e0a3e272f5e1bf01 /main/src/cgeo/geocaching/CacheCache.java | |
parent | db271dd2cd94a809d4422f58818a02403c08bbd6 (diff) | |
download | cgeo-0679e76ce7da5640cbeedbeff008624052b83991.zip cgeo-0679e76ce7da5640cbeedbeff008624052b83991.tar.gz cgeo-0679e76ce7da5640cbeedbeff008624052b83991.tar.bz2 |
Changed database handling
Diffstat (limited to 'main/src/cgeo/geocaching/CacheCache.java')
-rw-r--r-- | main/src/cgeo/geocaching/CacheCache.java | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/main/src/cgeo/geocaching/CacheCache.java b/main/src/cgeo/geocaching/CacheCache.java index 9c02b28..75fcfde 100644 --- a/main/src/cgeo/geocaching/CacheCache.java +++ b/main/src/cgeo/geocaching/CacheCache.java @@ -3,6 +3,8 @@ package cgeo.geocaching; import cgeo.geocaching.cgData.StorageLocation; import cgeo.geocaching.utils.LeastRecentlyUsedCache; +import org.apache.commons.lang3.StringUtils; + /** * Cache for Caches. Every cache is stored in memory while c:geo is active to * speed up the app and to minimize network request - which are slow. @@ -27,7 +29,7 @@ public class CacheCache { return instance; } - public void removeAll() { + public void removeAllFromCache() { cachesCache.clear(); } @@ -36,24 +38,26 @@ public class CacheCache { * Geocode of the cache to remove from the cache */ public void removeCacheFromCache(final String geocode) { - if (geocode != null && cachesCache.containsKey(geocode)) { - cachesCache.remove(geocode); + if (StringUtils.isBlank(geocode)) { + throw new IllegalArgumentException("geocode must not be empty"); } + cachesCache.remove(geocode); } /** + * "Store" a cache in the CacheCache. If the cache is already in the CacheCache the cache gets replaced. + * * @param cache - * Cache to "store" in the cache + * Cache + * */ public void putCacheInCache(final cgCache cache) { - if (cache == null || cache.getGeocode() == null) { - return; + if (cache == null) { + throw new IllegalArgumentException("cache must not be null"); } - - if (cachesCache.containsKey(cache.getGeocode())) { - cachesCache.remove(cache.getGeocode()); + if (StringUtils.isBlank(cache.getGeocode())) { + throw new IllegalArgumentException("geocode must not be empty"); } - cache.addStorageLocation(StorageLocation.CACHE); cachesCache.put(cache.getGeocode(), cache); } @@ -64,11 +68,19 @@ public class CacheCache { * @return cache if found, null else */ public cgCache getCacheFromCache(final String geocode) { - if (geocode != null && cachesCache.containsKey(geocode)) { - return cachesCache.get(geocode); + if (StringUtils.isBlank(geocode)) { + throw new IllegalArgumentException("geocode must not be empty"); } + return cachesCache.get(geocode); + } - return null; + @Override + public String toString() { + String result = ""; + for (String geocode : cachesCache.keySet()) { + result += geocode + " "; + } + return result; } } |