Top Description Fields Constructors Methods
org.apache.commons.collections4.iterators

public final Class UnmodifiableIterator<E>

extends Object
implements Iterator<E>, Unmodifiable
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.Unmodifiable, java.util.Iterator
Imports
java.util.Iterator, org.apache.commons.collections4.Unmodifiable

Decorates an iterator such that it cannot be modified.

Attempts to modify it will result in an UnsupportedOperationException.

Since
3.0

Field Summary

Modifier and TypeField and Description
private final Iterator<? extends E>
iterator

The iterator being decorated

Constructor Summary

AccessConstructor and Description
private
UnmodifiableIterator(final Iterator<? extends E>
the iterator to decorate
iterator
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
public E
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).
public static <
the element type
E
>
Iterator<E>

Returns:

a new unmodifiable iterator
unmodifiableIterator
(final Iterator<? extends E>
the iterator to decorate
iterator
)

Decorates the specified iterator such that it cannot be modified.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iteratorback to summary
private final Iterator<? extends E> iterator

The iterator being decorated

Constructor Detail

UnmodifiableIteratorback to summary
private UnmodifiableIterator(final Iterator<? extends E> iterator)

Constructor.

Parameters
iterator:Iterator<? extends E>

the iterator to decorate

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.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.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public E next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:E

the next element in the iteration

Annotations
@Override
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override
unmodifiableIteratorback to summary
public static <E> Iterator<E> unmodifiableIterator(final Iterator<? extends E> iterator)

Decorates the specified iterator such that it cannot be modified.

If the iterator is already unmodifiable it is returned directly.

Parameters
<E>
the element type
iterator:Iterator<? extends E>

the iterator to decorate

Returns:Iterator<E>

a new unmodifiable iterator

Exceptions
NullPointerException:
if the iterator is null