E
- Type of element which is (not) iterated by an instance of this
object.public final class EmptyIterator<E>
extends java.lang.Object
implements java.util.Iterator<E>
Iterator
which manages no elements.
This is useful when a method must return an iterator, but the collection
which normally backs the iterator does not exist. This may occur, for
example, if a class lazily creates the backing collection, and it has not
yet done so at the time the method is called which must return an iterator
on that collection.Modifier and Type | Field and Description |
---|---|
private static EmptyIterator |
SINGLETON
Singleton instance
|
Modifier | Constructor and Description |
---|---|
private |
EmptyIterator()
Private constructor; access is only available through the static, singleton instance.
|
Modifier and Type | Method and Description |
---|---|
static <E> EmptyIterator<E> |
get()
Get the singleton instance of this class.
|
boolean |
hasNext()
Indicates that there is no next element (since there is no backing
collection).
|
E |
next()
Throws an exception, since there is no next element to return.
|
void |
remove()
An unsupported operation for this implementation, since there is no
backing collection and nothing to remove.
|
private static final EmptyIterator SINGLETON
private EmptyIterator()
public static <E> EmptyIterator<E> get()
public boolean hasNext()
hasNext
in interface java.util.Iterator<E>
false
.public E next()
java.util.Iterator
.next
in interface java.util.Iterator<E>
java.util.NoSuchElementException
- always.public void remove()
remove
in interface java.util.Iterator<E>
java.lang.UnsupportedOperationException
- always.