net.sf.jga.fn.adaptor
public class Conditional<T,R> extends AbstractUnaryFunctor<T,R> implements Serializable
?:
operator.
Copyright © 2003 David A. Hall
Nested Class Summary | |
---|---|
interface | Conditional.Visitor
Interface for classes that may interpret a Conditional functor. |
Constructor Summary | |
---|---|
Conditional(UnaryFunctor<T,Boolean> test, UnaryFunctor<T,R> trueFn, UnaryFunctor<T,R> falseFn)
Builds a Conditional 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(Conditional) 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,Boolean> | getCondition()
Returns the test functors |
UnaryFunctor<T,R> | getFalseFn()
Returns the functor that is executed when the condition is false |
UnaryFunctor<T,R> | getTrueFn()
Returns the functor that is executed when the condition is true |
static <T> Conditional<T,T> | replaceAll(UnaryFunctor<T,Boolean> test, T value)
Builds a replacement functor: returns the given value if the arg
passes the test, returns the arg if it does not pass the test.
|
String | toString() |
Throws: IllegalArgumentException if any of the functors is missing
visit(Conditional)
method, if it
implements the nested Visitor interface.Returns: test(x) ? trueFn(x) : falseFn(x)
Returns: the test functors
Returns: the functor that is executed when the condition is false
Returns: the functor that is executed when the condition is true
Returns: a UnaryFunctor of the form: test(x) ? x : value;