aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorblafoo <github@blafoo.de>2012-01-05 23:34:16 +0100
committerblafoo <github@blafoo.de>2012-01-05 23:34:16 +0100
commit4060518ad84125d07ecb2d50526d9ad51a2ccf7c (patch)
treeba105ae528fbc66a58a0886b9d8c67205f030f0f /main
parent932b33d33890212eebbdc6de7fa29725c96d5dc6 (diff)
downloadcgeo-4060518ad84125d07ecb2d50526d9ad51a2ccf7c.zip
cgeo-4060518ad84125d07ecb2d50526d9ad51a2ccf7c.tar.gz
cgeo-4060518ad84125d07ecb2d50526d9ad51a2ccf7c.tar.bz2
Save a cache to the database only if there are changes
Diffstat (limited to 'main')
-rw-r--r--main/src/cgeo/geocaching/cgCache.java108
-rw-r--r--main/src/cgeo/geocaching/cgeoapplication.java5
2 files changed, 107 insertions, 6 deletions
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java
index 4b87ead..981d679 100644
--- a/main/src/cgeo/geocaching/cgCache.java
+++ b/main/src/cgeo/geocaching/cgCache.java
@@ -101,18 +101,35 @@ public class cgCache implements ICache {
*
* @param other
* the other version, or null if non-existent
+ * @return true if this cache is "equal" to the other version
*/
- public void gatherMissingFrom(final cgCache other) {
+ public boolean gatherMissingFrom(final cgCache other) {
if (other == null) {
- return;
+ return false;
}
updated = System.currentTimeMillis();
if (!detailed && other.detailed) {
detailed = true;
detailedUpdate = other.detailedUpdate;
- }
-
+ coords = other.coords;
+ premiumMembersOnly = other.premiumMembersOnly;
+ reliableLatLon = other.reliableLatLon;
+ archived = other.archived;
+ favorite = other.favorite;
+ onWatchlist = other.onWatchlist;
+ logOffline = other.logOffline;
+ }
+
+ /*
+ * No gathering for boolean members
+ * - found
+ * - own
+ * - disabled
+ * - favorite
+ * - onWatchlist
+ * - logOffline
+ */
if (visitedDate == 0) {
visitedDate = other.getVisitedDate();
}
@@ -220,6 +237,78 @@ public class cgCache implements ICache {
if (CollectionUtils.isEmpty(logs)) { // keep last known logs if none
logs = other.logs;
}
+ if (logCounts.size() == 0) {
+ logCounts = other.logCounts;
+ }
+
+ return isEqualTo(other);
+ }
+
+ /**
+ * Compare two caches quickly. For map and list fields only the references are compared !
+ *
+ * @param other
+ * @return true if both caches have the same content
+ */
+ public boolean isEqualTo(cgCache other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (geocode.equalsIgnoreCase("GC2CJPF")) {
+ Log.d(Settings.tag, "Treffer");
+ }
+ if (
+ // updated
+ // detailedUpdate
+ // visitedDate
+ detailed == other.detailed &&
+ geocode.equalsIgnoreCase(other.geocode) &&
+ name.equalsIgnoreCase(other.name) &&
+ cacheType == other.cacheType &&
+ size == other.size &&
+ found == other.found &&
+ own == other.own &&
+ premiumMembersOnly == other.premiumMembersOnly &&
+ difficulty == other.difficulty &&
+ terrain == other.terrain &&
+ (coords != null ? coords.isEqualTo(other.coords) : coords == other.coords) &&
+ reliableLatLon == other.reliableLatLon &&
+ disabled == other.disabled &&
+ archived == other.archived &&
+ listId == other.listId &&
+ owner.equalsIgnoreCase(other.owner) &&
+ ownerReal.equalsIgnoreCase(other.ownerReal) &&
+ (description != null ? description.equalsIgnoreCase(other.description) : description == other.description) &&
+ (personalNote != null ? personalNote.equalsIgnoreCase(other.personalNote) : personalNote == other.personalNote) &&
+ shortdesc.equalsIgnoreCase(other.shortdesc) &&
+ latlon.equalsIgnoreCase(other.latlon) &&
+ location.equalsIgnoreCase(other.location) &&
+ favorite == other.favorite &&
+ favoritePoints == other.favoritePoints &&
+ onWatchlist == other.onWatchlist &&
+ (hidden != null ? hidden.compareTo(other.hidden) == 0 : hidden == other.hidden) &&
+ guid.equalsIgnoreCase(other.guid) &&
+ hint.equalsIgnoreCase(other.hint) &&
+ cacheId.equalsIgnoreCase(other.cacheId) &&
+ direction == other.direction &&
+ distance == other.distance &&
+ elevation == other.elevation &&
+ nameSp == other.nameSp &&
+ rating == other.rating &&
+ votes == other.votes &&
+ myVote == other.myVote &&
+ inventoryItems == other.inventoryItems &&
+ attributes == other.attributes &&
+ waypoints == other.waypoints &&
+ spoilers == other.spoilers &&
+ logs == other.logs &&
+ inventory == other.inventory &&
+ logCounts == other.logCounts &&
+ logOffline == other.logOffline) {
+ return true;
+ }
+ return false;
}
public boolean hasTrackables() {
@@ -1108,4 +1197,15 @@ public class cgCache implements ICache {
}
logs.add(log);
}
+
+ /*
+ * For working in the debugger
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return this.geocode + " " + this.name;
+ }
}
diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java
index f4bead9..856a51c 100644
--- a/main/src/cgeo/geocaching/cgeoapplication.java
+++ b/main/src/cgeo/geocaching/cgeoapplication.java
@@ -488,11 +488,12 @@ public class cgeoapplication extends Application {
*/
private boolean storeWithMerge(final cgCache cache, final boolean override) {
+ boolean saveCache = true;
if (!override) {
final cgCache oldCache = storage.loadCache(cache.getGeocode(), LoadFlags.LOADALL);
- cache.gatherMissingFrom(oldCache);
+ saveCache = !cache.gatherMissingFrom(oldCache);
}
- return storage.saveCache(cache);
+ return saveCache ? storage.saveCache(cache) : true;
}
public void dropStored(int listId) {