Class CollectionWriterPipe<T>

  • All Implemented Interfaces:
    Closeable, AutoCloseable, BasePipe

    public class CollectionWriterPipe<T>
    extends TerminalPipe
    A terminal pipe writing all contents from an input pipe into a given collection. Thread safety: It's the responsibility of the caller to make sure access to the output collection is thread safe. For example, if the collection itself is thread safe, or if a single thread creates, runs and queries the results (using getItems()) then there's no concurrency problem.
    Author:
    Eyal Schneider
    • Constructor Detail

      • CollectionWriterPipe

        public CollectionWriterPipe​(Pipe<T> input,
                                    Collection<T> outputCollection)
        Constructor
        Parameters:
        input - The input pipe
        outputCollection - The output collection to write items to.
      • CollectionWriterPipe

        public CollectionWriterPipe​(Pipe<T> input)
        Constructor Collects items into an ArrayList
        Parameters:
        input - The input pipe
    • Method Detail

      • 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.
        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.
      • getItems

        public Collection<T> getItems()
        Returns:
        The collection given in the constructor