gov.sandia.cognition.factory
Class PrototypeFactory<CreatedType extends CloneableSerializable>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.factory.PrototypeFactory<CreatedType>
Type Parameters:
CreatedType - The type created by the factory.
All Implemented Interfaces:
Factory<CreatedType>, CloneableSerializable, Serializable, Cloneable

@CodeReview(reviewer="Kevin R. Dixon",
            date="2008-12-02",
            changesNeeded=false,
            comments={"I just don\'t think this class will be useful.","However, the implementation is great... if anybody ever finds it useful.","This is definitely the hazard of Justin with time on his hands ;"})
public class PrototypeFactory<CreatedType extends CloneableSerializable>
extends AbstractCloneableSerializable
implements Factory<CreatedType>

The PrototypeFactory class implements a Factory that uses a prototype object to create new objects from by cloning it.

Since:
2.1
Author:
Justin Basilico
See Also:
Serialized Form

Field Summary
protected  CreatedType prototype
          The prototype to create clones from.
 
Constructor Summary
PrototypeFactory()
          Creates a new PrototypeFactory with no prototype.
PrototypeFactory(CreatedType prototype)
          Creates a new PrototypeFactory with the given prototype.
PrototypeFactory(PrototypeFactory<? extends CreatedType> other)
          Creates a new copy of a PrototypeFactory.
 
Method Summary
 PrototypeFactory<CreatedType> clone()
          Clones this PrototypeFactory.
 CreatedType create()
          Creates a new object by calling the clone method on the prototype in the factory.
static
<T extends CloneableSerializable>
PrototypeFactory<T>
createFactory(T prototype)
          A convenience method for creating prototype factories.
 CreatedType getPrototype()
          Gets the prototype object that is cloned to create new objects.
 void setPrototype(CreatedType prototype)
          Sets the prototype object that is cloned to create new objects.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

prototype

protected CreatedType extends CloneableSerializable prototype
The prototype to create clones from.

Constructor Detail

PrototypeFactory

public PrototypeFactory()
Creates a new PrototypeFactory with no prototype.


PrototypeFactory

public PrototypeFactory(CreatedType prototype)
Creates a new PrototypeFactory with the given prototype.

Parameters:
prototype - The prototype to create clones from.

PrototypeFactory

public PrototypeFactory(PrototypeFactory<? extends CreatedType> other)
Creates a new copy of a PrototypeFactory.

Parameters:
other - The other factory to copy.
Method Detail

clone

public PrototypeFactory<CreatedType> clone()
Clones this PrototypeFactory.

Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractCloneableSerializable
Returns:
A new copy of this PrototypeFactory.

create

public CreatedType create()
Creates a new object by calling the clone method on the prototype in the factory.

Specified by:
create in interface Factory<CreatedType extends CloneableSerializable>
Returns:
A new clone of the prototype.

getPrototype

public CreatedType getPrototype()
Gets the prototype object that is cloned to create new objects.

Returns:
The prototype object.

setPrototype

public void setPrototype(CreatedType prototype)
Sets the prototype object that is cloned to create new objects. This object is cloned to store the prototype.

Parameters:
prototype - The prototype object.

createFactory

public static <T extends CloneableSerializable> PrototypeFactory<T> createFactory(T prototype)
A convenience method for creating prototype factories.

Type Parameters:
T - The type of the prototype object to create a factory for.
Parameters:
prototype - The prototype object.
Returns:
A new prototype factory that uses the given object as the prototype.