net.sf.jga.fn.logical

Class Any<T>

public class Any<T> extends AbstractUnaryPredicate<T> implements Serializable

Unary Predicate that returns true when one of 0 or more branch predicates returns true. When the collection of branch predicates is empty, an Any predicate will return false (somewhat arbitrarily). This predicate will short circuit: once one of the branches returns true, none of the subsequent branches will be evaluated.

The order of evaluation is dependant on the type of collection used: when using the default constructor, the collection used is a list, and branch predicates will be evaluated in the order given.

Copyright © 2003 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceAny.Visitor
Interface for classes that may interpret an Any predicate.
Constructor Summary
Any()
Builds the Any predicate with an empty default collection of branch predicates.
Any(Collection<UnaryFunctor<T,Boolean>> branches)
Builds the Any predicate with the given collection of branch predicates.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(Any) method, if it implements the nested Visitor interface.
voidaddBranch(UnaryFunctor<T,Boolean> pred)
Adds the predicate to the collection of branch predicates.
Iterator<UnaryFunctor<T,Boolean>>branches()
Returns an Iterator over the branch predicates.
booleanp(T x)
Given arguments x, returns true if at least one branch predicate returns true when given x.
StringtoString()

Constructor Detail

Any

public Any()
Builds the Any predicate with an empty default collection of branch predicates. The default collection is a list, and branches will be evaluated in the order they are added.

Any

public Any(Collection<UnaryFunctor<T,Boolean>> branches)
Builds the Any predicate with the given collection of branch predicates. More predicates may be added to the collection after construction. The order of evaluation of the branch predicates is determined by the collection in use.

Method Detail

accept

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

addBranch

public void addBranch(UnaryFunctor<T,Boolean> pred)
Adds the predicate to the collection of branch predicates. The predicate is added at the default location for the chosen collection.

branches

public Iterator<UnaryFunctor<T,Boolean>> branches()
Returns an Iterator over the branch predicates.

Returns: an Iterator over the branch predicates

p

public boolean p(T x)
Given arguments x, returns true if at least one branch predicate returns true when given x. Returns false when there are no branch predicates.

Returns: true if one branch predicates return true, false otherwise

toString

public String toString()