Class MapWriterPipe<T,​K,​V>

  • Type Parameters:
    T - The type of items in the input pipe
    K - The key type in the output map. Must be suitable as a key map (i.e. equal items must have the same hashcode).
    V - The value type in the output map
    All Implemented Interfaces:
    Closeable, AutoCloseable, BasePipe

    public class MapWriterPipe<T,​K,​V>
    extends TerminalPipe
    A terminal pipe writing all contents from an input pipe into a given Map. Thread safety: It's the responsibility of the caller to make sure access to the output map is thread safe. For example, if the map 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

      • MapWriterPipe

        public MapWriterPipe​(Pipe<T> inputPipe,
                             FailableFunction<T,​K,​ValidationPipeException> keyExtractor,
                             FailableFunction<T,​V,​ValidationPipeException> valueExtractor)
        Constructor Creates a writer that populates a new HashMap.
        Parameters:
        inputPipe - The input pipe to consume
        keyExtractor - The logic for extracting the map key from an input item. In case that two different items produce the same key, the latter (in input pipe appearance order) will override the results of the former.
        valueExtractor - The logic for extracting the map value from an input item
      • MapWriterPipe

        public MapWriterPipe​(Pipe<T> inputPipe,
                             FailableFunction<T,​K,​ValidationPipeException> keyExtractor,
                             FailableFunction<T,​V,​ValidationPipeException> valueExtractor,
                             Map<K,​V> outputMap)
        Constructor
        Parameters:
        inputPipe - The input pipe to consume
        keyExtractor - The logic for extracting the map key from an input item. In case that two different items produce the same key, the latter (in input pipe appearance order) will override the results of the former.
        valueExtractor - The logic for extracting the map value from an input item
        outputMap - The map to populate
    • 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 Map<K,​V> getItems()
        Returns:
        The output map