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.

@FunctionalInterface public interface CollectionFactory<V>
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 Details

    • makeCollection

      default Collection<V> makeCollection()
      Generates a new, mutable, empty Collection.
    • makeCollection

      default Collection<V> makeCollection(int initialCapacity)
      Generates a new, mutable, empty Collection, using initialCapacity as a hint to use for the capacity for the produced Collection.
    • makeCollection

      Collection<V> makeCollection(Collection<? extends V> c)
      Generates a new, mutable Collection, 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.