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

java.lang.Object
  extended by net.sf.jga.fn.Functor<R>
      extended by net.sf.jga.fn.BinaryFunctor<T1,T2,R>
All Implemented Interfaces:
java.io.Serializable, Visitable
Direct Known Subclasses:
AndBinary, ApplyBinary, ArrayBinary, BinaryNegate, BitwiseAnd, BitwiseOr, BitwiseXor, ChainBinary, ComparatorFn, ComposeBinary, CompoundBinary, ConditionalBinary, ConstantBinary, Distribute, Divides, ElementOf, Equality, GenerateBinary, Greater, GreaterEqual, InvokeMethod, Less, LessEqual, LogicalAnd, LogicalOr, Max, Min, Minus, Modulus, Multiplies, NotEqualEqual, NotEqualTo, OrBinary, Plus, Project1st, Project2nd, SetField, SetProperty, ShiftLeft, ShiftRight, UnsignedShiftRight

public abstract class BinaryFunctor<T1,T2,R>
extends Functor<R>
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-2005 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Constructor Summary
BinaryFunctor()
           
 
Method Summary
 Generator<R> bind(T1 value1, T2 value2)
          Factory method that creates a Generator that binds constant values to this' arguments.
 Functor<R> bind0th(java.lang.Object arg0, java.lang.Object... args)
          Binds the given values to this functor, starting from the first argument.
 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.
 Functor<R> bindNth(int idx, java.lang.Object arg0, java.lang.Object... args)
          Binds the given values to this functor, starting from the given index.
<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.
 Functor<R> composeNth(int idx, UnaryFunctor<?,?> uf)
          Modifies the argument at the given index using the given functor
<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.
 R eval(java.lang.Object... args)
          Executes the function and returns the result.
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.
 Functor<R> generateNth(int idx, Generator<?> gen)
          Generates the argument at the given index to this functor
 
Methods inherited from class net.sf.jga.fn.Functor
accept, composeNth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.jga.fn.Visitable
accept
 

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(fn(), 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, fn()).


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()).


eval

public R eval(java.lang.Object... args)
Executes the function and returns the result.

Specified by:
eval in class Functor<R>

bind0th

public Functor<R> bind0th(java.lang.Object arg0,
                          java.lang.Object... args)
Binds the given values to this functor, starting from the first argument.

Overrides:
bind0th in class Functor<R>
Parameters:
arg0 -
args -
Returns:

bindNth

public Functor<R> bindNth(int idx,
                          java.lang.Object arg0,
                          java.lang.Object... args)
Binds the given values to this functor, starting from the given index.

Overrides:
bindNth in class Functor<R>
Parameters:
idx -
arg0 -
args -
Returns:

generateNth

public Functor<R> generateNth(int idx,
                              Generator<?> gen)
Generates the argument at the given index to this functor

Overrides:
generateNth in class Functor<R>
Parameters:
idx -
arg0 -
args -
Returns:

composeNth

public Functor<R> composeNth(int idx,
                             UnaryFunctor<?,?> uf)
Modifies the argument at the given index using the given functor

Overrides:
composeNth in class Functor<R>
Parameters:
idx -
arg0 -
args -
Returns:


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