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.
This commit is contained in:
Michael Bayne
2009-07-14 21:15:06 +00:00
parent 4839512173
commit a83bca4bc1
2 changed files with 12 additions and 7 deletions
@@ -21,9 +21,10 @@
package com.samskivert.depot; package com.samskivert.depot;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import com.google.common.base.Function; 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 * An array list specialization that implements {@link XList}. Depot returns this list from all of
@@ -33,8 +34,8 @@ public class XArrayList<T> extends ArrayList<T>
implements XList<T> implements XList<T>
{ {
// from interface XList<T> // from interface XList<T>
public <R> Iterable<R> map (Function<T, R> mapper) public <R> Collection<R> map (Function<T, R> mapper)
{ {
return Iterables.transform(this, mapper); return Lists.transform(this, mapper);
} }
} }
+8 -4
View File
@@ -20,19 +20,23 @@
package com.samskivert.depot; package com.samskivert.depot;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import com.google.common.base.Function; import com.google.common.base.Function;
/** /**
* Extends the {@link List} interface with a method {@link #map} that makes it easy to convert the * 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 * contents of the list to an ordered {@link Collection} of a different type via the application of
* Function}. * a {@link Function}.
*/ */
public interface XList<T> extends List<T> public interface XList<T> extends List<T>
{ {
/** /**
* 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 <R> Iterable<R> map (Function<T, R> mapper); public <R> Collection<R> map (Function<T, R> mapper);
} }