public class

SingletonListIterator

extends Object
implements ListIterator<E> ResettableListIterator
java.lang.Object
   ↳ org.apache.commons.collections.iterators.SingletonListIterator

Class Overview

SingletonIterator is an ListIterator over a single object instance.

Summary

Public Constructors
SingletonListIterator(Object object)
Constructs a new SingletonListIterator.
Public Methods
void add(Object obj)
boolean hasNext()
Is another object available from the iterator?

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

boolean hasPrevious()
Is a previous object available from the iterator?

This returns true if the single object has been returned.

Object next()
Get the next object from the iterator.
int nextIndex()
Returns the index of the element that would be returned by a subsequent call to next.
Object previous()
Get the previous object from the iterator.
int previousIndex()
Returns the index of the element that would be returned by a subsequent call to previous.
void remove()
Remove the object from this iterator.
void reset()
Reset the iterator back to the start.
void set(Object obj)
Set sets the value of the singleton.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.util.Iterator
From interface java.util.ListIterator
From interface org.apache.commons.collections.ResettableIterator
From interface org.apache.commons.collections.ResettableListIterator

Public Constructors

public SingletonListIterator (Object object)

Constructs a new SingletonListIterator.

Parameters
object the single object to return from the iterator

Public Methods

public void add (Object obj)

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 boolean hasPrevious ()

Is a previous object available from the iterator?

This returns true if the single object has been returned.

Returns
  • true if the single object has been returned

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 int nextIndex ()

Returns the index of the element that would be returned by a subsequent call to next.

Returns
  • 0 or 1 depending on current state.

public Object previous ()

Get the previous object from the iterator.

This returns the single object if it has been returned.

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

public int previousIndex ()

Returns the index of the element that would be returned by a subsequent call to previous. A return value of -1 indicates that the iterator is currently at the start.

Returns
  • 0 or -1 depending on current state.

public void remove ()

Remove the object from this iterator.

Throws
IllegalStateException if the next or previous method has not yet been called, or the remove method has already been called after the last call to next or previous.

public void reset ()

Reset the iterator back to the start.

public void set (Object obj)

Set sets the value of the singleton.

Parameters
obj the object to set
Throws
IllegalStateException if next has not been called or the object has been removed