jut.lang
Class OneTimeIterableWrapper<T>

java.lang.Object
  extended by jut.lang.AbstractOneTimeIterable<T>
      extended by jut.lang.OneTimeIterableWrapper<T>
All Implemented Interfaces:
Iterable<T>, OneTimeIterable<T>

public class OneTimeIterableWrapper<T>
extends AbstractOneTimeIterable<T>

wrapper for an Iterable to guarantee only one Iterator can be obtained. as convenience, a user method can be called before handing over the result of Iterator.next(), see AbstractOneTimeIterable.onNext(jut.lang.ParamRunnable).

this class is part of the problem solution that in the standard JDK the Iterables are supposed to produce any number of Iterators. see also AbstractOneTimeIterable.

Author:
Georg Dietrich

Constructor Summary
OneTimeIterableWrapper(Iterable<T> iterable)
          wrap an Iterable so only one Iterator can be obtained. as convenience, a user method can be called before handing over the result of Iterator.next(), see AbstractOneTimeIterable.onNext(jut.lang.ParamRunnable).
 
Method Summary
protected  boolean iteratorHasNext()
          returns true if the iterator has more elements.
protected  T iteratorNext()
          returns the next element in the iterator.
 
Methods inherited from class jut.lang.AbstractOneTimeIterable
iterator, onNext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OneTimeIterableWrapper

public OneTimeIterableWrapper(Iterable<T> iterable)
wrap an Iterable so only one Iterator can be obtained. as convenience, a user method can be called before handing over the result of Iterator.next(), see AbstractOneTimeIterable.onNext(jut.lang.ParamRunnable).

Parameters:
iterable - - the Iterable to wrap.
Method Detail

iteratorHasNext

protected final boolean iteratorHasNext()
returns true if the iterator has more elements. (in other words, returns true if AbstractOneTimeIterable.iteratorNext() would return an element rather than throwing an exception.)

Specified by:
iteratorHasNext in class AbstractOneTimeIterable<T>
Returns:
true if the iterator has more elements, false if not.

iteratorNext

protected final T iteratorNext()
returns the next element in the iterator.

Specified by:
iteratorNext in class AbstractOneTimeIterable<T>
Returns:
the next element in the iterator.