Package com.complexible.common.collect

# Class SpoolingMarkResetIterator<T extends Copyable<T>>

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

All Implemented Interfaces:
  `CloseableIterator<T>`, `Copyable<MarkResetIterator<T>>`, `MarkResetIterator<T>`, `ResettableIterator<T>`, `RestrictedMarkResetIterator<T>`, `AutoCloseable`, `Iterator<T>`

public class SpoolingMarkResetIterator<T extends Copyable<T>> extends Object implements RestrictedMarkResetIterator<T>
A wrapper around `MarkResetSkippingIterator` with bounded spooling: once the `mark(T)` method has been called, the iterator will start spooling until one of the following conditions occurs: 1) the spooling threshold is reached, in which case the iterator switches to the `skipping-based` mark-reset behavior. 2) the `resetToMark()` method is called, in which case the iterator starts returning the spooled elements. Note: this implementation should only be used when marking the last returned element. Otherwise it is not able to retrieve the elements that are between the mark and the current position after calling the `resetToMark()` method. Similarly to `MarkResetSkippingIterator` this implementation does not close the base iterator.

Since:
  8.0
Author:
  Pavel Klinov

- ## Nested Class Summary

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

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

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SpoolingMarkResetIterator(PeekingSkippingIterator<T> theIterator, int theSpoolLimit)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  `RestrictedMarkResetIterator<T>`
  `copy()`
  Create a deep copy of the object which does not share any references with the original.
  `boolean`
  `hasNext()`
  `void`
  `mark(T mark)`
  Creates a mark from the provided element.
  `T`
  `next()`
  `void`
  `reset()`
  Resets the iterator to the beginning so the following `Iterator.next()` call will return the first element in this iteration.
  `void`
  `resetToMark()`
  Rewinds the position of the iterator to the previously marked element.
  `void`
  `restrict(Predicate<T> restriction)`

  ### 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, remove`

- ## Constructor Details

  - ### SpoolingMarkResetIterator

    public SpoolingMarkResetIterator(PeekingSkippingIterator<T> theIterator, int theSpoolLimit)

- ## Method Details

  - ### restrict

    public void restrict(Predicate<T> restriction)
    Specified by:
      `restrict` in interface `RestrictedMarkResetIterator<T extends Copyable<T>>`

  - ### next

    public T next()
    Specified by:
      `next` in interface `Iterator<T extends Copyable<T>>`

  - ### hasNext

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

  - ### mark

    public void mark(T mark)
    Description copied from interface: `MarkResetIterator`
    Creates a mark from the provided element.
    Specified by:
      `mark` in interface `MarkResetIterator<T extends Copyable<T>>`

  - ### resetToMark

    public void resetToMark()
    Description copied from interface: `MarkResetIterator`
    Rewinds the position of the iterator to the previously marked element.
    Specified by:
      `resetToMark` in interface `MarkResetIterator<T extends Copyable<T>>`

  - ### close

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

  - ### reset

    public void reset()
    Description copied from interface: `ResettableIterator`
    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 extends Copyable<T>>`

  - ### copy

    public RestrictedMarkResetIterator<T> copy()
    Description copied from interface: `Copyable`
    Create a deep copy of the object which does not share any references with the original.
    Specified by:
      `copy` in interface `Copyable<T extends Copyable<T>>`
    Specified by:
      `copy` in interface `RestrictedMarkResetIterator<T extends Copyable<T>>`
    Returns:
      a copy of the object