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

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

public class Unique<T>
extends UnaryFunctor<java.util.Iterator<? extends T>,UniqueIterator<T>>

Returns an iterator based on the input iterator that will not yield the same value twice in succession.

Copyright © 2003 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface Unique.Visitor
          Interface for classes that may interpret an Unique functor.
 
Constructor Summary
Unique()
          Builds an Unique functor that will use EqualTo to compare successive elements.
Unique(BinaryFunctor<T,T,java.lang.Boolean> test)
          Builds an Unique functor that will use the given functor to compare successive elements.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(Unique) method, if it implements the nested Visitor interface.
 UniqueIterator<T> fn(java.util.Iterator<? extends T> iterator)
          Apply the functor to each element in the iteration and return an iterator over the results
 BinaryFunctor<T,T,java.lang.Boolean> getFunction()
          Returns the functor used to process elements in an iteration.
 java.lang.String toString()
           
 
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

Unique

public Unique()
Builds an Unique functor that will use EqualTo to compare successive elements.

Throws:
java.lang.IllegalArgumentException - if the test is null

Unique

public Unique(BinaryFunctor<T,T,java.lang.Boolean> test)
Builds an Unique functor that will use the given functor to compare successive elements. The functor is required to return TRUE when its arguments are the same.

Throws:
java.lang.IllegalArgumentException - if the test is null
Method Detail

getFunction

public BinaryFunctor<T,T,java.lang.Boolean> getFunction()
Returns the functor used to process elements in an iteration.


fn

public UniqueIterator<T> fn(java.util.Iterator<? extends T> iterator)
Apply the functor to each element in the iteration and return an iterator over the results

Specified by:
fn in class UnaryFunctor<java.util.Iterator<? extends T>,UniqueIterator<T>>
Returns:
an iterator over the results of the transformation

accept

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

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

toString

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


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