Class ConcatPipe<T>

  • All Implemented Interfaces:
    Closeable, AutoCloseable, BasePipe, Pipe<T>

    public class ConcatPipe<T>
    extends Object
    implements Pipe<T>
    An intermediate pipe consisting of concatenating the contents of a series of pipes
    Author:
    Eyal Schneider
    • Constructor Detail

      • ConcatPipe

        public ConcatPipe​(List<PipeSupplier<T>> inputs)
        Constructor
        Parameters:
        inputs - A list of pipe generators for the pipes to be concatenated, in the required concatenation order. The usage of pipe suppliers instead of ready-to-use pipes allows building the pipes one by one, instead of allocating all resources at once.
      • ConcatPipe

        public ConcatPipe​(PipeSupplier<T>... inputs)
        Constructor
        Parameters:
        inputs - A list of pipe generators for the pipes to be concatenated, in the required concatenation order. The usage of pipe suppliers instead of ready-to-use pipes allows building the pipes one by one, instead of allocating all resources at once.
    • Method Detail

      • next

        public T next()
               throws PipeException,
                      InterruptedException
        Specified by:
        next in interface Pipe<T>
        Returns:
        The next item in this pipe output, or null if the output end has been reached. May be a blocking operation.
        Throws:
        PipeException - In case of pipe errors in this pipe or somewhere up-stream while trying to prepare next item to return.
        InterruptedException - In case that the operation has been interrupted by another thread.
      • peek

        public T peek()
        Specified by:
        peek in interface Pipe<T>
        Returns:
        The next item in the pipe's output. Does not remove it, so next call to next() will return it.
      • fromPipes

        public static <T> ConcatPipe<T> fromPipes​(List<Pipe<T>> inputs)
        Parameters:
        inputs - A list of pipes to be concatenated, in the required concatenation order.
        Returns:
        A ConcatPipe initialized with the given input pipes
      • fromPipes

        @SafeVarargs
        public static <T> ConcatPipe<T> fromPipes​(Pipe<T>... inputs)
        Parameters:
        inputs - An array of pipes to be concatenated, in the required concatenation order.
        Returns:
        A ConcatPipe initialized with the given input pipes
      • start

        public void start()
                   throws PipeException,
                          InterruptedException
        Description copied from interface: BasePipe
        Performs pre-processing prior to item flow throw the pipe. Implementations must call the same method for all their input pipes before accessing their items. This is typically done here.
        Specified by:
        start in interface BasePipe
        Throws:
        PipeException - In case of pipe errors in this pipe or somewhere up-stream.
        InterruptedException - In case that the operation has been interrupted by another thread.
      • getProgress

        public float getProgress()
        Specified by:
        getProgress in interface BasePipe
        Returns:
        The pipe flow progress, as a floating number between 0.0 and 1.0. Important implementation rules: 1) Calling this method before start() call is complete isn't allowed and has an undefined behavior. 2) Implementation should do best effort to provide an estimate of the progress this pipe has made (0.0 - 1.0) 3) When the pipe is fully consumed, getProgress() should return 1.0. 4) Results must be monotonous, i.e. results of consecutive calls may never be decreasing. 5) Thread safety: progress may be maintained by some thread/s but monitoring by other threads. Implementations must be thread safe.