net.sf.jga.fn.algorithm

Class FindElement<T>

public class FindElement<T> extends AbstractUnaryFunctor<Iterator<? extends T>,FindIterator<T>> implements Serializable

Locates values from a given collection in an iteration.

Copyright © 2003 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceFindElement.Visitor
Interface for classes that may interpret a FindElement functor
Constructor Summary
FindElement(Collection<? extends T> elements)
Builds a FindElement functor that locates values in the given collection using the contains() method.
FindElement(Collection<? extends T> elements, BinaryFunctor<T,T,Boolean> eq)
Builds a FindElement functor that locates values in the given collection using the given functor.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(FindElement) method, if it implements the nested Visitor interface.
FindIterator<T>fn(Iterator<? extends T> iterator)
Finds the first/next element in the iteration that is an element of the given collection.
BinaryFunctor<T,T,Boolean>getComparisonFn()
Returns the (possibly null) functor used to compare a value to the contents of the given collection.
Collection<? extends T>getElementSet()
Returns the set of values being sought.
StringtoString()

Constructor Detail

FindElement

public FindElement(Collection<? extends T> elements)
Builds a FindElement functor that locates values in the given collection using the contains() method.

FindElement

public FindElement(Collection<? extends T> elements, BinaryFunctor<T,T,Boolean> eq)
Builds a FindElement functor that locates values in the given collection using the given functor. The functor is expected to compare two values and return TRUE if they are determined to be equal.

Method Detail

accept

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

fn

public FindIterator<T> fn(Iterator<? extends T> iterator)
Finds the first/next element in the iteration that is an element of the given collection.

Returns: an iterator whose next() [if it hasNext()] points to the next element in the iteration that is an element of the given collection. If no such element exists, then the returned iterator's hasNext() will be false.

getComparisonFn

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

getElementSet

public Collection<? extends T> getElementSet()
Returns the set of values being sought.

toString

public String toString()