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

public class FindAdjacent<T>
extends LookAheadFunctor<T>

Locates pairs of adjacent values in an iteration.

Copyright © 2003 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface FindAdjacent.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,java.lang.Boolean> eq)
          Builds a FindAdjacent functor that uses the given predicate to determine if adjacent values are the same.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(FindAdjacent) method, if it implements the nested Visitor interface.
 LookAheadIterator<T> fn(java.util.Iterator<? extends T> iterator)
          Locates the first/next pair of adjacent elements in an iteration that are the same value.
 BinaryFunctor<T,T,java.lang.Boolean> getComparisonFn()
          Returns the functor used to determine if two adjacent values are the same
 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

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,java.lang.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

getComparisonFn

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


fn

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

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

accept

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