org.apache.commons.collections.iterators

Class SingletonListIterator

public class SingletonListIterator extends Object implements ListIterator, ResettableListIterator

SingletonIterator is an ListIterator over a single object instance.

Since: Commons Collections 2.1

Version: $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $

Author: Stephen Colebourne Rodney Waldhoff

Constructor Summary
SingletonListIterator(Object object)
Constructs a new SingletonListIterator.
Method Summary
voidadd(Object obj)
Add always throws UnsupportedOperationException.
booleanhasNext()
Is another object available from the iterator?
booleanhasPrevious()
Is a previous object available from the iterator?
Objectnext()
Get the next object from the iterator.
intnextIndex()
Returns the index of the element that would be returned by a subsequent call to next.
Objectprevious()
Get the previous object from the iterator.
intpreviousIndex()
Returns the index of the element that would be returned by a subsequent call to previous.
voidremove()
Remove the object from this iterator.
voidreset()
Reset the iterator back to the start.
voidset(Object obj)
Set sets the value of the singleton.

Constructor Detail

SingletonListIterator

public SingletonListIterator(Object object)
Constructs a new SingletonListIterator.

Parameters: object the single object to return from the iterator

Method Detail

add

public void add(Object obj)
Add always throws UnsupportedOperationException.

Throws: UnsupportedOperationException always

hasNext

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

hasPrevious

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

next

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

nextIndex

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.

previous

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

previousIndex

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.

remove

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.

reset

public void reset()
Reset the iterator back to the start.

set

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

Copyright © 2001-2008 Apache Software Foundation. All Rights Reserved.