AbstractIterator (apache-cassandra API)
Date: 2018-02-14

org.apache.cassandra.index.sasi.utils

## Class AbstractIterator<T>

- java.lang.Object
- - org.apache.cassandra.index.sasi.utils.AbstractIterator<T>

- All Implemented Interfaces:
    com.google.common.collect.PeekingIterator<T>, java.util.Iterator<T>
  Direct Known Subclasses:
    RangeIterator

      public abstract class AbstractIterator<T>
      extends java.lang.Object
      implements com.google.common.collect.PeekingIterator<T>

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected static class` | `AbstractIterator.State`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected T` | `next`
    `protected AbstractIterator.State` | `state`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractIterator()` Constructor for use by subclasses.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract T` | `computeNext()` Returns the next element.
    `protected T` | `endOfData()` Implementations of `computeNext()` must invoke this method when there are no elements left in the iteration.
    `boolean` | `hasNext()`
    `T` | `next()`
    `T` | `peek()` Returns the next element in the iteration without advancing the iteration, according to the contract of `PeekingIterator.peek()`.
    `void` | `remove()`
    `protected boolean` | `tryToComputeNext()`

    - ### 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 Detail

    - #### state

          protected AbstractIterator.State state

    - #### next

          protected T next

  - ### Constructor Detail

    - #### AbstractIterator

          protected AbstractIterator()

      Constructor for use by subclasses.

  - ### Method Detail

    - #### computeNext

          protected abstract T computeNext()

      Returns 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.

      The initial invocation of `hasNext()` or `next()` calls this method, as does the first invocation of `hasNext` or `next` following each successful call to `next`. Once the implementation either invokes `endOfData` or throws an exception, `computeNext` is guaranteed to never be called again.

      If this method throws an exception, it will propagate outward to the `hasNext` or `next` invocation that invoked this method. Any further attempts to use the iterator will result in an `IllegalStateException`.

      The implementation of this method may not invoke the `hasNext`, `next`, or `peek()` methods on this instance; if it does, an `IllegalStateException` will result.

      Returns:
        the next element if there was one. If `endOfData` was called during execution, the return value will be ignored.
      Throws:
        `java.lang.RuntimeException` - if any unrecoverable error happens. This exception will propagate outward to the `hasNext()`, `next()`, or `peek()` invocation that invoked this method. Any further attempts to use the iterator will result in an `IllegalStateException`.

    - #### endOfData

          protected final T endOfData()

      Implementations of `computeNext()` must invoke this method when there are no elements left in the iteration.
      Returns:
        `null`; a convenience so your `computeNext` implementation can use the simple statement `return endOfData();`

    - #### hasNext

          public final boolean hasNext()

      Specified by:
        `hasNext` in interface `java.util.Iterator<T>`

    - #### tryToComputeNext

          protected boolean tryToComputeNext()

    - #### next

          public final T next()

      Specified by:
        `next` in interface `com.google.common.collect.PeekingIterator<T>`
      Specified by:
        `next` in interface `java.util.Iterator<T>`

    - #### remove

          public void remove()

      Specified by:
        `remove` in interface `com.google.common.collect.PeekingIterator<T>`
      Specified by:
        `remove` in interface `java.util.Iterator<T>`

    - #### peek

          public final T peek()

      Returns the next element in the iteration without advancing the iteration, according to the contract of `PeekingIterator.peek()`.

      Implementations of `AbstractIterator` that wish to expose this functionality should implement `PeekingIterator`.

      Specified by:
        `peek` in interface `com.google.common.collect.PeekingIterator<T>`

Copyright © 2018 The Apache Software Foundation