net.sf.jga.fn.algorithm

Class FindSequence<T>

public class FindSequence<T> extends AbstractUnaryFunctor<Iterator<? extends T>,LookAheadIterator<T>> implements Serializable

Locates a sequence that matches the given pattern.

Copyright © 2003 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceFindSequence.Visitor
Interface for classes that may interpret a FindSequence functor
Constructor Summary
FindSequence(Collection<? extends T> pattern)
Builds a FindSequence functor that locates the given pattern using the equals() method to compare elements.
FindSequence(Collection<? extends T> pattern, BinaryFunctor<T,T,Boolean> eq)
Builds a FindSequence functor that locates the given pattern using given functor to compare elements.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(FindSequence) method, if it implements the nested Visitor interface.
LookAheadIterator<T>fn(Iterator<? extends T> iterator)
Locates a sequence that matches the given pattern.
BinaryFunctor<T,T,Boolean>getComparisonFn()
Returns the functor used to compare elements in the iteration and the pattern.
Collection<? extends T>getPattern()
Returns the pattern being sought
StringtoString()

Constructor Detail

FindSequence

public FindSequence(Collection<? extends T> pattern)
Builds a FindSequence functor that locates the given pattern using the equals() method to compare elements.

FindSequence

public FindSequence(Collection<? extends T> pattern, BinaryFunctor<T,T,Boolean> eq)
Builds a FindSequence functor that locates the given pattern using given functor to compare elements. If the pattern is null, then an arbitrary empty collection will be used.

Throws: IllegalArgumentException if the functor is null.

Method Detail

accept

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

fn

public LookAheadIterator<T> fn(Iterator<? extends T> iterator)
Locates a sequence that matches the given pattern.

Returns: an iterator whose next() [if it hasNext()] points to the beginning of a sequence in the iteration that matches the given pattern. If no such sequence exists, then the returned interator's hasNext() will be false.

getComparisonFn

public BinaryFunctor<T,T,Boolean> getComparisonFn()
Returns the functor used to compare elements in the iteration and the pattern.

getPattern

public Collection<? extends T> getPattern()
Returns the pattern being sought

toString

public String toString()