diff options
author | blafoo <github@blafoo.de> | 2012-01-24 22:48:19 +0100 |
---|---|---|
committer | blafoo <github@blafoo.de> | 2012-01-24 22:48:19 +0100 |
commit | 0a3f72f92fb970952eb29a9cb56075acacb7c3f9 (patch) | |
tree | 3e46af91b761d382b38aed71eae62ce93452bd39 /main/src/cgeo/geocaching/cgeoapplication.java | |
parent | beb7f7be8f127fba5ad333d6c31cefd1596157b6 (diff) | |
download | cgeo-0a3f72f92fb970952eb29a9cb56075acacb7c3f9.zip cgeo-0a3f72f92fb970952eb29a9cb56075acacb7c3f9.tar.gz cgeo-0a3f72f92fb970952eb29a9cb56075acacb7c3f9.tar.bz2 |
Stronger use of CacheCache
Diffstat (limited to 'main/src/cgeo/geocaching/cgeoapplication.java')
-rw-r--r-- | main/src/cgeo/geocaching/cgeoapplication.java | 43 |
1 files changed, 10 insertions, 33 deletions
diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java index 827e29f..c876d13 100644 --- a/main/src/cgeo/geocaching/cgeoapplication.java +++ b/main/src/cgeo/geocaching/cgeoapplication.java @@ -260,19 +260,9 @@ public class cgeoapplication extends Application { } public cgCache getCacheByGeocode(final String geocode, final EnumSet<LoadFlag> loadFlags) { - cgCache cache = CacheCache.getInstance().getCacheFromCache(geocode); - if (cache != null) { - return cache; - } - - cache = storage.loadCache(geocode, loadFlags); - if (cache != null && cache.isDetailed() && loadFlags == LoadFlags.LOADALL) { - // "Store" cache for the next access in the cache - CacheCache.getInstance().putCacheInCache(cache); - } + return storage.loadCache(geocode, loadFlags); - return cache; } public cgTrackable getTrackableByGeocode(String geocode) { @@ -294,6 +284,10 @@ public class cgeoapplication extends Application { CacheCache.getInstance().putCacheInCache(cache); } + public static cgCache getCacheFromCache(final String geocode) { + return CacheCache.getInstance().getCacheFromCache(geocode); + } + public String[] geocodesInCache() { return storage.allDetailedThere(); } @@ -342,36 +336,19 @@ public class cgeoapplication extends Application { * @return */ public Set<cgCache> getCaches(final SearchResult search, final boolean loadWaypoints) { - return getCaches(search, null, null, null, null, loadWaypoints ? EnumSet.of(LoadFlag.LOADWAYPOINTS, LoadFlag.LOADOFFLINELOG) : EnumSet.of(LoadFlag.LOADOFFLINELOG)); + return storage.loadCaches(search.getGeocodes(), loadWaypoints ? EnumSet.of(LoadFlag.LOADWAYPOINTS, LoadFlag.LOADOFFLINELOG) : EnumSet.of(LoadFlag.LOADOFFLINELOG)); } public Set<cgCache> getCaches(final SearchResult search, Long centerLat, Long centerLon, Long spanLat, Long spanLon) { - return getCaches(search, centerLat, centerLon, spanLat, spanLon, EnumSet.of(LoadFlag.LOADWAYPOINTS, LoadFlag.LOADOFFLINELOG)); - } - - public Set<cgCache> getCaches(final SearchResult search, final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final EnumSet<LoadFlag> loadFlags) { if (search == null) { - Set<cgCache> cachesOut = new HashSet<cgCache>(); - - final Set<cgCache> cachesPre = storage.loadCaches(null, centerLat, centerLon, spanLat, spanLon, loadFlags); - if (cachesPre != null) { - cachesOut.addAll(cachesPre); - } - - return cachesOut; + final Set<cgCache> cachesPre = storage.loadCaches(null, centerLat, centerLon, spanLat, spanLon, EnumSet.of(LoadFlag.LOADWAYPOINTS, LoadFlag.LOADOFFLINELOG)); + return cachesPre != null ? cachesPre : new HashSet<cgCache>(); } - Set<cgCache> cachesOut = new HashSet<cgCache>(); - - final Set<String> geocodeList = search.getGeocodes(); - // The list of geocodes is sufficient. more parameters generate an overly complex select. - final Set<cgCache> cachesPre = storage.loadCaches(geocodeList.toArray(), null, null, null, null, loadFlags); - if (cachesPre != null) { - cachesOut.addAll(cachesPre); - } + final Set<cgCache> cachesPre = storage.loadCaches(search.getGeocodes(), EnumSet.of(LoadFlag.LOADWAYPOINTS, LoadFlag.LOADOFFLINELOG)); + return cachesPre != null ? cachesPre : new HashSet<cgCache>(); - return cachesOut; } public SearchResult getBatchOfStoredCaches(final boolean detailedOnly, final Geopoint coords, final CacheType cacheType, final int list) { |