net.sf.jga.fn.algorithm
Class FindRepeated<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.FindRepeated<T>
All Implemented Interfaces:
java.io.Serializable, Visitable

public class FindRepeated<T>
extends LookAheadFunctor<T>

Locates runs of repeated values in an iteration.

Copyright © 2003 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface FindRepeated.Visitor
          Interface for classes that may interpret an FindRepeated functor.
 
Constructor Summary
FindRepeated(int count, T value)
          Builds a FindRepeated functor that will look for a run of the given size, using the equals() method.
FindRepeated(int count, T value, Equality<T> eq)
          Builds a FindRepeated functor that will look for a run of the given size, using the given equality functor.
FindRepeated(int count, UnaryFunctor<T,java.lang.Boolean> eq)
          Builds a FindRepeated functor that will look for a run of the given size, using the given functor.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(FindRepeated) method, if it implements the nested Visitor interface.
 LookAheadIterator<T> fn(java.util.Iterator<? extends T> iterator)
          Locates the first/next run of the given length containing elements that meet the given criteria.
 UnaryFunctor<T,java.lang.Boolean> getComparisonFn()
          Returns the functor used to determine if the element should be included in the run
 int getRunLength()
          Returns the length of the run 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

FindRepeated

public FindRepeated(int count,
                    T value)
Builds a FindRepeated functor that will look for a run of the given size, using the equals() method.


FindRepeated

public FindRepeated(int count,
                    T value,
                    Equality<T> eq)
Builds a FindRepeated functor that will look for a run of the given size, using the given equality functor.


FindRepeated

public FindRepeated(int count,
                    UnaryFunctor<T,java.lang.Boolean> eq)
Builds a FindRepeated functor that will look for a run of the given size, using the given functor. The functor is expected to return TRUE if the element should be included in the run.

Method Detail

getRunLength

public int getRunLength()
Returns the length of the run being sought


getComparisonFn

public UnaryFunctor<T,java.lang.Boolean> getComparisonFn()
Returns the functor used to determine if the element should be included in the run


fn

public LookAheadIterator<T> fn(java.util.Iterator<? extends T> iterator)
Locates the first/next run of the given length containing elements that meet the given criteria.

Specified by:
fn in class UnaryFunctor<java.util.Iterator<? extends T>,LookAheadIterator<T>>
Returns:
an Iterator whose next() [if it hasNext()] points at the first element in the desired run. If no such run of elements exists, then the returned iterator's hasNext() will be false.

accept

public void accept(Visitor v)
Calls the Visitor's visit(FindRepeated) 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.