diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2012-03-04 12:09:24 +0100 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2012-03-04 12:09:24 +0100 |
| commit | d1f6c0164f8c8442ee0dc17cbff0e18db06286bf (patch) | |
| tree | f779f57b74ebbc1d051abd26f2dde49966396d10 /main/src/cgeo/geocaching/gcvote | |
| parent | 79bda3a54d92f51be99aebffdc67aa11b8ddf09f (diff) | |
| download | cgeo-d1f6c0164f8c8442ee0dc17cbff0e18db06286bf.zip cgeo-d1f6c0164f8c8442ee0dc17cbff0e18db06286bf.tar.gz cgeo-d1f6c0164f8c8442ee0dc17cbff0e18db06286bf.tar.bz2 | |
performance refactorings
* avoid creating message objects, there is a pool
* only get GCVotes for filtered caches, not for all
* don't use GepointParser in LocParser, we know those are pure floats
* String concatenation
Diffstat (limited to 'main/src/cgeo/geocaching/gcvote')
| -rw-r--r-- | main/src/cgeo/geocaching/gcvote/GCVote.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/gcvote/GCVote.java b/main/src/cgeo/geocaching/gcvote/GCVote.java index 077add2..663fd20 100644 --- a/main/src/cgeo/geocaching/gcvote/GCVote.java +++ b/main/src/cgeo/geocaching/gcvote/GCVote.java @@ -6,6 +6,7 @@ import cgeo.geocaching.cgCache; import cgeo.geocaching.network.Parameters; import cgeo.geocaching.utils.LeastRecentlyUsedCache; +import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -223,4 +224,37 @@ public final class GCVote { return result.trim().equalsIgnoreCase("ok"); } + + public static void loadRatings(ArrayList<cgCache> caches) { + if (!Settings.isRatingWanted()) { + return; + } + + final ArrayList<String> guids = new ArrayList<String>(caches.size()); + for (final cgCache cache : caches) { + String guid = cache.getGuid(); + if (StringUtils.isNotBlank(guid)) { + guids.add(guid); + } + } + + try { + final Map<String, GCVoteRating> ratings = GCVote.getRating(guids, null); + + if (MapUtils.isNotEmpty(ratings)) { + // save found cache coordinates + for (cgCache cache : caches) { + if (ratings.containsKey(cache.getGuid())) { + GCVoteRating rating = ratings.get(cache.getGuid()); + + cache.setRating(rating.getRating()); + cache.setVotes(rating.getVotes()); + cache.setMyVote(rating.getMyVote()); + } + } + } + } catch (Exception e) { + Log.e(Settings.tag, "GCvote.loadRatings: " + e.toString()); + } + } } |
