net.sf.jga.fn.logical
Class Any<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.Any<T>
All Implemented Interfaces:
java.io.Serializable, Visitable

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

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

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface Any.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(java.util.Collection<UnaryFunctor<T,java.lang.Boolean>> branches)
          Builds the Any predicate with the given collection of branch predicates.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(Any) 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 at least one branch predicate returns 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

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

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 at least one branch predicate returns true when given x. Returns false when there are no branch predicates.

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

accept

public void accept(Visitor v)
Calls the Visitor's visit(Any) 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.