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

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

public class FindSequence<T>
extends LookAheadFunctor<T>

Locates a sequence that matches the given pattern.

To Serialize a FindSequence, 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 FindSequence.Visitor
          Interface for classes that may interpret a FindSequence functor
 
Constructor Summary
FindSequence(java.util.Collection<? extends T> pattern)
          Builds a FindSequence functor that locates the given pattern using the equals() method to compare elements.
FindSequence(java.util.Collection<? extends T> pattern, BinaryFunctor<T,T,java.lang.Boolean> eq)
          Builds a FindSequence functor that locates the given pattern using given functor to compare elements.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(FindSequence) method, if it implements the nested Visitor interface.
 LookAheadIterator<T> fn(java.util.Iterator<? extends T> iterator)
          Locates a sequence that matches the given pattern.
 BinaryFunctor<T,T,java.lang.Boolean> getComparisonFn()
          Returns the functor used to compare elements in the iteration and the pattern.
 java.util.Collection<? extends T> getPattern()
          Returns the pattern being sought
 java.lang.String toString()
           
 
Methods inherited from class net.sf.jga.fn.algorithm.LookAheadFunctor
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

FindSequence

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


FindSequence

public FindSequence(java.util.Collection<? extends T> pattern,
                    BinaryFunctor<T,T,java.lang.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:
java.lang.IllegalArgumentException - if the functor is null.
Method Detail

getPattern

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


getComparisonFn

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


fn

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

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

accept

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

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

toString

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


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