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

public Class SingletonIterator<E>

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

SingletonIterator is an java.util.Iterator over a single object instance.
Since
2.0

Field Summary

Modifier and TypeField and Description
private boolean
beforeFirst

Is the cursor before the first element

private E
object

The object

private final boolean
removeAllowed

Whether remove is allowed

private boolean
removed

Has the element been removed

Constructor Summary

AccessConstructor and Description
public
SingletonIterator(final E
the single object to return from the iterator
object
)

Constructs a new SingletonIterator where remove is a permitted operation.

public
SingletonIterator(final E
the single object to return from the iterator
object
,
final boolean
true if remove is allowed
removeAllowed
)

Constructs a new SingletonIterator optionally choosing if remove is a permitted operation.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the single object hasn't been returned yet
hasNext
()

Implements java.util.Iterator.hasNext.

Is another object available from the iterator?
public E

Returns:

the single object
next
()

Implements java.util.Iterator.next.

Get the next object from the iterator.
public void
remove()

Overrides default java.util.Iterator.remove.

Remove the object from this iterator.
public void
reset()

Implements org.apache.commons.collections4.ResettableIterator.reset.

Reset the iterator to the start.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beforeFirstback to summary
private boolean beforeFirst

Is the cursor before the first element

objectback to summary
private E object

The object

removeAllowedback to summary
private final boolean removeAllowed

Whether remove is allowed

removedback to summary
private boolean removed

Has the element been removed

Constructor Detail

SingletonIteratorback to summary
public SingletonIterator(final E object)

Constructs a new SingletonIterator where remove is a permitted operation.

Parameters
object:E

the single object to return from the iterator

SingletonIteratorback to summary
public SingletonIterator(final E object, final boolean removeAllowed)

Constructs a new SingletonIterator optionally choosing if remove is a permitted operation.

Parameters
object:E

the single object to return from the iterator

removeAllowed:boolean

true if remove is allowed

Since
3.1

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Is another object available from the iterator?

This returns true if the single object hasn't been returned yet.

Returns:boolean

true if the single object hasn't been returned yet

Annotations
@Override
nextback to summary
public E next()

Implements java.util.Iterator.next.

Get the next object from the iterator.

This returns the single object if it hasn't been returned yet.

Returns:E

the single object

Annotations
@Override
Exceptions
NoSuchElementException:
if the single object has already been returned
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Remove the object from this iterator.

Annotations
@Override
Exceptions
IllegalStateException:
if the next method has not yet been called, or the remove method has already been called after the last call to the next method.
UnsupportedOperationException:
if remove is not supported
resetback to summary
public void reset()

Implements org.apache.commons.collections4.ResettableIterator.reset.

Reset the iterator to the start.

Annotations
@Override