net.cscott.jutil

Class UnmodifiableIterator<E>

public abstract class UnmodifiableIterator<E> extends Object implements Iterator<E>

UnmodifiableIterator is an abstract superclass to save you the trouble of implementing the remove method over and over again for those iterators which don't implement it. The name's a bit clunky, but fits with the JDK naming in java.util.Collections and etc.

Version: $Id: UnmodifiableIterator.java,v 1.4 2006-10-30 20:14:41 cananian Exp $

Author: C. Scott Ananian

Method Summary
abstract booleanhasNext()
Returns true if the iteration has more elements.
abstract Enext()
Returns the next element in the iteration.
static <E> UnmodifiableIterator<E>proxy(Iterator<E> it)
Create an UnmodifiableIterator from the given (potentailly modifiable) Iterator.
voidremove()
Always throws an UnsupportedOperationException.

Method Detail

hasNext

public abstract boolean hasNext()
Returns true if the iteration has more elements.

Returns: true if the iterator has more elements.

next

public abstract E next()
Returns the next element in the iteration.

Throws: java.util.NoSuchElementException iteration has no more elements.

proxy

public static <E> UnmodifiableIterator<E> proxy(Iterator<E> it)
Create an UnmodifiableIterator from the given (potentailly modifiable) Iterator.

remove

public final void remove()
Always throws an UnsupportedOperationException.

Throws: UnsupportedOperationException always.

Copyright (c) 2006 C. Scott Ananian