net.sf.jga.fn.algorithm

Class ElementOf<T>

public class ElementOf<T> extends AbstractBinaryPredicate<T,Collection<? extends T>> implements Serializable

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

Copyright © 2003 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceElementOf.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,Boolean> eq)
Builds an ElementOf predicate that will use the given functor to determine collection membership.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(ElementOf) method, if it implements the nested Visitor interface.
BinaryFunctor<T,T,Boolean>getComparisonFn()
Returns the (possibly null) functor used to compare a value to the contents of a collection.
booleanp(T value, Collection<? extends T> collection)
Return true if the given value is an element of the collection
StringtoString()

Constructor Detail

ElementOf

public ElementOf()
Builds an ElementOf predicate that will use the collection's built in contains() method. This for 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,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

accept

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

getComparisonFn

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

p

public boolean p(T value, Collection<? extends T> collection)
Return true if the given value is an element of the collection

toString

public String toString()