From 0679e76ce7da5640cbeedbeff008624052b83991 Mon Sep 17 00:00:00 2001 From: blafoo Date: Wed, 8 Feb 2012 00:44:27 +0100 Subject: Changed database handling --- main/src/cgeo/geocaching/CacheCache.java | 38 +++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'main/src/cgeo/geocaching/CacheCache.java') 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; } } -- cgit v1.1