Interface SetFactory<V>

All Superinterfaces:
CollectionFactory<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 SetFactory<V> extends CollectionFactory<V>
SetFactory is a Set generator. Implementations construct specific types of Sets. It is a functional interface, so a constructor which copies a collection is a SetFactory:
SetFactory<String> sf = HashSet::new;
A lambda or a method reference is not serializable unless it is cast to a serializable type, as in (SetFactory<V> & Serializable) HashSet::new. The factories of Factories are serializable.

Note also that the current limitations on parametric types in Java mean that we can't easily type this class as SetFactory<S extends Set<V>,V>, as SetFactory<HashSet<V>,V> is not a subtype of SetFactory<Set<V>,V>, even though HashSet is a subtype of Set.

Author:
Felix S. Klock II <pnkfelix@mit.edu>
  • Method Summary

    Modifier and Type
    Method
    Description
    default Set<V>
    Generates a new, mutable, empty Collection.
    default Set<V>
    makeCollection(int initCapacity)
    Generates a new, mutable, empty Collection, using initialCapacity as a hint to use for the capacity for the produced Collection.
    default Set<V>
    makeCollection(Collection<? extends V> c)
    Generates a new, mutable Collection, using the elements of c as a template for its initial contents.
    default Set<V>
    Generates a new, mutable, empty Set.
    default Set<V>
    makeSet(int initialCapacity)
    Generates a new, mutable, empty Set, using initialCapacity as a hint to use for the capacity for the produced Set.
    makeSet(Collection<? extends V> c)
    Generates a new mutable Set, using the elements of c as a template for its initial contents.
  • Method Details

    • makeCollection

      default Set<V> makeCollection()
      Description copied from interface: CollectionFactory
      Generates a new, mutable, empty Collection.
      Specified by:
      makeCollection in interface CollectionFactory<V>
    • makeCollection

      default Set<V> makeCollection(Collection<? extends V> c)
      Description copied from interface: CollectionFactory
      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.
      Specified by:
      makeCollection in interface CollectionFactory<V>
    • makeCollection

      default Set<V> makeCollection(int initCapacity)
      Description copied from interface: CollectionFactory
      Generates a new, mutable, empty Collection, using initialCapacity as a hint to use for the capacity for the produced Collection.
      Specified by:
      makeCollection in interface CollectionFactory<V>
    • makeSet

      default Set<V> makeSet()
      Generates a new, mutable, empty Set.
    • makeSet

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

      Set<V> makeSet(Collection<? extends V> c)
      Generates a new mutable Set, using the elements of c as a template for its initial contents.