Package net.cscott.jutil
Interface ListFactory<V>
- All Superinterfaces:
CollectionFactory<V>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
ListFactory is a List generator.
Implementations construct specific types of Lists.
It is a functional interface, so a constructor which copies a
collection is a ListFactory: ArrayList::new.
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.
- Author:
- Felix S. Klock II <pnkfelix@mit.edu>
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E> List<E> concatenate(List<List<E>> lists) Creates and returns an unmodifiableListview of the list made from connectingliststogether in order.Generates a new, mutable, emptyCollection.makeCollection(int initCapacity) Generates a new, mutable, emptyCollection, usinginitialCapacityas a hint to use for the capacity for the producedCollection.makeCollection(Collection<? extends V> c) Generates a new, mutableCollection, using the elements ofcas a template for its initial contents.makeList()Generates a new, mutable, emptyList.makeList(int initialCapacity) makeList(Collection<? extends V> c) Generates a new mutableList, using the elements ofcas a template for its initial contents.static <E> List<E> singleton(E o) Deprecated.
-
Method Details
-
makeCollection
Description copied from interface:CollectionFactoryGenerates a new, mutable, emptyCollection.- Specified by:
makeCollectionin interfaceCollectionFactory<V>
-
makeCollection
Description copied from interface:CollectionFactoryGenerates a new, mutable, emptyCollection, usinginitialCapacityas a hint to use for the capacity for the producedCollection.- Specified by:
makeCollectionin interfaceCollectionFactory<V>
-
makeCollection
Description copied from interface:CollectionFactoryGenerates a new, mutableCollection, using the elements ofcas a template for its initial contents. Note that theCollectionreturned is not a view ofc, but rather a snapshot; changes tocare not reflected in the returnedCollection.- Specified by:
makeCollectionin interfaceCollectionFactory<V>
-
makeList
Generates a new, mutable, emptyList. -
makeList
-
makeList
Generates a new mutableList, using the elements ofcas a template for its initial contents. -
concatenate
Creates and returns an unmodifiableListview of the list made from connectingliststogether in order.
requires:listsis aListofLists.
effects: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 oflistsare reflected in the returnedList, but even changes tolistsitself (adding or removing lists) are also reflected. -
singleton
Deprecated.UseCollections.singletonListinstead.Creates and returns an immutableListof one element.
effects: returns the list [ o ]
-
Collections.singletonListinstead.