Class SeqBuffer<T>


  • final class SeqBuffer<T>
    extends java.lang.Object
    Lazily consumes given Spliterator through Seqs provided by method seq(). This method may be called multiple times, and the returned Seqs may be consumed interchangeably. Instances of this class ARE thread-safe.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  SeqBuffer.BufferSpliterator
      Special Spliterator whose tryAdvance method can buffer (i.e.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<T> buffer  
      private boolean buffering
      True while source hasn't reported that it's exhausted.
      private java.util.Spliterator<T> source  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SeqBuffer​(java.util.Spliterator<T> source)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static <T> SeqBuffer<T> of​(java.util.Spliterator<T> spliterator)  
      (package private) static <T> SeqBuffer<T> of​(java.util.stream.Stream<? extends T> stream)  
      (package private) Seq<T> seq()
      Returns a Seq over given source.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • source

        private final java.util.Spliterator<T> source
      • buffer

        private final java.util.List<T> buffer
      • buffering

        private volatile boolean buffering
        True while source hasn't reported that it's exhausted. This volatile field acts as a memory barrier for the contents of source and buffer:
    • Constructor Detail

      • SeqBuffer

        private SeqBuffer​(java.util.Spliterator<T> source)
    • Method Detail

      • of

        static <T> SeqBuffer<T> of​(java.util.stream.Stream<? extends T> stream)
      • of

        static <T> SeqBuffer<T> of​(java.util.Spliterator<T> spliterator)
      • seq

        Seq<T> seq()
        Returns a Seq over given source. Although such Seq is not thread-safe by itself, it interacts in a thread-safe way with its parent SeqBuffer. As a result, each Seq returned by this method can be safely used on a different thread.