net.sf.jga.fn.adaptor

Class Constant<T,V>

public class Constant<T,V> extends AbstractBinaryFunctor<T,T,V> implements UnaryFunctor<T,V>, Serializable

Functor that returns the constant value given at construction. This functor fulfills both the UnaryFunctor and BinaryFunctor interface.

Copyright © 2003 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceConstant.Visitor
Interface for classes that may interpret a Constant functor.
Constructor Summary
Constant(V val)
Builds a Constant functor for the given value.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(Constant) method, if it implements the nested Visitor interface.
<F> UnaryFunctor<F,V>compose(UnaryFunctor<F,T> f)
Implements the FactoryMethod in the UnaryFunctor interface.
<F1,F2> BinaryFunctor<F1,F2,V>compose(BinaryFunctor<F1,F2,T> f)
Implements the FactoryMethod in the UnaryFunctor interface.
Vfn(T unused)
Given one argument, summarily ignores it and returns the constant value given at construction.
Vfn(T unused, T ignored)
Given two arguments, ignores both and returns the constant value given at construction.
StringtoString()

Constructor Detail

Constant

public Constant(V val)
Builds a Constant functor for the given value. The value may be null: in that case, evaluating the functor will return null.

Method Detail

accept

public void accept(Visitor v)
Calls the Visitor's visit(Constant) method, if it implements the nested Visitor interface.

compose

public <F> UnaryFunctor<F,V> compose(UnaryFunctor<F,T> f)
Implements the FactoryMethod in the UnaryFunctor interface. The result of the newly created functor will still be the same as this, but the argument is passed to the inner function and evaluated: the result of the inner function is ignored and the constant value of this functor is returned to the caller. The contract demands that the inner functor is actually evaluated (as it might have side effects that are significant -- that would be the only reason to be composing a functor whose outer function is a constant)

compose

public <F1,F2> BinaryFunctor<F1,F2,V> compose(BinaryFunctor<F1,F2,T> f)
Implements the FactoryMethod in the UnaryFunctor interface. The result of the newly created functor will still be the same as this, but the arguments are passed to the inner function and evaluated: the result of the inner function is ignored and the constant value of this functor is returned to the caller. The contract demands that the inner functor is actually evaluated (as it might have side effects that are significant -- that would be the only reason to be composing a functor whose outer function is a constant)

fn

public V fn(T unused)
Given one argument, summarily ignores it and returns the constant value given at construction. The argument will not be evaluated in any way by this functor.

Returns: the constant value given at construction

fn

public V fn(T unused, T ignored)
Given two arguments, ignores both and returns the constant value given at construction. Neither argument will be evaluated in any way by this functor.

Returns: the constant value given at construction

toString

public String toString()