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

java.lang.Object
  extended by net.sf.jga.fn.UnaryFunctor<java.util.Iterator<? extends T>,FindIterator<T>>
      extended by net.sf.jga.fn.algorithm.FindIteratorFunctor<T>
          extended by net.sf.jga.fn.algorithm.FindElement<T>
All Implemented Interfaces:
java.io.Serializable, Visitable

public class FindElement<T>
extends FindIteratorFunctor<T>

Locates values from a given collection in an iteration.

To Serialize a FindElement, the generic parameter T must be serializable.

Copyright © 2003 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface FindElement.Visitor
          Interface for classes that may interpret a FindElement functor
 
Constructor Summary
FindElement(java.util.Collection<? extends T> elements)
          Builds a FindElement functor that locates values in the given collection using the contains() method.
FindElement(java.util.Collection<? extends T> elements, BinaryFunctor<T,T,java.lang.Boolean> eq)
          Builds a FindElement functor that locates values in the given collection using the given functor.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(FindElement) method, if it implements the nested Visitor interface.
 FindIterator<T> fn(java.util.Iterator<? extends T> iterator)
          Finds the first/next element in the iteration that is an element of the given collection.
 BinaryFunctor<T,T,java.lang.Boolean> getComparisonFn()
          Returns the (possibly null) functor used to compare a value to the contents of the given collection.
 java.util.Collection<? extends T> getElementSet()
          Returns the set of values being sought.
 java.lang.String toString()
           
 
Methods inherited from class net.sf.jga.fn.algorithm.FindIteratorFunctor
wrap
 
Methods inherited from class net.sf.jga.fn.UnaryFunctor
bind, compose, compose, generate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FindElement

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


FindElement

public FindElement(java.util.Collection<? extends T> elements,
                   BinaryFunctor<T,T,java.lang.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

getElementSet

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


getComparisonFn

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


fn

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

Specified by:
fn in class UnaryFunctor<java.util.Iterator<? extends T>,FindIterator<T>>
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.

accept

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

Specified by:
accept in interface Visitable
Overrides:
accept in class UnaryFunctor<java.util.Iterator<? extends T>,FindIterator<T>>

toString

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


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