net.sf.saffron.runtime
Class BufferedIterator

java.lang.Object
  |
  +--net.sf.saffron.runtime.BufferedIterator
All Implemented Interfaces:
Enumeration, Iterable, Iterator

public class BufferedIterator
extends Object
implements Iterator, Iterable, Enumeration

BufferedIterator converts a regular iterator into one which implements Iterable (and Enumeration for good measure).

Implementation note: The first time you read from it, it duplicates objects into a list. The next time, it creates an iterator from that list. The implementation handles infinite iterators gracefully: it copies objects onto the replay list only when they are requested for the first time.

Since:
26 April, 2002
Version:
$Id: //open/saffron/src/net/sf/saffron/runtime/BufferedIterator.java#2 $
Author:
jhyde

Nested Class Summary
private static class BufferedIterator.Clonerator
          Reads from an iterator, duplicating elements into a list as it does so.
static class BufferedIterator.Test
           
 
Field Summary
private  BufferedIterator.Clonerator clonerator
           
private  Iterator iterator
           
private  List list
           
 
Constructor Summary
BufferedIterator(Iterator iterator)
           
 
Method Summary
 boolean hasMoreElements()
           
 boolean hasNext()
           
 Iterator iterator()
          Returns an iterator over the elements in this collection.
 Object next()
           
 Object nextElement()
           
 void remove()
           
 void restart()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

clonerator

private BufferedIterator.Clonerator clonerator

iterator

private Iterator iterator

list

private List list
Constructor Detail

BufferedIterator

public BufferedIterator(Iterator iterator)
Method Detail

hasMoreElements

public boolean hasMoreElements()
Specified by:
hasMoreElements in interface Enumeration

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator

iterator

public Iterator iterator()
Description copied from interface: Iterable
Returns an iterator over the elements in this collection. There are no guarantees over the order in which the elements are returned.

If this method is called twice on the same object, and the object is not modified in between times, the iterators produced may or may not be the same iterator, and may or may not return the elements in the same order, but must return the same objects.

Specified by:
iterator in interface Iterable

next

public Object next()
Specified by:
next in interface Iterator

nextElement

public Object nextElement()
Specified by:
nextElement in interface Enumeration

remove

public void remove()
Specified by:
remove in interface Iterator

restart

public void restart()

SourceForge.net_Logo