net.sf.collections15.functors.transformer
Class ConstantTransformer<I,O>

java.lang.Object
  extended by net.sf.collections15.functors.transformer.ConstantTransformer<I,O>
All Implemented Interfaces:
java.io.Serializable, Transformer<I,O>

public class ConstantTransformer<I,O>
extends java.lang.Object
implements Transformer<I,O>, java.io.Serializable

Transformer 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 ConstantTransformer. Mutable objects should use the FactoryTransformer, seeded with a PrototypeFactory

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

Constructor Summary
protected ConstantTransformer(O constant)
          Creates a new instance whose transform(I) method always returns the specified constant.
 
Method Summary
 O getConstant()
          Returns the constant used by this Transformer.
static
<I,O> ConstantTransformer<I,O>
getInstance(O constant)
          Returns an instance whose transform(I) method always returns the specified constant.
 O transform(I input)
          Transforms the input by ignoring it and returning the stored constant instead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConstantTransformer

protected ConstantTransformer(O constant)
Creates a new instance whose transform(I) method always returns the specified constant.

Parameters:
constant - The constant to be returned each time the transform(I) method is invoked. May be null.
Method Detail

getInstance

public static <I,O> ConstantTransformer<I,O> getInstance(O constant)
Returns an instance whose transform(I) method always returns the specified constant.

Parameters:
constant - The constant to be returned each time the transform(I) method is invoked. May be null.
Returns:
An instance whose transform(I) method always returns the specified constant.

transform

public O transform(I input)
Transforms the input by ignoring it and returning the stored constant instead.

Specified by:
transform in interface Transformer<I,O>
Parameters:
input - The input object which is ignored.
Returns:
The stored constant.

getConstant

public O getConstant()
Returns the constant used by this Transformer.

Returns:
The constant used by this Transformer.
Since:
Collections15 1.0


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