argutia.tools
Class UnmodifiableIterator<E>

java.lang.Object
  extended by argutia.tools.UnmodifiableIterator<E>
Type Parameters:
E - the object type being iterated over.
All Implemented Interfaces:
Iterator<E>
Direct Known Subclasses:
UnmodifiableListIterator
public class UnmodifiableIterator<E>
extends Object
implements Iterator<E>

Decorates an iterator such that iterator cannot be modified.

Author:
Geoffroy AUBRY
Field Summary
protected Iterator<E> iterator
          Wrapped iterator.
 
Constructor Summary
UnmodifiableIterator(Iterator<E> iterator)
          Decorates the specified iterator such that iterator cannot be modified.
 
Method Summary
 boolean hasNext()
          Returns true if the iteration has more elements.
 E next()
          Returns the next element in the iteration.
 void remove()
          Unsupported operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Field Detail

iterator

protected Iterator<E> iterator
Wrapped iterator.

Constructor Detail

UnmodifiableIterator

public UnmodifiableIterator(Iterator<E> iterator)
Decorates the specified iterator such that iterator cannot be modified.

Parameters:
iterator - iterator being wrapped.
Method Detail

hasNext

public boolean hasNext()
Returns true if the iteration has more elements. In other words, returns true if next() would return an element rather than throwing an exception.

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

next

public E next()
       throws NoSuchElementException
Returns the next element in the iteration. Calling this method repeatedly until the hasNext() method returns false will return each element in the underlying collection exactly once.

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

remove

public void remove()
            throws UnsupportedOperationException
Unsupported operation. Always throws an UnsupportedOperationException.

Specified by:
remove in interface Iterator<E>
Throws:
UnsupportedOperationException - always.
Argutia JavaDoc
23 décembre 2007