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 | |
| 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')
| -rw-r--r-- | main/src/cgeo/geocaching/Geocache.java | 35 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ICache.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/VisitCacheActivity.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCParser.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/oc/OC11XMLParser.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/utils/LazyInitializedList.java | 9 |
6 files changed, 29 insertions, 23 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) { 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<String> getAttributes(); + public List<String> 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<LogEntry> allLogs = cache.getLogs(); + List<LogEntry> allLogs = cache.getLogs(); List<LogEntry> 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<ElementType> extends AbstractList<ElementType> { @@ -26,14 +25,6 @@ public abstract class LazyInitializedList<ElementType> extends AbstractList<Elem return list.add(element); } - public void prepend(final ElementType element) { - add(0, element); - } - - public void set(final List<ElementType> elements) { - list = elements != null ? new ArrayList<ElementType>(elements) : new ArrayList<ElementType>(); - } - @Override public ElementType set(final int index, final ElementType element) { initializeList(); |
