net.sf.jga.fn.adaptor
public class ComposeUnary<T,F1,F2,R> extends AbstractUnaryFunctor<T,R> implements Serializable
For example: LogicalAnd is of limited utility since it takes only Boolean arguments. To use LogicalAnd for something a little more interesting (eg, is the given integer between 1 and 10), combine LogicalAnd with GreaterEqual and LessEqual using Binary Compose and Bind1st as follows:
new ComposeUnary<Integer,Boolean,Boolean,Boolean> ( new Bind1st<Integer,Integer,Boolean> (1, new LessEqual<Integer>()), new Bind1st<Integer,Integer,Boolean> (10, new GreaterEqual<Integer>()), new LogicalAnd());While it may not be the most readable construction in the world, it does become easier over time.
Copyright © 2002 David A. Hall
Nested Class Summary | |
---|---|
interface | ComposeUnary.Visitor
Interface for classes that may interpret a ComposeUnary functor. |
Constructor Summary | |
---|---|
ComposeUnary(UnaryFunctor<T,F1> f, UnaryFunctor<T,F2> g, BinaryFunctor<F1,F2,R> h)
Builds a ComposeUnary functor, given two inner functors f and
g, and outer functor h. |
Method Summary | |
---|---|
void | accept(Visitor v)
Calls the Visitor's visit(ComposeUnary) method, if it
implements the nested Visitor interface. |
R | fn(T x)
Given argument x, passes x to both inner functors, and passes the
results of those functors to the outer functor.
|
UnaryFunctor<T,F1> | getFirstInner()
Returns the first of two inner functors |
BinaryFunctor<F1,F2,R> | getOuter()
Returns the outer functor |
UnaryFunctor<T,F2> | getSecondInner()
Returns the second of two inner functors |
String | toString() |
Throws: IllegalArgumentException if any of the functors is missing
visit(ComposeUnary)
method, if it
implements the nested Visitor interface.Returns: h(f(x), g(x))
Returns: the first of two inner functors
Returns: the outer functor
Returns: the second of two inner functors