Class WrappedIterator<T>

All Implemented Interfaces:
Iterator<T>, IteratorCloseable<T>, Closeable, ClosableIterator<T>, ExtendedIterator<T>
Direct Known Subclasses:
FilterIterator, NodeIteratorImpl, NsIteratorImpl, RandomOrderIterator, ResIteratorImpl, RSIteratorImpl, StmtIteratorImpl, TrackingTripleIterator

public class WrappedIterator<T> extends NiceIterator<T>
a WrappedIterator is an ExtendedIterator wrapping around a plain (or presented as plain) Iterator. The wrapping allows the usual extended operations (filtering, concatenating) to be done on an Iterator derived from some other source.
  • Method Details

    • create

      public static <T> ExtendedIterator<T> create(Iterator<T> it)
      Answer an ExtendedIterator returning the elements of it. If it is itself an ExtendedIterator, return that; otherwise wrap it.
    • createNoRemove

      public static <T> WrappedIterator<T> createNoRemove(Iterator<T> it)
      Answer an ExtendedIterator wrapped round it which does not permit .remove() even if it does.
    • ofStream

      public static <T> WrappedIterator<T> ofStream(Stream<T> stream)
      Answer an ExtendedIterator wrapped round a Stream. The extended iterator does not permit .remove().

      The stream should not be used directly. The effect of doing so is undefined.

    • createIteratorIterator

      public static <T> ExtendedIterator<T> createIteratorIterator(Iterator<Iterator<T>> it)
      Given an Iterator that returns Iterator's, this creates an Iterator over the next level values. Similar to list splicing in lisp.
    • forTestingOnly_getBase

      public Iterator<? extends T> forTestingOnly_getBase()
    • hasNext

      public boolean hasNext()
      hasNext: defer to the base iterator
      Specified by:
      hasNext in interface Iterator<T>
      hasNext in class NiceIterator<T>
    • next

      public T next()
      next: defer to the base iterator
      Specified by:
      next in interface Iterator<T>
      next in class NiceIterator<T>
    • remove

      public void remove()
      if .remove() is allowed, delegate to the base iterator's .remove; otherwise, throw an UnsupportedOperationException.
      Specified by:
      remove in interface Iterator<T>
      remove in class NiceIterator<T>
    • close

      public void close()
      close: defer to the base, iff it is closable
      Specified by:
      close in interface ClosableIterator<T>
      Specified by:
      close in interface Closeable
      close in class NiceIterator<T>
    • close

      public static void close(Iterator<?> it)
      if it is a Closableiterator, close it. Abstracts away from tests [that were] scattered through the code.