net.sf.jga.fn.logical

Class All<T>

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

Unary Predicate that returns true when each of 0 or more branch predicates returns true. When the collection of branch predicates is empty, an All predicate will return true (somewhat arbitrarily). This predicate will short circuit: once one of the branches returns false, 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 © 2002 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceAll.Visitor
Interface for classes that may interpret an All predicate.
Constructor Summary
All()
Builds the All predicate with an empty default collection of branch predicates.
All(Collection<UnaryFunctor<T,Boolean>> branches)
Builds the All predicate with the given collection of branch predicates.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(All) 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 all branch predicates return true when given x.
StringtoString()

Constructor Detail

All

public All()
Builds the All 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.

All

public All(Collection<UnaryFunctor<T,Boolean>> branches)
Builds the All 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(All) 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 all branch predicates return true when given x. Also returns true when there are no branch predicates.

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

toString

public String toString()