Package com.complexible.common.collect

# Class AbstractSkippingIterator<T>

java.lang.Object
com.complexible.common.collect.AbstractSkippingIterator<T>

All Implemented Interfaces:
  `CloseableIterator<T>`, `PeekingSkippingIterator<T>`, `ResettableIterator<T>`, `SkippingIterator<T>`, `com.google.common.collect.PeekingIterator<T>`, `AutoCloseable`, `Iterator<T>`

Direct Known Subclasses:
  `MarkResetSkippingIterator`

public abstract class AbstractSkippingIterator<T> extends Object implements PeekingSkippingIterator<T>, CloseableIterator<T>

Abstract `SkippingIterator` implementation to help with concrete implementations. The remove function of this implementation throws `UnsupportedOperationException` and its size estimate is `unknown`.

Version:
  2.2.1
Author:
  Evren Sirin, Pavel Klinov, Michael Grove

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from interface com.complexible.common.base.CloseableIterator

  `CloseableIterator.AbstractCloseableIterator<T>, CloseableIterator.DelegatingCloseableIterator<T>, CloseableIterator.EmptyCloseableIterator<T>`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final Comparator<T>`
  `mComparator`
  The comparator which defines the order for skipping

  ### Fields inherited from interface com.complexible.common.collect.SkippingIterator

  `UNKNOWN_SIZE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AbstractSkippingIterator(Comparator<T> theComparator)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `assertOpen()`
  `void`
  `close()`
  `Comparator<T>`
  `comparator()`
  Returns the comparator for this iterator that specifies the order in which the elements are returned.
  `protected abstract T`
  `computeNext()`
  Return the next element to be returned by the iterator
  `protected abstract T`
  `computeSkipTo(T theTarget)`
  Returns the element that this iteration has skipped to or `null` if it ran off the end.
  `protected T`
  `computeSkipTo(T theTarget, T theBound)`
  `protected final T`
  `endOfData()`
  Signal that you're done iterating.
  `long`
  `estimatedSize()`
  Returns the estimated size of this iterator without advancing the iterator or `SkippingIterator.UNKNOWN_SIZE` if the estimate is not known.
  `final boolean`
  `hasNext()`
  `protected boolean`
  `isClosed()`
  `boolean`
  `isLessOrEqualThan(T theElement, T theBound)`
  `final T`
  `next()`
  `final T`
  `peek()`
  Implementation of peeking to the next item returned by the iterator.
  `protected abstract void`
  `performReset()`
  `void`
  `remove()`
  `final void`
  `reset()`
  Resets the iterator to the beginning so the following `Iterator.next()` call will return the first element in this iteration.
  `protected final void`
  `resetState()`
  `final boolean`
  `skipTo(T theElement)`
  Moves the iterators position to the next element which is greater than or equal to `theElement`.
  `final boolean`
  `skipTo(T theElement, T theBound)`
  Same contract as `SkippingIterator.skipTo(Object)` but skipping is bounded: if the implementation can determine that the next element after target is greater than the bound, it can return false.
  `protected void`
  `validateSkipTarget(T theTarget)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface java.util.Iterator

  `forEachRemaining`

- ## Field Details

  - ### mComparator

    protected final Comparator<T> mComparator
    The comparator which defines the order for skipping

- ## Constructor Details

  - ### AbstractSkippingIterator

    public AbstractSkippingIterator(Comparator<T> theComparator)

- ## Method Details

  - ### comparator

    public Comparator<T> comparator()
    Returns the comparator for this iterator that specifies the order in which the elements are returned.
    Specified by:
      `comparator` in interface `SkippingIterator<T>`

  - ### estimatedSize

    public long estimatedSize()
    Returns the estimated size of this iterator without advancing the iterator or `SkippingIterator.UNKNOWN_SIZE` if the estimate is not known. The estimate is for the whole iterator and will not change after the iterator is advanced. There is no guarantee about the accuracy of the estimate.
    Specified by:
      `estimatedSize` in interface `SkippingIterator<T>`

  - ### remove

    public void remove()
    Specified by:
      `remove` in interface `Iterator<T>`
    Specified by:
      `remove` in interface `com.google.common.collect.PeekingIterator<T>`

  - ### computeNext

    protected abstract T computeNext()
    Return the next element to be returned by the iterator
    Returns:
      the next element

  - ### computeSkipTo

    protected abstract T computeSkipTo(T theTarget)
    Returns the element that this iteration has skipped to or `null` if it ran off the end.
    Parameters:
      `theTarget` - the skipping target
    Returns:
      the first element that is greater or equal to the skipping target, or `null` if it doesn't exist.

  - ### computeSkipTo

    protected T computeSkipTo(T theTarget, T theBound)

  - ### isLessOrEqualThan

    public boolean isLessOrEqualThan(T theElement, T theBound)

  - ### next

    public final T next()
    Specified by:
      `next` in interface `Iterator<T>`
    Specified by:
      `next` in interface `com.google.common.collect.PeekingIterator<T>`

  - ### endOfData

    protected final T endOfData()
    Signal that you're done iterating.
    Returns:
      nothing, the result is ignored

  - ### hasNext

    public final boolean hasNext()
    Specified by:
      `hasNext` in interface `Iterator<T>`

  - ### close

    public void close()
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `CloseableIterator<T>`

  - ### peek

    public final T peek()
    Implementation of peeking to the next item returned by the iterator. Anyone wishing to expose this method simply need to also implement the `PeekingIterator` interface.
    Specified by:
      `peek` in interface `com.google.common.collect.PeekingIterator<T>`
    Returns:
      the next element to be returned

  - ### skipTo

    public final boolean skipTo(T theElement)
    Description copied from interface: `SkippingIterator`
    Moves the iterators position to the next element which is greater than or equal to `theElement`.
    Specified by:
      `skipTo` in interface `SkippingIterator<T>`
    Returns:
      true, if such an element exists (in which case the `Iterator.next()` call will return it), false otherwise

  - ### skipTo

    public final boolean skipTo(T theElement, T theBound)
    Same contract as `SkippingIterator.skipTo(Object)` but skipping is bounded: if the implementation can determine that the next element after target is greater than the bound, it can return false. In other words, if the method returns false, no element between the target (incl.) and the bound (incl.) exists. If the method returns true, the next element is definitely greater or equal than the target, but may exceed the bound. If the method returns false, there's no guarantee on the state of the iterator. If it needs to be reused, it must be first reset.
    Specified by:
      `skipTo` in interface `SkippingIterator<T>`
    Parameters:
      `theElement` - the target
      `theBound` - the bound. null means no upper bound.
    Returns:
      true, if an element that is greater than or equal to `theElement` but less than or equal to `theBound` exists.

  - ### validateSkipTarget

    protected void validateSkipTarget(T theTarget)

  - ### reset

    public final void reset()
    Resets the iterator to the beginning so the following `Iterator.next()` call will return the first element in this iteration.
    Specified by:
      `reset` in interface `ResettableIterator<T>`

  - ### isClosed

    protected boolean isClosed()

  - ### assertOpen

    protected void assertOpen()

  - ### resetState

    protected final void resetState()

  - ### performReset

    protected abstract void performReset()