Package io.atlassian.fugue
Class Iterators.Abstract<A>
java.lang.Object
io.atlassian.fugue.Iterators.Unmodifiable<A>
io.atlassian.fugue.Iterators.Abstract<A>
- All Implemented Interfaces:
Iterator<A>
- Direct Known Subclasses:
Iterables.CollectingIterable.Iter,Iterables.Cycle.Iter,Iterables.Drop.Iter,Iterables.Join.Iter,Iterables.Memoizer.Iter,Iterables.MergeSortedIterable.Iter,Iterables.Take.Iter,Iterables.UnfoldingIterable.Iter
- Enclosing class:
Iterators
A template implementation of the
Iterator interface, so clients can
more easily implement Iterator for some patterns of iteration.
An example is an iterator that skips over null elements in a backing iterator. This could be implemented as:
public static Iterator<String> filterNulls(final Iterator<String> in) {
return new AbstractIterator<String>() {
protected String computeNext() {
while (in.hasNext()) {
String s = in.next();
if (s != null) {
return s;
}
}
return endOfData();
}
};
}
This class supports iterators that include null elements.
This class is a re-implentation of the Guava AbstractIterator class.
- Since:
- 3.0
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class io.atlassian.fugue.Iterators.Unmodifiable
removeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
state
-
next
-
-
Constructor Details
-
Abstract
protected Abstract()Constructor for use by subclasses.
-
-
Method Details
-
computeNext
The next element.Note: the implementation must call
endOfData()when there are no elements left in the iteration. Failure to do so could result in an infinite loop. -
endOfData
Implementations ofcomputeNext()must invoke this method when there are no elements left in the iteration.- Returns:
null; a convenience so yourcomputeNextimplementation can use the simple statementreturn endOfData();
-
hasNext
public final boolean hasNext() -
tryToComputeNext
private boolean tryToComputeNext() -
next
-