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:
java.util.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
abstract static class Iterators.Abstract<A> extends Iterators.Unmodifiable<A>
A template implementation of theIteratorinterface, 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 Modifier and Type Class Description private static classIterators.Abstract.State
-
Field Summary
Fields Modifier and Type Field Description private Anextprivate Iterators.Abstract.Statestate
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstract()Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract AcomputeNext()The next element.protected AendOfData()Implementations ofcomputeNext()must invoke this method when there are no elements left in the iteration.booleanhasNext()Anext()private booleantryToComputeNext()-
Methods inherited from class io.atlassian.fugue.Iterators.Unmodifiable
remove
-
-
-
-
Field Detail
-
state
private Iterators.Abstract.State state
-
next
private A next
-
-
Method Detail
-
computeNext
protected abstract A 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
protected final A 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
public final A next()
-
-