net.sf.jga.fn.algorithm

Class FindAdjacent<T>

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

Locates pairs of adjacent values in an iteration.

Copyright © 2003 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceFindAdjacent.Visitor
Interface for classes that may interpret an FindAdjacent functor.
Constructor Summary
FindAdjacent()
Builds a FindAdjacent functor that uses the equals() method to determine if adjacent values are the same.
FindAdjacent(BinaryFunctor<T,T,Boolean> eq)
Builds a FindAdjacent functor that uses the given predicate to determine if adjacent values are the same.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(FindAdjacent) method, if it implements the nested Visitor interface.
LookAheadIterator<T>fn(Iterator<? extends T> iterator)
Locates the first/next pair of adjacent elements in an iteration that are the same value.
BinaryFunctor<T,T,Boolean>getComparisonFn()
Returns the functor used to determine if two adjacent values are the same
StringtoString()

Constructor Detail

FindAdjacent

public FindAdjacent()
Builds a FindAdjacent functor that uses the equals() method to determine if adjacent values are the same.

FindAdjacent

public FindAdjacent(BinaryFunctor<T,T,Boolean> eq)
Builds a FindAdjacent functor that uses the given predicate to determine if adjacent values are the same. The functor argument is expected to compare two values and return TRUE if they are considered to be equal..

Method Detail

accept

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

fn

public LookAheadIterator<T> fn(Iterator<? extends T> iterator)
Locates the first/next pair of adjacent elements in an iteration that are the same value.

Returns: an iterator whose next() [if it hasNext()] points to the first of a pair of adjacent equivalent values. If no such pair exists, then the iterator's hasNext() will be false.

getComparisonFn

public BinaryFunctor<T,T,Boolean> getComparisonFn()
Returns the functor used to determine if two adjacent values are the same

toString

public String toString()