net.sf.jga.fn.algorithm
Class ElementOf<T>

java.lang.Object
  extended by net.sf.jga.fn.Functor<R>
      extended by net.sf.jga.fn.BinaryFunctor<T,java.util.Collection<? extends T>,java.lang.Boolean>
          extended by net.sf.jga.fn.algorithm.ElementOf<T>
All Implemented Interfaces:
java.io.Serializable, Visitable

public class ElementOf<T>
extends BinaryFunctor<T,java.util.Collection<? extends T>,java.lang.Boolean>

BinaryPredicate that returns true if a given value is an element of a given collection.

Copyright © 2003-2005 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface ElementOf.Visitor
          Interface for classes that may interpret an ElementOf functor.
 
Constructor Summary
ElementOf()
          Builds an ElementOf predicate that will use the collection's built in contains() method.
ElementOf(BinaryFunctor<T,T,java.lang.Boolean> eq)
          Builds an ElementOf predicate that will use the given functor to determine collection membership.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(ElementOf) method, if it implements the nested Visitor interface.
 java.lang.Boolean fn(T value, java.util.Collection<? extends T> collection)
          Return true if the given value is an element of the collection
 BinaryFunctor<T,T,java.lang.Boolean> getComparisonFn()
          Returns the (possibly null) functor used to compare a value to the contents of a collection.
 java.lang.String toString()
           
 
Methods inherited from class net.sf.jga.fn.BinaryFunctor
bind, bind0th, bind1st, bind2nd, bindNth, compose, compose, composeNth, distribute, eval, generate, generate1st, generate2nd, generateNth
 
Methods inherited from class net.sf.jga.fn.Functor
composeNth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ElementOf

public ElementOf()
Builds an ElementOf predicate that will use the collection's built in contains() method. This form is potentially more efficient than the other constructed form, if the collection passed at evaluation implements contains() using an algorithm more efficient than a linear search.


ElementOf

public ElementOf(BinaryFunctor<T,T,java.lang.Boolean> eq)
Builds an ElementOf predicate that will use the given functor to determine collection membership. The collection will be searched sequentially for the first element for which the functor returns true.

Method Detail

getComparisonFn

public BinaryFunctor<T,T,java.lang.Boolean> getComparisonFn()
Returns the (possibly null) functor used to compare a value to the contents of a collection.


fn

public java.lang.Boolean fn(T value,
                            java.util.Collection<? extends T> collection)
Return true if the given value is an element of the collection

Specified by:
fn in class BinaryFunctor<T,java.util.Collection<? extends T>,java.lang.Boolean>

accept

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