net.sf.collections15.functors.factory
Class ConstantFactory<E>

java.lang.Object
  extended by net.sf.collections15.functors.factory.ConstantFactory<E>
All Implemented Interfaces:
java.io.Serializable, Factory<E>

public class ConstantFactory<E>
extends java.lang.Object
implements Factory<E>, java.io.Serializable

Factory implementation that returns the same constant each time.

No check is made that the object is immutable. In general, only immutable objects should use the ConstantFactory. Mutable objects should use the PrototypeFactory instead.

Since:
Collections15 1.0
Author:
Stephen Colebourne, Chris Lambrou (port to Java 5.0)
See Also:
Serialized Form

Constructor Summary
protected ConstantFactory(E constantToReturn)
          Creates a new instance that returns the specified constant.
 
Method Summary
 E create()
          Always returns the stored constant value.
 E getConstant()
          Gets the stored constant value.
static
<E> ConstantFactory<E>
getInstance(E constantToReturn)
          Factory method that performs validation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConstantFactory

protected ConstantFactory(E constantToReturn)
Creates a new instance that returns the specified constant.

Parameters:
constantToReturn - The constant to return each time. May be null.
Method Detail

getInstance

public static <E> ConstantFactory<E> getInstance(E constantToReturn)
Factory method that performs validation.

Parameters:
constantToReturn - the constant object to return each time in the factory
Returns:
the constant factory.

create

public E create()
Always returns the stored constant value.

Specified by:
create in interface Factory<E>
Returns:
The stored constant value

getConstant

public E getConstant()
Gets the stored constant value.

Returns:
The stored constant value.
Since:
Collections15 1.0


Copyright © 2001-2005 SourceForge.net. All Rights Reserved.