public abstract class ListFactory<V> extends CollectionFactory<V>
ListFactory is a List generator.
Subclasses should implement constructions of specific types of
Lists. ListFactory also has a set of
static helper methods for building List objects.
Note also that the current limitations on parametric types in
Java mean that we can't easily type this class as
ListFactory<L extends List<V>,V>,
as ListFactory<LinkedList<V>,V> is not
a subtype of ListFactory<List<V>,V>,
even though LinkedList is a subtype of List.
| Constructor and Description |
|---|
ListFactory()
Creates a
ListFactory. |
| Modifier and Type | Method and Description |
|---|---|
static <E> java.util.List<E> |
concatenate(java.util.List<java.util.List<E>> lists)
Creates and returns an unmodifiable
List view of
the list made from connecting lists together in
order. |
java.util.List<V> |
makeCollection()
Generates a new, mutable, empty
Collection. |
java.util.List<V> |
makeCollection(java.util.Collection<? extends V> c)
Generates a new, mutable
Collection, using the
elements of c as a template for its initial
contents. |
java.util.List<V> |
makeCollection(int initCapacity)
Generates a new, mutable, empty
Collection, using
initialCapacity as a hint to use for the capacity
for the produced Collection. |
java.util.List<V> |
makeList()
Generates a new, mutable, empty
List. |
abstract java.util.List<V> |
makeList(java.util.Collection<? extends V> c)
Generates a new mutable
List, using the elements
of c as a template for its initial contents. |
java.util.List<V> |
makeList(int initialCapacity)
Generates a new, mutable, empty
List, using
initialCapacity as a hint to use for the capacity
for the produced List. |
static <E> java.util.List<E> |
singleton(E o)
Deprecated.
Use
Collections.singletonList instead. |
public ListFactory()
ListFactory.public final java.util.List<V> makeCollection()
CollectionFactoryCollection.makeCollection in class CollectionFactory<V>public final java.util.List<V> makeCollection(int initCapacity)
CollectionFactoryCollection, using
initialCapacity as a hint to use for the capacity
for the produced Collection.makeCollection in class CollectionFactory<V>public final java.util.List<V> makeCollection(java.util.Collection<? extends V> c)
CollectionFactoryCollection, using the
elements of c as a template for its initial
contents. Note that the Collection returned is
not a view of c, but rather a snapshot;
changes to c are not reflected in the returned
Collection.makeCollection in class CollectionFactory<V>public java.util.List<V> makeList()
List.public java.util.List<V> makeList(int initialCapacity)
List, using
initialCapacity as a hint to use for the capacity
for the produced List.public abstract java.util.List<V> makeList(java.util.Collection<? extends V> c)
List, using the elements
of c as a template for its initial contents.public static <E> java.util.List<E> concatenate(java.util.List<java.util.List<E>> lists)
List view of
the list made from connecting lists together in
order.
lists is a
List of Lists.
let l0 = (List) lists.get(0)
l1 = (List) lists.get(1)
...
ln = (List) lists.get(n) where n is lists.size()-1
returns a list view
[ l0.get(0) , l0.get(1), ... , l0.get(l0.size()-1),
l1.get(0) , l1.get(1), ... , l1.get(l1.size()-1),
...
ln.get(0) , ln.get(1), ... , ln.get(ln.size()-1) ]
Note that not only changes to the elements of
lists are reflected in the returned
List, but even changes to lists
itself (adding or removing lists) are also reflected.public static <E> java.util.List<E> singleton(E o)
Collections.singletonList instead.List of one element.
Copyright (c) 2006 C. Scott Ananian