public class

SingletonIterator

extends Object
implements Iterator<E> ResettableIterator
java.lang.Object
   ↳ org.apache.commons.collections.iterators.SingletonIterator

Class Overview

SingletonIterator is an Iterator over a single object instance.

Summary

Public Constructors
SingletonIterator(Object object)
Constructs a new SingletonIterator where remove is a permitted operation.
SingletonIterator(Object object, boolean removeAllowed)
Constructs a new SingletonIterator optionally choosing if remove is a permitted operation.
Public Methods
boolean hasNext()
Is another object available from the iterator?

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

Object next()
Get the next object from the iterator.
void remove()
Remove the object from this iterator.
void reset()
Reset the iterator to the start.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.util.Iterator
From interface org.apache.commons.collections.ResettableIterator

Public Constructors

public SingletonIterator (Object object)

Constructs a new SingletonIterator where remove is a permitted operation.

Parameters
object the single object to return from the iterator

public SingletonIterator (Object object, boolean removeAllowed)

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

Parameters
object the single object to return from the iterator
removeAllowed true if remove is allowed

Public Methods

public boolean hasNext ()

Is another object available from the iterator?

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

Returns
  • true if the single object hasn't been returned yet

public Object next ()

Get the next object from the iterator.

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

Returns
  • the single object
Throws
NoSuchElementException if the single object has already been returned

public void remove ()

Remove the object from this iterator.

Throws
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

public void reset ()

Reset the iterator to the start.