|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.jga.fn.Functor<R> net.sf.jga.fn.UnaryFunctor<T,R> net.sf.jga.fn.adaptor.ConditionalUnary<T,R>
public class ConditionalUnary<T,R>
UnaryFunctor that tests a condition, executes one of two given functors, and
returns the result. The argument 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
Nested Class Summary | |
---|---|
static interface |
ConditionalUnary.Visitor
Interface for classes that may interpret a ConditionalUnary functor. |
Constructor Summary | |
---|---|
ConditionalUnary(UnaryFunctor<T,java.lang.Boolean> test,
UnaryFunctor<T,R> trueFn,
UnaryFunctor<T,R> falseFn)
Builds a ConditionalUnary 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(ConditionalUnary) method, if it
implements the nested Visitor interface. |
R |
fn(T x)
Given argument x, evaluates test(x); if true, returns trueFn(x), otherwise, returns falseFn(x). |
UnaryFunctor<T,java.lang.Boolean> |
getCondition()
Returns the test functors |
UnaryFunctor<T,R> |
getFalseFunctor()
Returns the functor that is executed when the condition is false |
UnaryFunctor<T,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.UnaryFunctor |
---|
bind, bind0th, bindNth, compose, compose, compose, composeNth, composeNth, eval, generate, generateNth |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ConditionalUnary(UnaryFunctor<T,java.lang.Boolean> test, UnaryFunctor<T,R> trueFn, UnaryFunctor<T,R> falseFn)
java.lang.IllegalArgumentException
- if any of the functors is missingMethod Detail |
---|
public UnaryFunctor<T,java.lang.Boolean> getCondition()
public UnaryFunctor<T,R> getTrueFunctor()
public UnaryFunctor<T,R> getFalseFunctor()
public R fn(T x)
fn
in class UnaryFunctor<T,R>
public void accept(Visitor v)
visit(ConditionalUnary)
method, if it
implements the nested Visitor interface.
accept
in interface Visitable
accept
in class Functor<R>
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |