Package org.pipecraft.pipes.terminal
Class MapWriterPipe<T,K,V>
- java.lang.Object
-
- org.pipecraft.pipes.terminal.TerminalPipe
-
- org.pipecraft.pipes.terminal.MapWriterPipe<T,K,V>
-
- Type Parameters:
T- The type of items in the input pipeK- 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 givenMap. 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 Summary
Constructors Constructor Description MapWriterPipe(Pipe<T> inputPipe, FailableFunction<T,K,ValidationPipeException> keyExtractor, FailableFunction<T,V,ValidationPipeException> valueExtractor)Constructor Creates a writer that populates a newHashMap.MapWriterPipe(Pipe<T> inputPipe, FailableFunction<T,K,ValidationPipeException> keyExtractor, FailableFunction<T,V,ValidationPipeException> valueExtractor, Map<K,V> outputMap)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Map<K,V>getItems()voidstart()Performs pre-processing prior to item flow throw the pipe.-
Methods inherited from class org.pipecraft.pipes.terminal.TerminalPipe
getProgress
-
-
-
-
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 newHashMap.- Parameters:
inputPipe- The input pipe to consumekeyExtractor- 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 consumekeyExtractor- 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 itemoutputMap- The map to populate
-
-
Method Detail
-
start
public void start() throws PipeException, InterruptedExceptionDescription copied from interface:BasePipePerforms 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.
-
close
public void close() throws IOException- Throws:
IOException
-
-