From 5ddc2beec34023b94b0f3f6489dc16ba40271e4c Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 3 Feb 2013 14:40:52 +0100 Subject: Restrict LazyInitializedList to the List interface This way, we can use various types of list at various places without specifically needing a LazyInitializedList. --- main/src/cgeo/geocaching/Geocache.java | 35 +++++++++++++++------- main/src/cgeo/geocaching/ICache.java | 2 +- main/src/cgeo/geocaching/VisitCacheActivity.java | 2 +- .../src/cgeo/geocaching/connector/gc/GCParser.java | 2 +- .../geocaching/connector/oc/OC11XMLParser.java | 2 +- .../cgeo/geocaching/utils/LazyInitializedList.java | 9 ------ 6 files changed, 29 insertions(+), 23 deletions(-) (limited to 'main/src') 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 attributes = new LazyInitializedList() { + private List attributes = new LazyInitializedList() { @Override protected List loadFromDatabase() { return cgData.loadAttributes(geocode); } }; - private LazyInitializedList waypoints = new LazyInitializedList() { + private List waypoints = new LazyInitializedList() { @Override protected List loadFromDatabase() { return cgData.loadWaypoints(geocode); } }; private List spoilers = null; - private LazyInitializedList logs = new LazyInitializedList() { + private List logs = new LazyInitializedList() { @Override protected List 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 getAttributes() { + public List getAttributes() { return attributes; } @@ -943,7 +949,10 @@ public class Geocache implements ICache, IWaypoint { * @return true if waypoints successfully added to waypoint database */ public boolean setWaypoints(List 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 null */ - public LazyInitializedList getLogs() { + public List getLogs() { return logs; } @@ -981,7 +990,10 @@ public class Geocache implements ICache, IWaypoint { * the log entries */ public void setLogs(List 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 attributes) { - this.attributes.set(attributes); + this.attributes.clear(); + if (attributes != null) { + this.attributes.addAll(attributes); + } } public void setSpoilers(List spoilers) { diff --git a/main/src/cgeo/geocaching/ICache.java b/main/src/cgeo/geocaching/ICache.java index 9aa01bb..c852d05 100644 --- a/main/src/cgeo/geocaching/ICache.java +++ b/main/src/cgeo/geocaching/ICache.java @@ -107,7 +107,7 @@ public interface ICache extends IBasicCache { * * @return the list of attributes for this cache */ - public LazyInitializedList getAttributes(); + public List getAttributes(); /** * @return the list of trackables in this cache diff --git a/main/src/cgeo/geocaching/VisitCacheActivity.java b/main/src/cgeo/geocaching/VisitCacheActivity.java index 3da4ecc..d77be5f 100644 --- a/main/src/cgeo/geocaching/VisitCacheActivity.java +++ b/main/src/cgeo/geocaching/VisitCacheActivity.java @@ -532,7 +532,7 @@ public class VisitCacheActivity extends AbstractLoggingActivity implements DateD if (status == StatusCode.NO_ERROR) { final LogEntry logNow = new LogEntry(date, typeSelected, log); - cache.getLogs().prepend(logNow); + cache.getLogs().add(0, logNow); if (typeSelected == LogType.FOUND_IT) { cache.setFound(true); diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java index b54e00c..2117053 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCParser.java +++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java @@ -1631,7 +1631,7 @@ public abstract class GCParser { //cache.setLogs(loadLogsFromDetails(page, cache, false)); if (Settings.isFriendLogsWanted()) { CancellableHandler.sendLoadProgressDetail(handler, R.string.cache_dialog_loading_details_status_logs); - LazyInitializedList allLogs = cache.getLogs(); + List allLogs = cache.getLogs(); List friendLogs = loadLogsFromDetails(page, cache, true, false); if (friendLogs != null) { for (LogEntry log : friendLogs) { diff --git a/main/src/cgeo/geocaching/connector/oc/OC11XMLParser.java b/main/src/cgeo/geocaching/connector/oc/OC11XMLParser.java index 5cba53d..ec53a7f 100644 --- a/main/src/cgeo/geocaching/connector/oc/OC11XMLParser.java +++ b/main/src/cgeo/geocaching/connector/oc/OC11XMLParser.java @@ -517,7 +517,7 @@ public class OC11XMLParser { final Geocache cache = caches.get(logHolder.cacheId); if (cache != null && logHolder.logEntry.type != LogType.UNKNOWN) { logs.put(logHolder.id, logHolder.logEntry); - cache.getLogs().prepend(logHolder.logEntry); + cache.getLogs().add(0, logHolder.logEntry); if (logHolder.logEntry.type == LogType.FOUND_IT && StringUtils.equalsIgnoreCase(logHolder.logEntry.author, Settings.getOCConnectorUserName())) { cache.setFound(true); diff --git a/main/src/cgeo/geocaching/utils/LazyInitializedList.java b/main/src/cgeo/geocaching/utils/LazyInitializedList.java index 6ea132c..d9c3897 100644 --- a/main/src/cgeo/geocaching/utils/LazyInitializedList.java +++ b/main/src/cgeo/geocaching/utils/LazyInitializedList.java @@ -1,7 +1,6 @@ package cgeo.geocaching.utils; import java.util.AbstractList; -import java.util.ArrayList; import java.util.List; public abstract class LazyInitializedList extends AbstractList { @@ -26,14 +25,6 @@ public abstract class LazyInitializedList extends AbstractList elements) { - list = elements != null ? new ArrayList(elements) : new ArrayList(); - } - @Override public ElementType set(final int index, final ElementType element) { initializeList(); -- cgit v1.1