diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2011-09-13 11:57:06 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2011-09-13 12:19:27 +0200 |
| commit | ac1c117d59db84827db38f87c242122e06510e2d (patch) | |
| tree | 41021267860eb37a331064bb12122551e4150546 | |
| parent | 0dab75878492f23f345cf70fba70416a14436471 (diff) | |
| download | cgeo-ac1c117d59db84827db38f87c242122e06510e2d.zip cgeo-ac1c117d59db84827db38f87c242122e06510e2d.tar.gz cgeo-ac1c117d59db84827db38f87c242122e06510e2d.tar.bz2 | |
Rename merge() into more exact gatherMissingFrom()
Also, the method no longer returns "this" as chaining calls is
not important here. The unused "storage" argument has been
removed.
| -rw-r--r-- | src/cgeo/geocaching/cgCache.java | 92 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeoapplication.java | 19 |
2 files changed, 54 insertions, 57 deletions
diff --git a/src/cgeo/geocaching/cgCache.java b/src/cgeo/geocaching/cgCache.java index 4a16d76..f4e7c3b 100644 --- a/src/cgeo/geocaching/cgCache.java +++ b/src/cgeo/geocaching/cgCache.java @@ -84,129 +84,127 @@ public class cgCache implements ICache { public boolean statusCheckedView = false; public String directionImg = null; - public cgCache merge(cgData storage, cgCache oldCache) { - - if (oldCache == null) { - return this; - } - + /** + * Gather missing information from another cache object. + * + * @param other the other version, or null if non-existent + */ + public void gatherMissingFrom(final cgCache other) { updated = System.currentTimeMillis(); - if (detailed == false && oldCache.detailed) { + if (detailed == false && other.detailed) { detailed = true; - detailedUpdate = System.currentTimeMillis(); + detailedUpdate = updated; } if (visitedDate == null || visitedDate == 0) { - visitedDate = oldCache.visitedDate; + visitedDate = other.visitedDate; } if (reason == null || reason == 0) { - reason = oldCache.reason; + reason = other.reason; } if (StringUtils.isBlank(geocode)) { - geocode = oldCache.geocode; + geocode = other.geocode; } if (StringUtils.isBlank(cacheId)) { - cacheId = oldCache.cacheId; + cacheId = other.cacheId; } if (StringUtils.isBlank(guid)) { - guid = oldCache.guid; + guid = other.guid; } if (StringUtils.isBlank(type)) { - type = oldCache.type; + type = other.type; } if (StringUtils.isBlank(name)) { - name = oldCache.name; + name = other.name; } if (StringUtils.isBlank(nameSp)) { - nameSp = oldCache.nameSp; + nameSp = other.nameSp; } if (StringUtils.isBlank(owner)) { - owner = oldCache.owner; + owner = other.owner; } if (StringUtils.isBlank(ownerReal)) { - ownerReal = oldCache.ownerReal; + ownerReal = other.ownerReal; } if (hidden == null) { - hidden = oldCache.hidden; + hidden = other.hidden; } if (StringUtils.isBlank(hint)) { - hint = oldCache.hint; + hint = other.hint; } if (StringUtils.isBlank(size)) { - size = oldCache.size; + size = other.size; } if (difficulty == null || difficulty == 0) { - difficulty = oldCache.difficulty; + difficulty = other.difficulty; } if (terrain == null || terrain == 0) { - terrain = oldCache.terrain; + terrain = other.terrain; } if (direction == null) { - direction = oldCache.direction; + direction = other.direction; } if (distance == null) { - distance = oldCache.distance; + distance = other.distance; } if (StringUtils.isBlank(latlon)) { - latlon = oldCache.latlon; + latlon = other.latlon; } if (StringUtils.isBlank(latitudeString)) { - latitudeString = oldCache.latitudeString; + latitudeString = other.latitudeString; } if (StringUtils.isBlank(longitudeString)) { - longitudeString = oldCache.longitudeString; + longitudeString = other.longitudeString; } if (StringUtils.isBlank(location)) { - location = oldCache.location; + location = other.location; } if (coords == null) { - coords = oldCache.coords; + coords = other.coords; } if (elevation == null) { - elevation = oldCache.elevation; + elevation = other.elevation; } if (StringUtils.isNotBlank(personalNote)) { - personalNote = oldCache.personalNote; + personalNote = other.personalNote; } if (StringUtils.isBlank(shortdesc)) { - shortdesc = oldCache.shortdesc; + shortdesc = other.shortdesc; } if (StringUtils.isBlank(description)) { - description = oldCache.description; + description = other.description; } if (favouriteCnt == null) { - favouriteCnt = oldCache.favouriteCnt; + favouriteCnt = other.favouriteCnt; } if (rating == null) { - rating = oldCache.rating; + rating = other.rating; } if (votes == null) { - votes = oldCache.votes; + votes = other.votes; } if (myVote == null) { - myVote = oldCache.myVote; + myVote = other.myVote; } if (inventoryItems == 0) { - inventoryItems = oldCache.inventoryItems; + inventoryItems = other.inventoryItems; } if (attributes == null) { - attributes = oldCache.attributes; + attributes = other.attributes; } if (waypoints == null) { - waypoints = oldCache.waypoints; + waypoints = other.waypoints; } - cgWaypoint.mergeWayPoints(waypoints, oldCache.waypoints); + cgWaypoint.mergeWayPoints(waypoints, other.waypoints); if (spoilers == null) { - spoilers = oldCache.spoilers; + spoilers = other.spoilers; } if (inventory == null) { - inventory = oldCache.inventory; + inventory = other.inventory; } if (logs == null || logs.isEmpty()) { // keep last known logs if none - logs = oldCache.logs; + logs = other.logs; } - - return this; } public boolean hasTrackables(){ diff --git a/src/cgeo/geocaching/cgeoapplication.java b/src/cgeo/geocaching/cgeoapplication.java index 17efe7e..0244112 100644 --- a/src/cgeo/geocaching/cgeoapplication.java +++ b/src/cgeo/geocaching/cgeoapplication.java @@ -722,19 +722,18 @@ public class cgeoapplication extends Application { /** * Checks if Cache is already in Database and if so does a merge. - * @param cache The cache to be saved - * @param forceSave override the check and persist the new state. - * @return + * @param cache the cache to be saved + * @param override override the check and persist the new state. + * @return true if the cache has been saved correctly */ - private boolean storeWithMerge(final cgCache cache, final boolean forceSave) { - if (forceSave) { - return storage.saveCache(cache); + private boolean storeWithMerge(final cgCache cache, final boolean override) { + if (!override) { + final cgCache oldCache = storage.loadCache(cache.geocode, cache.guid, + true, true, true, true, true, true); + cache.gatherMissingFrom(oldCache); } - - final cgCache oldCache = storage.loadCache(cache.geocode, cache.guid, - true, true, true, true, true, true); - return storage.saveCache(cache.merge(storage, oldCache)); + return storage.saveCache(cache); } public void dropStored(int listId) { |
