net.sf.jga.fn.algorithm

Class FindRepeated<T>

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

Locates runs of repeated values in an iteration.

Copyright © 2003 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceFindRepeated.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,Boolean> eq)
Builds a FindRepeated functor that will look for a run of the given size, using the given functor.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(FindRepeated) method, if it implements the nested Visitor interface.
LookAheadIterator<T>fn(Iterator<? extends T> iterator)
Locates the first/next run of the given length containing elements that meet the given criteria.
UnaryFunctor<T,Boolean>getComparisonFn()
Returns the functor used to determine if the element should be included in the run
intgetRunLength()
Returns the length of the run being sought
StringtoString()

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,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

accept

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

fn

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

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.

getComparisonFn

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

getRunLength

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

toString

public String toString()