net.sf.jga.fn
Class BinaryFunctor<T1,T2,R>

java.lang.Object
  extended by net.sf.jga.fn.BinaryFunctor<T1,T2,R>
All Implemented Interfaces:
java.io.Serializable, Visitable
Direct Known Subclasses:
ApplyBinary, ArrayBinary, BinaryPredicate, BitwiseAnd, BitwiseOr, BitwiseXor, ChainBinary, ComparatorFn, ComposeBinary, ConditionalBinary, ConstantBinary, Distribute, Divides, GenerateBinary, InvokeMethod, Max, Merge, Min, Minus, Modulus, Multiplies, Plus, Project1st, Project2nd, SetField, SetProperty, ShiftLeft, ShiftRight, TransformBinary, UnsignedShiftRight

public abstract class BinaryFunctor<T1,T2,R>
extends java.lang.Object
implements java.io.Serializable, Visitable

A Function Object that takes two arguments and returns a result. The two arguments are of type T1 and T2, and the result is of type R

Copyright © 2002 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Constructor Summary
BinaryFunctor()
           
 
Method Summary
 void accept(Visitor v)
          No-op implementation of Visitable interface.
 Generator<R> bind(T1 value1, T2 value2)
          Factory method that creates a Generator that binds constant values to this' arguments.
 UnaryFunctor<T2,R> bind1st(T1 value)
          Factory method that creates a UnaryFunctor that binds a constant value to this' first argument.
 UnaryFunctor<T1,R> bind2nd(T2 value)
          Factory method that creates a UnaryFunctor that binds a constant value to this' second argument.
<F1,F2> BinaryFunctor<F1,F2,R>
compose(BinaryFunctor<F1,F2,T1> g, BinaryFunctor<F1,F2,T2> h)
          FactoryMethod that creates a BinaryFunctor that passes its argument to each of the given functors, and uses the results as the arguments to this function.
<F> UnaryFunctor<F,R>
compose(UnaryFunctor<F,T1> g, UnaryFunctor<F,T2> h)
          FactoryMethod that creates a UnaryFunctor that passes its argument to each of the given functors, and uses the results as the arguments to this function.
<F1,F2> BinaryFunctor<F1,F2,R>
distribute(UnaryFunctor<F1,T1> g, UnaryFunctor<F2,T2> h)
          FactoryMethod that creates a BinaryFunctor that passes each of its two arguments to a pair of UnaryFunctors, then uses the results as arguments to this function.
abstract  R fn(T1 arg1, T2 arg2)
          Executes the function and returns the result.
 Generator<R> generate(Generator<T1> gen1, Generator<T2> gen2)
          FactoryMethod that converts this functor to a Generator by using the two given generators to produce the arguments.
 UnaryFunctor<T2,R> generate1st(Generator<T1> gen)
          FactoryMethod that converts this functor to a UnaryFunctor by using the given generator to produce the first argument.
 UnaryFunctor<T1,R> generate2nd(Generator<T2> gen)
          FactoryMethod that converts this functor to a UnaryFunctor by using the given generator to produce the first argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinaryFunctor

public BinaryFunctor()
Method Detail

fn

public abstract R fn(T1 arg1,
                     T2 arg2)
Executes the function and returns the result.


bind1st

public UnaryFunctor<T2,R> bind1st(T1 value)
Factory method that creates a UnaryFunctor that binds a constant value to this' first argument. Given argument x, the new functor will return fnthis(value, x)


bind2nd

public UnaryFunctor<T1,R> bind2nd(T2 value)
Factory method that creates a UnaryFunctor that binds a constant value to this' second argument. Given argument x, the new functor will return fnthis(x, value)


bind

public Generator<R> bind(T1 value1,
                         T2 value2)
Factory method that creates a Generator that binds constant values to this' arguments. The new generator will return fnthis(value1, value2)


compose

public <F> UnaryFunctor<F,R> compose(UnaryFunctor<F,T1> g,
                                     UnaryFunctor<F,T2> h)
FactoryMethod that creates a UnaryFunctor that passes its argument to each of the given functors, and uses the results as the arguments to this function. Given argument x, the new functor will return fnthis(g(x), h(x))


compose

public <F1,F2> BinaryFunctor<F1,F2,R> compose(BinaryFunctor<F1,F2,T1> g,
                                              BinaryFunctor<F1,F2,T2> h)
FactoryMethod that creates a BinaryFunctor that passes its argument to each of the given functors, and uses the results as the arguments to this function. Given arguments x and y, the new functor will return fnthis(g(x,y), h(x,y))


distribute

public <F1,F2> BinaryFunctor<F1,F2,R> distribute(UnaryFunctor<F1,T1> g,
                                                 UnaryFunctor<F2,T2> h)
FactoryMethod that creates a BinaryFunctor that passes each of its two arguments to a pair of UnaryFunctors, then uses the results as arguments to this function. Given arguments x and y, the new functor will return fnthis(g(x), h(y)). Note: this method cannot be called compose, as it is only distinct from the unary form of compose in its param types and its return type


generate1st

public UnaryFunctor<T2,R> generate1st(Generator<T1> gen)
FactoryMethod that converts this functor to a UnaryFunctor by using the given generator to produce the first argument. Given argument y, the new functor will return fnthis(gen(), y).


generate2nd

public UnaryFunctor<T1,R> generate2nd(Generator<T2> gen)
FactoryMethod that converts this functor to a UnaryFunctor by using the given generator to produce the first argument. Given argument x, the new functor will return fnthis(x, gen()).


generate

public Generator<R> generate(Generator<T1> gen1,
                             Generator<T2> gen2)
FactoryMethod that converts this functor to a Generator by using the two given generators to produce the arguments. The new functor will return fnthis(gen1(), gen2()).


accept

public void accept(Visitor v)
No-op implementation of Visitable interface.

Specified by:
accept in interface Visitable


Copyright © 2002-2005 David A. Hall. All Rights Reserved.