net.sf.jga.util

Class UniqueIterator<T>

public class UniqueIterator<T> extends Object implements Iterator<T>

Iterator that will not return the same element twice in succession.

Copyright © 2003 David A. Hall

Author: David A. Hall

Constructor Summary
UniqueIterator(Iterator<? extends T> base)
Builds a UniqueIterator for the given base iterator.
UniqueIterator(Iterator<? extends T> base, BinaryFunctor<T,T,Boolean> eq)
Builds a UniqueIterator for the given base iterator that uses the given predicate to compare adjacent elements.
Method Summary
booleanhasNext()
Tnext()
voidremove()
static <T> UniqueIterator<T>wrapIfNecessary(Iterator<? extends T> base)
Creates a UniqueIterator to wrap the given iterator, if the given iterator isn't already a UniqueIterator

Constructor Detail

UniqueIterator

public UniqueIterator(Iterator<? extends T> base)
Builds a UniqueIterator for the given base iterator.

UniqueIterator

public UniqueIterator(Iterator<? extends T> base, BinaryFunctor<T,T,Boolean> eq)
Builds a UniqueIterator for the given base iterator that uses the given predicate to compare adjacent elements.

Throws: IllegalArgumentException if either argument is null

Method Detail

hasNext

public boolean hasNext()

Returns:

next

public T next()

Returns:

remove

public void remove()

wrapIfNecessary

public static <T> UniqueIterator<T> wrapIfNecessary(Iterator<? extends T> base)
Creates a UniqueIterator to wrap the given iterator, if the given iterator isn't already a UniqueIterator