Class SeqBuffer.BufferSpliterator

  • All Implemented Interfaces:
    java.util.Spliterator<T>
    Enclosing class:
    SeqBuffer<T>

    private class SeqBuffer.BufferSpliterator
    extends java.lang.Object
    implements java.util.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.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Spliterator

        java.util.Spliterator.OfDouble, java.util.Spliterator.OfInt, java.util.Spliterator.OfLong, java.util.Spliterator.OfPrimitive<T extends java.lang.Object,​T_CONS extends java.lang.Object,​T_SPLITR extends java.util.Spliterator.OfPrimitive<T,​T_CONS,​T_SPLITR>>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int nextIndex
      Index of the element that will be returned upon next call to tryAdvance if such element exists.
      • Fields inherited from interface java.util.Spliterator

        CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private BufferSpliterator()  
    • Field Detail

      • nextIndex

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

      • BufferSpliterator

        private BufferSpliterator()
    • Method Detail

      • tryAdvance

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

        private boolean tryAdvanceThisWithBuffering​(java.util.function.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​(java.util.function.Consumer<? super T> action)
        Called only when buffering has been completed.
      • estimateSize

        public long estimateSize()
        Specified by:
        estimateSize in interface java.util.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 java.util.Spliterator<T> trySplit()
        Specified by:
        trySplit in interface java.util.Spliterator<T>
      • characteristics

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

        public java.util.Comparator<? super T> getComparator()
        Specified by:
        getComparator in interface java.util.Spliterator<T>