aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2012-03-01 08:24:50 +0100
committerBananeweizen <bananeweizen@gmx.de>2012-03-01 08:25:59 +0100
commit0816152835818260387d6c21a8c912ed150b31be (patch)
tree323c7d72fda9742f767f19f52724abca7b98508f /main/src/cgeo
parent3fde9652fdc7c7285e4aa00a447df2ae4359b8d9 (diff)
downloadcgeo-0816152835818260387d6c21a8c912ed150b31be.zip
cgeo-0816152835818260387d6c21a8c912ed150b31be.tar.gz
cgeo-0816152835818260387d6c21a8c912ed150b31be.tar.bz2
refactoring: don't load caches in loops
Diffstat (limited to 'main/src/cgeo')
-rw-r--r--main/src/cgeo/geocaching/SearchResult.java4
-rw-r--r--main/src/cgeo/geocaching/cgBase.java13
-rw-r--r--main/src/cgeo/geocaching/files/LocParser.java13
3 files changed, 18 insertions, 12 deletions
diff --git a/main/src/cgeo/geocaching/SearchResult.java b/main/src/cgeo/geocaching/SearchResult.java
index 74602d4..fba946a 100644
--- a/main/src/cgeo/geocaching/SearchResult.java
+++ b/main/src/cgeo/geocaching/SearchResult.java
@@ -145,8 +145,8 @@ public class SearchResult implements Parcelable {
SearchResult result = new SearchResult(this);
result.geocodes.clear();
- for (final String geocode : geocodes) {
- cgCache cache = cgeoapplication.getInstance().loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
+ final Set<cgCache> caches = cgeoapplication.getInstance().loadCaches(geocodes, LoadFlags.LOAD_CACHE_OR_DB);
+ for (cgCache cache : caches) {
// Is there any reason to exclude the cache from the list?
final boolean excludeCache = (excludeDisabled && cache.isDisabled()) ||
(excludeMine && (cache.isOwn() || cache.isFound())) ||
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java
index 38b404e..8d00710 100644
--- a/main/src/cgeo/geocaching/cgBase.java
+++ b/main/src/cgeo/geocaching/cgBase.java
@@ -96,6 +96,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Set;
import java.util.regex.Matcher;
import javax.net.ssl.HostnameVerifier;
@@ -656,10 +657,10 @@ public class cgBase {
// get direction images
if (Settings.getLoadDirImg())
{
- for (String geocode : searchResult.getGeocodes()) {
- cgCache oneCache = cgeoapplication.getInstance().loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
- if (oneCache.getCoords() == null && StringUtils.isNotEmpty(oneCache.getDirectionImg())) {
- DirectionImage.getDrawable(oneCache.getGeocode(), oneCache.getDirectionImg());
+ final Set<cgCache> caches = cgeoapplication.getInstance().loadCaches(searchResult.getGeocodes(), LoadFlags.LOAD_CACHE_OR_DB);
+ for (cgCache cache : caches) {
+ if (cache.getCoords() == null && StringUtils.isNotEmpty(cache.getDirectionImg())) {
+ DirectionImage.getDrawable(cache.getGeocode(), cache.getDirectionImg());
}
}
}
@@ -674,8 +675,8 @@ public class cgBase {
if (MapUtils.isNotEmpty(ratings)) {
// save found cache coordinates
- for (String geocode : searchResult.getGeocodes()) {
- cgCache cache = cgeoapplication.getInstance().loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
+ final Set<cgCache> caches = cgeoapplication.getInstance().loadCaches(searchResult.getGeocodes(), LoadFlags.LOAD_CACHE_OR_DB);
+ for (cgCache cache : caches) {
if (ratings.containsKey(cache.getGuid())) {
GCVoteRating rating = ratings.get(cache.getGuid());
diff --git a/main/src/cgeo/geocaching/files/LocParser.java b/main/src/cgeo/geocaching/files/LocParser.java
index e3fd5e5..46e1227 100644
--- a/main/src/cgeo/geocaching/files/LocParser.java
+++ b/main/src/cgeo/geocaching/files/LocParser.java
@@ -20,9 +20,11 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -48,14 +50,17 @@ public final class LocParser extends FileParser {
final Map<String, cgCoord> cidCoords = parseCoordinates(fileContent);
// save found cache coordinates
+ final HashSet<String> contained = new HashSet<String>();
for (String geocode : searchResult.getGeocodes()) {
if (cidCoords.containsKey(geocode)) {
- cgCache cache = cgeoapplication.getInstance().loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
- cgCoord coord = cidCoords.get(cache.getGeocode());
-
- copyCoordToCache(coord, cache);
+ contained.add(geocode);
}
}
+ Set<cgCache> caches = cgeoapplication.getInstance().loadCaches(contained, LoadFlags.LOAD_CACHE_OR_DB);
+ for (cgCache cache : caches) {
+ cgCoord coord = cidCoords.get(cache.getGeocode());
+ copyCoordToCache(coord, cache);
+ }
}
private static void copyCoordToCache(final cgCoord coord, final cgCache cache) {