diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2013-02-03 14:40:52 +0100 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2013-02-03 14:45:35 +0100 |
| commit | 5ddc2beec34023b94b0f3f6489dc16ba40271e4c (patch) | |
| tree | 5e019b8745f3741e3d59e6562ba9a6719261c143 /main/src/cgeo/geocaching/Geocache.java | |
| parent | 0f2eb5549ee2177ba1725213804dd712b740ef0b (diff) | |
| download | cgeo-5ddc2beec34023b94b0f3f6489dc16ba40271e4c.zip cgeo-5ddc2beec34023b94b0f3f6489dc16ba40271e4c.tar.gz cgeo-5ddc2beec34023b94b0f3f6489dc16ba40271e4c.tar.bz2 | |
Restrict LazyInitializedList to the List interface
This way, we can use various types of list at various places without
specifically needing a LazyInitializedList.
Diffstat (limited to 'main/src/cgeo/geocaching/Geocache.java')
| -rw-r--r-- | main/src/cgeo/geocaching/Geocache.java | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index 10da00d..6507746 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -95,20 +95,20 @@ public class Geocache implements ICache, IWaypoint { private float myVote = 0; // valid ratings are larger than zero private int inventoryItems = 0; private boolean onWatchlist = false; - private LazyInitializedList<String> attributes = new LazyInitializedList<String>() { + private List<String> attributes = new LazyInitializedList<String>() { @Override protected List<String> loadFromDatabase() { return cgData.loadAttributes(geocode); } }; - private LazyInitializedList<Waypoint> waypoints = new LazyInitializedList<Waypoint>() { + private List<Waypoint> waypoints = new LazyInitializedList<Waypoint>() { @Override protected List<Waypoint> loadFromDatabase() { return cgData.loadWaypoints(geocode); } }; private List<Image> spoilers = null; - private LazyInitializedList<LogEntry> logs = new LazyInitializedList<LogEntry>() { + private List<LogEntry> logs = new LazyInitializedList<LogEntry>() { @Override protected List<LogEntry> loadFromDatabase() { return cgData.loadLogs(geocode); @@ -288,7 +288,10 @@ public class Geocache implements ICache, IWaypoint { myVote = other.myVote; } if (attributes.isEmpty()) { - attributes.set(other.attributes); + attributes.clear(); + if (other.attributes != null) { + attributes.addAll(other.attributes); + } } if (waypoints.isEmpty()) { this.setWaypoints(other.waypoints, false); @@ -310,7 +313,10 @@ public class Geocache implements ICache, IWaypoint { inventoryItems = other.inventoryItems; } if (logs.isEmpty()) { // keep last known logs if none - logs.set(other.logs); + logs.clear(); + if (other.logs != null) { + logs.addAll(other.logs); + } } if (logCounts.isEmpty()) { logCounts = other.logCounts; @@ -715,7 +721,7 @@ public class Geocache implements ICache, IWaypoint { } @Override - public LazyInitializedList<String> getAttributes() { + public List<String> getAttributes() { return attributes; } @@ -943,7 +949,10 @@ public class Geocache implements ICache, IWaypoint { * @return <code>true</code> if waypoints successfully added to waypoint database */ public boolean setWaypoints(List<Waypoint> waypoints, boolean saveToDatabase) { - this.waypoints.set(waypoints); + this.waypoints.clear(); + if (waypoints != null) { + this.waypoints.addAll(waypoints); + } finalDefined = false; if (waypoints != null) { for (Waypoint waypoint : waypoints) { @@ -959,7 +968,7 @@ public class Geocache implements ICache, IWaypoint { /** * @return never <code>null</code> */ - public LazyInitializedList<LogEntry> getLogs() { + public List<LogEntry> getLogs() { return logs; } @@ -981,7 +990,10 @@ public class Geocache implements ICache, IWaypoint { * the log entries */ public void setLogs(List<LogEntry> logs) { - this.logs.set(logs); + this.logs.clear(); + if (logs != null) { + this.logs.addAll(logs); + } } public boolean isLogOffline() { @@ -1074,7 +1086,10 @@ public class Geocache implements ICache, IWaypoint { } public void setAttributes(List<String> attributes) { - this.attributes.set(attributes); + this.attributes.clear(); + if (attributes != null) { + this.attributes.addAll(attributes); + } } public void setSpoilers(List<Image> spoilers) { |
