aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/cgeoapplication.java
diff options
context:
space:
mode:
authorblafoo <github@blafoo.de>2012-01-06 23:14:39 +0100
committerblafoo <github@blafoo.de>2012-01-06 23:14:39 +0100
commitcc6e80e8c2f040dffdb442cd8e08f5699d71d938 (patch)
tree766c8c6e183386f21d0e26b1dd75afef072b73a7 /main/src/cgeo/geocaching/cgeoapplication.java
parent1f187b21cc989986a5f82cac24ffa2d57c75788a (diff)
downloadcgeo-cc6e80e8c2f040dffdb442cd8e08f5699d71d938.zip
cgeo-cc6e80e8c2f040dffdb442cd8e08f5699d71d938.tar.gz
cgeo-cc6e80e8c2f040dffdb442cd8e08f5699d71d938.tar.bz2
Set instead of List to avoid caches multiple times in search results
Diffstat (limited to 'main/src/cgeo/geocaching/cgeoapplication.java')
-rw-r--r--main/src/cgeo/geocaching/cgeoapplication.java22
1 files changed, 12 insertions, 10 deletions
diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java
index 856a51c..3bfe69a 100644
--- a/main/src/cgeo/geocaching/cgeoapplication.java
+++ b/main/src/cgeo/geocaching/cgeoapplication.java
@@ -23,8 +23,10 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.EnumSet;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
public class cgeoapplication extends Application {
@@ -303,7 +305,7 @@ public class cgeoapplication extends Application {
return null;
}
- List<String> geocodeList = new ArrayList<String>();
+ Set<String> geocodeList = new HashSet<String>();
geocodeList.add(geocode);
return getBounds(geocodeList);
@@ -317,7 +319,7 @@ public class cgeoapplication extends Application {
return getBounds(search.getGeocodes());
}
- public List<Number> getBounds(final List<String> geocodes) {
+ public List<Number> getBounds(final Set<String> geocodes) {
if (CollectionUtils.isEmpty(geocodes)) {
return null;
}
@@ -326,13 +328,13 @@ public class cgeoapplication extends Application {
}
public cgCache getCache(final SearchResult search) {
- if (search == null) {
+ if (search == null || search.getCount() < 1) {
return null;
}
- final List<String> geocodeList = search.getGeocodes();
+ final Set<String> geocodeList = search.getGeocodes();
- return getCacheByGeocode(geocodeList.get(0), LoadFlags.LOADALL);
+ return getCacheByGeocode(geocodeList.toArray(new String[geocodeList.size()])[0], LoadFlags.LOADALL);
}
/**
@@ -363,7 +365,7 @@ public class cgeoapplication extends Application {
List<cgCache> cachesOut = new ArrayList<cgCache>();
- final List<String> geocodeList = search.getGeocodes();
+ final Set<String> geocodeList = search.getGeocodes();
// The list of geocodes is sufficient. more parameters generate an overly complex select.
final List<cgCache> cachesPre = storage.loadCaches(geocodeList.toArray(), null, null, null, null, loadFlags);
@@ -375,7 +377,7 @@ public class cgeoapplication extends Application {
}
public SearchResult getBatchOfStoredCaches(final boolean detailedOnly, final Geopoint coords, final CacheType cacheType, final int list) {
- final List<String> geocodes = storage.loadBatchOfStoredGeocodes(detailedOnly, coords, cacheType, list);
+ final Set<String> geocodes = storage.loadBatchOfStoredGeocodes(detailedOnly, coords, cacheType, list);
final SearchResult search = new SearchResult(geocodes);
search.totalCnt = getAllStoredCachesCount(true, cacheType, list);
return search;
@@ -386,19 +388,19 @@ public class cgeoapplication extends Application {
}
public SearchResult getHistoryOfCaches(final boolean detailedOnly, final CacheType cacheType) {
- final List<String> geocodes = storage.loadBatchOfHistoricGeocodes(detailedOnly, cacheType);
+ final Set<String> geocodes = storage.loadBatchOfHistoricGeocodes(detailedOnly, cacheType);
final SearchResult search = new SearchResult(geocodes);
search.totalCnt = getAllHistoricCachesCount();
return search;
}
public SearchResult getCachedInViewport(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cacheType) {
- final List<String> geocodes = storage.getCachedInViewport(centerLat, centerLon, spanLat, spanLon, cacheType);
+ final Set<String> geocodes = storage.getCachedInViewport(centerLat, centerLon, spanLat, spanLon, cacheType);
return new SearchResult(geocodes);
}
public SearchResult getStoredInViewport(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cacheType) {
- final List<String> geocodes = storage.getStoredInViewport(centerLat, centerLon, spanLat, spanLon, cacheType);
+ final Set<String> geocodes = storage.getStoredInViewport(centerLat, centerLon, spanLat, spanLon, cacheType);
return new SearchResult(geocodes);
}