Interface ExtendedIterator<T>

Type Parameters:
T - the type of element over which an instance of ExtendedIterator iterates
All Superinterfaces:
ClosableIterator<T>, org.apache.jena.atlas.lib.Closeable, Iterator<T>, org.apache.jena.atlas.iterator.IteratorCloseable<T>
All Known Subinterfaces:
NodeIterator, NsIterator, ResIterator, StmtIterator, TripleIterator
All Known Implementing Classes:
ContNodeIteratorImpl, FilterIterator, IteratorOfJenaSets, LazyIterator, Map1Iterator, MapFilterIterator, NiceIterator, NodeIteratorImpl, NsIteratorImpl, NullIterator, ObjectIterator, RandomOrderIterator, ResIteratorImpl, RoaringBitmapTripleIterator, SeqNodeIteratorImpl, SingletonIterator, SparseArrayIterator, StmtIteratorImpl, StoreTripleIterator, TrackingTripleIterator, WrappedIterator

public interface ExtendedIterator<T> extends ClosableIterator<T>
An ExtendedIterator is a ClosableIterator on which other operations are defined for convenience in iterator composition: composition, filtering in, filtering out, and element mapping.
NOTE that the result of these operations consumes the base iterator(s); they do not make independent copies.
The canonical implementation of ExtendedIterator is NiceIterator, which also defines static methods for these operations that will work on any ClosableIterators.
  • Method Details

    • removeNext

      T removeNext()
      Answer the next object, and remove it. Equivalent to next(); remove().
    • andThen

      <X extends T> ExtendedIterator<T> andThen(Iterator<X> other)
      return a new iterator which delivers all the elements of this iterator and then all the elements of the other iterator. Does not copy either iterator; they are consumed as the result iterator is consumed.
    • filterKeep

      ExtendedIterator<T> filterKeep(Predicate<T> f)
      return a new iterator containing only the elements of _this_ which pass the filter _f_. The order of the elements is preserved. Does not copy _this_, which is consumed as the result is consumed.
    • filterDrop

      ExtendedIterator<T> filterDrop(Predicate<T> f)
      return a new iterator containing only the elements of _this_ which are rejected by the filter _f_. The order of the elements is preserved. Does not copy _this_, which is consumed as the result is consumed.
    • mapWith

      <U> ExtendedIterator<U> mapWith(Function<T,U> map1)
      return a new iterator where each element is the result of applying _map1_ to the corresponding element of _this_. _this_ is not copied; it is consumed as the result is consumed.
    • forEach

      default void forEach(Consumer<T> action)
      Execute an action on each element of the iterator. This operation ends and closes the ExtendedIterator even if there is an exception. Shorter name for "Iterator.forEachRemaining", adding exception handling.
    • toList

      List<T> toList()
      Answer a list of the [remaining] elements of this iterator, in order, consuming this iterator.
    • toSet

      Set<T> toSet()
      Answer a set of the [remaining] elements of this iterator, consuming this iterator.
    • nextOptional

      default Optional<T> nextOptional()
      Answer with an Optional. This operation assumes that the ExtendedIterator does not return null for next(). If it does, NullPointerException is thrown.
      • If there is no next, return Optional.empty()
      • If the next object exists, and is not null, return that in the Optional.
      • If the next object exists, and is null, throw NullPointerException