Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

dk.rode.thesis.abstractfactory
Class CollectionValueFactory<E extends Serializable>

java.lang.Object
  extended by dk.rode.thesis.abstractfactory.CollectionValueFactory<E>
Type Parameters:
E - The type of values generated by created generators.
All Implemented Interfaces:
GeneratorFactory<E,Collection<E>>

@ParticipantUsage(value="ConcreteProduct",
                  type=SequenceValueGenerator.class)
@Participant(value="ConcreteFactory")
public class CollectionValueFactory<E extends Serializable>
extends Object
implements GeneratorFactory<E,Collection<E>>

A collection value factory creates specific SequenceValueCollection objects based on the supplied type of collection to the creation method.

This factory is thread-safe.

Author:
Gunni Rode / rode.dk

Field Summary
private  ArrayList<E> defaultCollection
          The default collection to use in case the creation process is not supplied an argument.
private  Class<E> type
          The type of values stored in the value collection.
 
Constructor Summary
CollectionValueFactory(Class<E> type, Collection<E> defaultCollection)
          Constructor.
 
Method Summary
 SequenceValueCollection<E,?> createGenerator()
          Creates a new sequence value generator using the default argument.
 SequenceValueCollection<E,?> createGenerator(Collection<E> collection)
          Creates a new sequence value generator, where argument is an argument used in the creation process of the generator.
 Collection<E> getDefaultArgument()
          Returns the default argument to use for generator creation in case no argument is supplied to the GeneratorFactory.createGenerator(Object) method.
 String toString()
          Returns the string representation of this factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultCollection

private final ArrayList<E extends Serializable> defaultCollection
The default collection to use in case the creation process is not supplied an argument. Will be copied before each use.

Never null.


type

private final Class<E extends Serializable> type
The type of values stored in the value collection.

Never null.

Constructor Detail

CollectionValueFactory

public CollectionValueFactory(Class<E> type,
                              Collection<E> defaultCollection)
Constructor.

Parameters:
type - The type of values generated by the created generators; cannot be null.
defaultCollection - The default collection to use in case the creation process is not supplied an argument, but will be copied before each use; cannot be null.
Throws:
NullPointerException - If either argument is null.
IllegalArgumentException - if defaultCollection is empty.
Method Detail

createGenerator

public SequenceValueCollection<E,?> createGenerator()
Description copied from interface: GeneratorFactory
Creates a new sequence value generator using the default argument.

Specified by:
createGenerator in interface GeneratorFactory<E extends Serializable,Collection<E extends Serializable>>
Returns:
A new created generator; never null.
See Also:
GeneratorFactory.createGenerator(Object), GeneratorFactory.getDefaultArgument()

createGenerator

public SequenceValueCollection<E,?> createGenerator(Collection<E> collection)
Description copied from interface: GeneratorFactory
Creates a new sequence value generator, where argument is an argument used in the creation process of the generator.

Specified by:
createGenerator in interface GeneratorFactory<E extends Serializable,Collection<E extends Serializable>>
Parameters:
collection - A context supplied argument to use in the construction of the generator, if any. If null, the default argument is used (which may also be null, depending on the actual implementation).
Returns:
A new created generator; never null.
See Also:
GeneratorFactory.createGenerator()

getDefaultArgument

public Collection<E> getDefaultArgument()
Description copied from interface: GeneratorFactory
Returns the default argument to use for generator creation in case no argument is supplied to the GeneratorFactory.createGenerator(Object) method.

Specified by:
getDefaultArgument in interface GeneratorFactory<E extends Serializable,Collection<E extends Serializable>>
Returns:
The default argument, if any; can be null, depending on the actual implementation.

toString

public String toString()
Returns the string representation of this factory.

Overrides:
toString in class Object
Returns:
The string representation; never null.

Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.