JUtil

net.cscott.jutil
Class CollectionFactory<V>

java.lang.Object
  extended by net.cscott.jutil.CollectionFactory<V>
Direct Known Subclasses:
ListFactory, SetFactory

public abstract class CollectionFactory<V>
extends Object

CollectionFactory is a Collection generator. Subclasses should implement constructions of specific types of Collections.

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.

Version:
$Id: CollectionFactory.java,v 1.4 2006-10-30 19:58:05 cananian Exp $
Author:
Felix S. Klock II

Constructor Summary
CollectionFactory()
          Creates a CollectionFactory.
 
Method Summary
 Collection<V> makeCollection()
          Generates a new, mutable, empty Collection.
abstract  Collection<V> makeCollection(Collection<? extends V> c)
          Generates a new, mutable Collection, using the elements of c as a template for its initial contents.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionFactory

public CollectionFactory()
Creates a CollectionFactory.

Method Detail

makeCollection

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


makeCollection

public 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

public abstract 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.


JUtil

Copyright (c) 2006 C. Scott Ananian