JUtil

net.cscott.jutil
Class UnmodifiableIterator<E>

java.lang.Object
  extended by net.cscott.jutil.UnmodifiableIterator<E>
All Implemented Interfaces:
Iterator<E>
Direct Known Subclasses:
FilterIterator, SnapshotIterator

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 Collections and etc.

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

Constructor Summary
UnmodifiableIterator()
           
 
Method Summary
abstract  boolean hasNext()
          Returns true if the iteration has more elements.
abstract  E next()
          Returns the next element in the iteration.
static
<E> UnmodifiableIterator<E>
proxy(Iterator<E> it)
          Create an UnmodifiableIterator from the given (potentailly modifiable) Iterator.
 void remove()
          Always throws an UnsupportedOperationException.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnmodifiableIterator

public UnmodifiableIterator()
Method Detail

proxy

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


hasNext

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

Specified by:
hasNext in interface Iterator<E>
Returns:
true if the iterator has more elements.

next

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

Specified by:
next in interface Iterator<E>
Throws:
NoSuchElementException - iteration has no more elements.

remove

public final void remove()
Always throws an UnsupportedOperationException.

Specified by:
remove in interface Iterator<E>
Throws:
UnsupportedOperationException - always.

JUtil

Copyright (c) 2006 C. Scott Ananian