org.apache.commons.collections.iterators

Class SingletonListIterator

Implemented Interfaces:
Iterator, ListIterator, ResettableIterator, ResettableListIterator

public class SingletonListIterator
extends java.lang.Object
implements ListIterator, ResettableListIterator

SingletonIterator is an ListIterator over a single object instance.
Version:
$Revision: 1.13 $ $Date: 2004/02/18 00:59:50 $
Authors:
Stephen Colebourne
Rodney Waldhoff
Since:
Commons Collections 2.1

Constructor Summary

SingletonListIterator(Object object)
Constructs a new SingletonListIterator.

Method Summary

void
add(Object obj)
Add always throws UnsupportedOperationException.
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.

Constructor Details

SingletonListIterator

public SingletonListIterator(Object object)
Constructs a new SingletonListIterator.
Parameters:
object - the single object to return from the iterator

Method Details

add

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

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

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

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.

reset

public void reset()
Reset the iterator back to the start.
Specified by:
reset in interface ResettableListIterator
reset in interface ResettableIterator

set

public void set(Object obj)
Set sets the value of the singleton.
Parameters:
obj - the object to set

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