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

java.lang.Object
  extended by net.sf.jga.fn.Functor<R>
      extended by net.sf.jga.fn.BinaryFunctor<T1,T2,R>
          extended by net.sf.jga.fn.adaptor.ConditionalBinary<T1,T2,R>
All Implemented Interfaces:
java.io.Serializable, Visitable

public class ConditionalBinary<T1,T2,R>
extends BinaryFunctor<T1,T2,R>

BinaryFunctor that tests a condition, executes one of two given functors, and returns the result. The arguments used to evaluate the condition will also be passed to whichever functor is executed. This functor implements the traditional ?: operator.

Copyright © 2003-2005 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface ConditionalBinary.Visitor
          Interface for classes that may interpret a ConditionalBinary functor.
 
Constructor Summary
ConditionalBinary(BinaryFunctor<T1,T2,java.lang.Boolean> test, BinaryFunctor<T1,T2,R> trueFn, BinaryFunctor<T1,T2,R> falseFn)
          Builds a ConditionalBinary functor, given the condition to test, and the two functors that may be executed.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(ConditionalBinary) method, if it implements the nested Visitor interface.
 R fn(T1 x, T2 y)
          Given arguments x and x evaluates test(x,y); if true, returns trueFn(x,y), otherwise, returns falseFn(x,y).
 BinaryFunctor<T1,T2,java.lang.Boolean> getCondition()
          Returns the test functors
 BinaryFunctor<T1,T2,R> getFalseFunctor()
          Returns the functor that is executed when the condition is false
 BinaryFunctor<T1,T2,R> getTrueFunctor()
          Returns the functor that is executed when the condition is true
 java.lang.String toString()
           
 
Methods inherited from class net.sf.jga.fn.BinaryFunctor
bind, bind0th, bind1st, bind2nd, bindNth, compose, compose, composeNth, distribute, eval, generate, generate1st, generate2nd, generateNth
 
Methods inherited from class net.sf.jga.fn.Functor
composeNth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConditionalBinary

public ConditionalBinary(BinaryFunctor<T1,T2,java.lang.Boolean> test,
                         BinaryFunctor<T1,T2,R> trueFn,
                         BinaryFunctor<T1,T2,R> falseFn)
Builds a ConditionalBinary functor, given the condition to test, and the two functors that may be executed.

Throws:
java.lang.IllegalArgumentException - if any of the functors is missing
Method Detail

getCondition

public BinaryFunctor<T1,T2,java.lang.Boolean> getCondition()
Returns the test functors

Returns:
the test functors

getTrueFunctor

public BinaryFunctor<T1,T2,R> getTrueFunctor()
Returns the functor that is executed when the condition is true

Returns:
the functor that is executed when the condition is true

getFalseFunctor

public BinaryFunctor<T1,T2,R> getFalseFunctor()
Returns the functor that is executed when the condition is false

Returns:
the functor that is executed when the condition is false

fn

public R fn(T1 x,
            T2 y)
Given arguments x and x evaluates test(x,y); if true, returns trueFn(x,y), otherwise, returns falseFn(x,y).

Specified by:
fn in class BinaryFunctor<T1,T2,R>
Returns:
test(x,y) ? trueFn(x,y) : falseFn(x,y)

accept

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

Specified by:
accept in interface Visitable
Overrides:
accept in class Functor<R>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


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