net.sf.jga.util
Class SingletonIterator<T>

java.lang.Object
  extended by net.sf.jga.util.SingletonIterator<T>
All Implemented Interfaces:
java.lang.Iterable<T>, java.util.Iterator<T>, java.util.ListIterator<T>

public class SingletonIterator<T>
extends java.lang.Object
implements java.util.ListIterator<T>, java.lang.Iterable<T>

Iterates over a single item. The iterator is structured as a list iterator, but the list is a fixed size (1). The value may be changed after it has been retrieved at least one time.

Author:
David A. Hall

Constructor Summary
SingletonIterator(T value)
          Builds a SingletonIterator that will return the given value.
 
Method Summary
 void add(T arg)
           
 boolean hasNext()
          Returns true if the item has not yet been returned.
 boolean hasPrevious()
          Returns true if the item has not yet been returned.
 java.util.Iterator<T> iterator()
           
 T next()
          Returns the single item
 int nextIndex()
           
 T previous()
          Returns the single item
 int previousIndex()
           
 void remove()
           
 void set(T value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingletonIterator

public SingletonIterator(T value)
Builds a SingletonIterator that will return the given value.

Method Detail

iterator

public java.util.Iterator<T> iterator()
Specified by:
iterator in interface java.lang.Iterable<T>

hasNext

public boolean hasNext()
Returns true if the item has not yet been returned.

Specified by:
hasNext in interface java.util.Iterator<T>
Specified by:
hasNext in interface java.util.ListIterator<T>
Returns:
true if the item has not yet been returned

next

public T next()
Returns the single item

Specified by:
next in interface java.util.Iterator<T>
Specified by:
next in interface java.util.ListIterator<T>
Returns:
the single item
Throws:
java.util.NoSuchElementException - if the item has already been returned

hasPrevious

public boolean hasPrevious()
Returns true if the item has not yet been returned.

Specified by:
hasPrevious in interface java.util.ListIterator<T>
Returns:
true if the item has not yet been returned

previous

public T previous()
Returns the single item

Specified by:
previous in interface java.util.ListIterator<T>
Returns:
the single item
Throws:
java.util.NoSuchElementException - if the item has already been returned

nextIndex

public int nextIndex()
Specified by:
nextIndex in interface java.util.ListIterator<T>

previousIndex

public int previousIndex()
Specified by:
previousIndex in interface java.util.ListIterator<T>

add

public void add(T arg)
Specified by:
add in interface java.util.ListIterator<T>

set

public void set(T value)
Specified by:
set in interface java.util.ListIterator<T>

remove

public void remove()
Specified by:
remove in interface java.util.Iterator<T>
Specified by:
remove in interface java.util.ListIterator<T>


Copyright © 2002-2006 David A. Hall. All Rights Reserved.