diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2013-02-03 14:32:06 +0100 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2013-02-03 14:39:11 +0100 |
| commit | 0f2eb5549ee2177ba1725213804dd712b740ef0b (patch) | |
| tree | 70db7d1cb9b0ac3640e5441abbc2dbcfa4af8dfc /main | |
| parent | b53b6303ae321276d8c25d6a492372ac615580a2 (diff) | |
| download | cgeo-0f2eb5549ee2177ba1725213804dd712b740ef0b.zip cgeo-0f2eb5549ee2177ba1725213804dd712b740ef0b.tar.gz cgeo-0f2eb5549ee2177ba1725213804dd712b740ef0b.tar.bz2 | |
Make LazyInitializedList<E> a List<E>
Diffstat (limited to 'main')
| -rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 6 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/Geocache.java | 8 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/utils/LazyInitializedList.java | 62 |
3 files changed, 20 insertions, 56 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index 0724ad4..03c0bcf 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -1219,7 +1219,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc } // cache attributes - if (cache.getAttributes().isNotEmpty()) { + if (!cache.getAttributes().isEmpty()) { new AttributeViewBuilder().fillView((LinearLayout) view.findViewById(R.id.attributes_innerbox)); view.findViewById(R.id.attributes_box).setVisibility(View.VISIBLE); } @@ -1963,7 +1963,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc } } - final List<LogEntry> logs = allLogs ? cache.getLogs().asList() : cache.getFriendsLogs(); + final List<LogEntry> logs = allLogs ? cache.getLogs() : cache.getFriendsLogs(); view.setAdapter(new ArrayAdapter<LogEntry>(CacheDetailActivity.this, R.layout.cacheview_logs_item, logs) { final UserActionsClickListener userActionsClickListener = new UserActionsClickListener(); final DecryptTextClickListener decryptTextClickListener = new DecryptTextClickListener(); @@ -2365,7 +2365,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc pages.add(Page.DETAILS); final int detailsIndex = pages.size() - 1; pages.add(Page.DESCRIPTION); - if (cache.getLogs().isNotEmpty()) { + if (!cache.getLogs().isEmpty()) { pages.add(Page.LOGS); } if (CollectionUtils.isNotEmpty(cache.getFriendsLogs())) { diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index 2b8e03b..10da00d 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -291,11 +291,11 @@ public class Geocache implements ICache, IWaypoint { attributes.set(other.attributes); } if (waypoints.isEmpty()) { - this.setWaypoints(other.waypoints.asList(), false); + this.setWaypoints(other.waypoints, false); } else { - ArrayList<Waypoint> newPoints = new ArrayList<Waypoint>(waypoints.asList()); - Waypoint.mergeWayPoints(newPoints, other.waypoints.asList(), false); + ArrayList<Waypoint> newPoints = new ArrayList<Waypoint>(waypoints); + Waypoint.mergeWayPoints(newPoints, other.waypoints, false); this.setWaypoints(newPoints, false); } if (spoilers == null) { @@ -931,7 +931,7 @@ public class Geocache implements ICache, IWaypoint { * @return always non <code>null</code> */ public List<Waypoint> getWaypoints() { - return waypoints.asList(); + return waypoints; } /** diff --git a/main/src/cgeo/geocaching/utils/LazyInitializedList.java b/main/src/cgeo/geocaching/utils/LazyInitializedList.java index 25af811..6ea132c 100644 --- a/main/src/cgeo/geocaching/utils/LazyInitializedList.java +++ b/main/src/cgeo/geocaching/utils/LazyInitializedList.java @@ -1,11 +1,10 @@ package cgeo.geocaching.utils; +import java.util.AbstractList; import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; import java.util.List; -public abstract class LazyInitializedList<ElementType> implements Iterable<ElementType> { +public abstract class LazyInitializedList<ElementType> extends AbstractList<ElementType> { private volatile List<ElementType> list; @@ -21,83 +20,48 @@ public abstract class LazyInitializedList<ElementType> implements Iterable<Eleme protected abstract List<ElementType> loadFromDatabase(); - public void add(final ElementType element) { + @Override + public boolean add(final ElementType element) { initializeList(); - list.add(element); + return list.add(element); } public void prepend(final ElementType element) { - initializeList(); - list.add(0, element); + add(0, element); } public void set(final List<ElementType> elements) { - if (elements != null) { - list = new ArrayList<ElementType>(elements); - } else { - list = new ArrayList<ElementType>(); - } - } - - public void set(LazyInitializedList<ElementType> other) { - if (other != null) { - list = new ArrayList<ElementType>(other.asList()); - } else { - list = new ArrayList<ElementType>(); - } + list = elements != null ? new ArrayList<ElementType>(elements) : new ArrayList<ElementType>(); } - public boolean isEmpty() { + @Override + public ElementType set(final int index, final ElementType element) { initializeList(); - return list.isEmpty(); + return list.set(index, element); } + @Override public ElementType remove(final int index) { initializeList(); return list.remove(index); } + @Override public void add(int index, final ElementType element) { initializeList(); list.add(index, element); } + @Override public int size() { initializeList(); return list.size(); } @Override - public Iterator<ElementType> iterator() { - initializeList(); - return list.iterator(); - } - public ElementType get(final int index) { initializeList(); return list.get(index); } - public boolean contains(final ElementType element) { - initializeList(); - return list.contains(element); - } - - public boolean isNotEmpty() { - initializeList(); - return !list.isEmpty(); - } - - /** - * @return an unmodifiable list of the elements - */ - public List<ElementType> asList() { - initializeList(); - return Collections.unmodifiableList(list); - } - - public int indexOf(ElementType element) { - initializeList(); - return list.indexOf(element); - } } |
