Class SeqBuffer.BufferSpliterator

java.lang.Object
org.jooq.lambda.SeqBuffer.BufferSpliterator
All Implemented Interfaces:
Spliterator<T>
Enclosing class:
SeqBuffer<T>

private class SeqBuffer.BufferSpliterator extends Object implements Spliterator<T>
Special Spliterator whose tryAdvance method can buffer (i.e. can advance the source spliterator). Instances of this class are NOT thread-safe but they interact in a thread-safe way with SeqBuffer.
  • Field Details

    • nextIndex

      private int nextIndex
      Index of the element that will be returned upon next call to tryAdvance if such element exists.
  • Constructor Details

    • BufferSpliterator

      private BufferSpliterator()
  • Method Details

    • tryAdvance

      public boolean tryAdvance(Consumer<? super T> action)
      Specified by:
      tryAdvance in interface Spliterator<T>
    • tryAdvanceThisWithBuffering

      private boolean tryAdvanceThisWithBuffering(Consumer<? super T> action)
      Tries to advance this Spliterator to element at nextIndex, buffering source elements into buffer if necessary. Synchronized on buffer in order to: - obtain accurate buffer.size() - safely copy from source to buffer (if needed) - safely call buffer.get()
    • canAdvanceThisWithBuffering

      private boolean canAdvanceThisWithBuffering()
    • canAdvanceThisAtOnce

      private boolean canAdvanceThisAtOnce()
    • tryAdvanceSource

      private boolean tryAdvanceSource()
      Buffers (i.e. advances the source) until an item at nextIndex is added to the buffer, or until the source is exhausted. Guarded by: buffer
    • advanceThis

      private T advanceThis()
    • tryAdvanceThisAtOnce

      private boolean tryAdvanceThisAtOnce(Consumer<? super T> action)
      Called only when buffering has been completed.
    • estimateSize

      public long estimateSize()
      Specified by:
      estimateSize in interface Spliterator<T>
    • estimateSizeDuringBuffering

      private long estimateSizeDuringBuffering()
      Returns the estimate size of this Spliterator. Synchronized to get an accurate sum of buffer.size() and source.estimateSize().
    • numberOfElementsLeftInBuffer

      private int numberOfElementsLeftInBuffer()
    • trySplit

      public Spliterator<T> trySplit()
      Specified by:
      trySplit in interface Spliterator<T>
    • characteristics

      public int characteristics()
      Specified by:
      characteristics in interface Spliterator<T>
    • getComparator

      public Comparator<? super T> getComparator()
      Specified by:
      getComparator in interface Spliterator<T>
    • parentSeqBuffer

      SeqBuffer<T> parentSeqBuffer()