org.apache.commons.collections.functors
Class ConstantFactory<T>

java.lang.Object
  extended by org.apache.commons.collections.functors.ConstantFactory<T>
All Implemented Interfaces:
Serializable, Factory<T>

public class ConstantFactory<T>
extends Object
implements Factory<T>, 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 constant factory. Mutable objects should use the prototype factory.

Since:
Commons Collections 3.0
Version:
$Revision: 1.1.1.1 $ $Date: 2005/05/23 04:34:16 $
Author:
Matt Hall, John Watkinson, Stephen Colebourne
See Also:
Serialized Form

Field Summary
static Factory NULL_INSTANCE
          Returns null each time
 
Constructor Summary
ConstantFactory(T constantToReturn)
          Constructor that performs no validation.
 
Method Summary
 T create()
          Always return constant.
 T getConstant()
          Gets the constant.
static
<T> Factory<T>
getInstance(T constantToReturn)
          Factory method that performs validation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_INSTANCE

public static final Factory NULL_INSTANCE
Returns null each time

Constructor Detail

ConstantFactory

public ConstantFactory(T constantToReturn)
Constructor that performs no validation. Use getInstance if you want that.

Parameters:
constantToReturn - the constant to return each time
Method Detail

getInstance

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

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

create

public T create()
Always return constant.

Specified by:
create in interface Factory<T>
Returns:
the stored constant value

getConstant

public T getConstant()
Gets the constant.

Returns:
the constant
Since:
Commons Collections 3.1


Copyright © 2005-2005 Apache Software Foundation, Matt Hall, John Watkinson. All Rights Reserved.