Package net.cscott.jutil
Interface CollectionFactory<V>
- All Known Subinterfaces:
ListFactory<V>,SetFactory<V>
- All Known Implementing Classes:
AggregateSetFactory,BitSetFactory,PersistentSetFactory
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
CollectionFactory is a Collection
generator. Implementations construct specific types of
Collections. It is a functional interface, so a
constructor which copies a collection is a
CollectionFactory: ArrayList::new.
Note that since some types of Collections have
implicit constraints (such as Sets, which cannot
contain more than one of the same element), code which uses the
classes produced by CollectionFactorys must take care
not to assume more than what is guaranteed by the
Collection interface.
Note also that the current limitations on parametric types in
Java mean that we can't easily type this class as
CollectionFactory<C extends Collection<V>,V>,
as CollectionFactory<Set<V>,V> is not
a subtype of CollectionFactory<Collection<V>,V>,
even though Set is a subtype of Collection.
- Author:
- Felix S. Klock II <pnkfelix@mit.edu>
-
Method Summary
Modifier and TypeMethodDescriptiondefault Collection<V> Generates a new, mutable, emptyCollection.default Collection<V> makeCollection(int initialCapacity) 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.
-
Method Details
-
makeCollection
Generates a new, mutable, emptyCollection. -
makeCollection
Generates a new, mutable, emptyCollection, usinginitialCapacityas a hint to use for the capacity for the producedCollection. -
makeCollection
Generates 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.
-