net.sf.jga.fn.logical
Class All<T>

java.lang.Object
  extended by net.sf.jga.fn.Functor<R>
      extended by net.sf.jga.fn.UnaryFunctor<T,java.lang.Boolean>
          extended by net.sf.jga.fn.logical.All<T>
All Implemented Interfaces:
java.io.Serializable, Visitable

public class All<T>
extends UnaryFunctor<T,java.lang.Boolean>

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-2005 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface All.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(java.util.Collection<UnaryFunctor<T,java.lang.Boolean>> branches)
          Builds the All predicate with the given collection of branch predicates.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(All) method, if it implements the nested Visitor interface.
 java.util.Iterator<UnaryFunctor<T,java.lang.Boolean>> branches()
          Returns an Iterator over the branch predicates.
 java.lang.Boolean fn(T x)
          Given arguments x, returns true if all branch predicates return true when given x.
 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

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(java.util.Collection<UnaryFunctor<T,java.lang.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

branches

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

Returns:
an Iterator over the branch predicates

fn

public java.lang.Boolean fn(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.

Specified by:
fn in class UnaryFunctor<T,java.lang.Boolean>
Returns:
true if all branch predicates return true, false otherwise

accept

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

Specified by:
accept in interface Visitable
Overrides:
accept in class Functor<java.lang.Boolean>

toString

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


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