From a83bca4bc14f73a985535935e958042718b8d5fb Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 14 Jul 2009 21:15:06 +0000 Subject: [PATCH] Compromise with Mr Greenwell and provide a Collection which is still somewhat indicative to the caller that they're not just getting another array list back but rather a magical lazily converted list but is more useful than Iterable. --- src/java/com/samskivert/depot/XArrayList.java | 7 ++++--- src/java/com/samskivert/depot/XList.java | 12 ++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/java/com/samskivert/depot/XArrayList.java b/src/java/com/samskivert/depot/XArrayList.java index f6b148f..d58ef00 100644 --- a/src/java/com/samskivert/depot/XArrayList.java +++ b/src/java/com/samskivert/depot/XArrayList.java @@ -21,9 +21,10 @@ package com.samskivert.depot; import java.util.ArrayList; +import java.util.Collection; import com.google.common.base.Function; -import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; /** * An array list specialization that implements {@link XList}. Depot returns this list from all of @@ -33,8 +34,8 @@ public class XArrayList extends ArrayList implements XList { // from interface XList - public Iterable map (Function mapper) + public Collection map (Function mapper) { - return Iterables.transform(this, mapper); + return Lists.transform(this, mapper); } } diff --git a/src/java/com/samskivert/depot/XList.java b/src/java/com/samskivert/depot/XList.java index 8fa9ef2..3fc4383 100644 --- a/src/java/com/samskivert/depot/XList.java +++ b/src/java/com/samskivert/depot/XList.java @@ -20,19 +20,23 @@ package com.samskivert.depot; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; import com.google.common.base.Function; /** * Extends the {@link List} interface with a method {@link #map} that makes it easy to convert the - * contents of the list to an {@link Iterable} of a different type via the application of a {@link - * Function}. + * contents of the list to an ordered {@link Collection} of a different type via the application of + * a {@link Function}. */ public interface XList extends List { /** - * Returns an iterable over a mapping of this list via the specified mapping function. + * Returns mapping of this list via the specified mapping function. The result is a {@link + * Collection} to remind the caller that it is not an {@link ArrayList} but rather a lazy list + * that will call the mapping function on the fly each time an element is read. Caveat coder. */ - public Iterable map (Function mapper); + public Collection map (Function mapper); }