Package org.pipecraft.pipes.sync.inter
Class SortedMergePipe<T>
- java.lang.Object
-
- org.pipecraft.pipes.sync.inter.SortedMergePipe<T>
-
- Type Parameters:
T- The data type of the items this pipe works with
- All Implemented Interfaces:
Closeable,AutoCloseable,BasePipe,Pipe<T>
public class SortedMergePipe<T> extends Object implements Pipe<T>
An intermediate pipe sort-merging the contents of a collection of sorted input pipes. The input pipes must have the same item data type, and must all be ordered by the same order relation. In contrast toSortedUnionPipe, the order relation (comparator) used here may not be consistent with item equality. Input pipes may have item repetitions, which will appear in the output. The output of the pipe is always sorted.- Author:
- Eyal Schneider
-
-
Constructor Summary
Constructors Constructor Description SortedMergePipe(Comparator<? super T> comparator, Pipe<T>... inputPipes)ConstructorSortedMergePipe(List<? extends Pipe<T>> inputPipes, Comparator<? super T> comparator)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()floatgetProgress()Tnext()Tpeek()voidstart()Performs pre-processing prior to item flow throw the pipe.
-
-
-
Constructor Detail
-
SortedMergePipe
public SortedMergePipe(List<? extends Pipe<T>> inputPipes, Comparator<? super T> comparator)
Constructor- Parameters:
inputPipes- The input pipes. Each of them must be sorted by the order defined in the provided comparator, and items may have duplicates.comparator- The total order relation to use when merging the data from the different input pipes. Should be consistent with the ordering of the input pipes.
-
SortedMergePipe
@SafeVarargs public SortedMergePipe(Comparator<? super T> comparator, Pipe<T>... inputPipes)
Constructor- Parameters:
comparator- The total order relation to use when merging the data from the different input pipes. Should be consistent with the ordering of the input pipes.inputPipes- The input pipes. Each of them must be sorted by the order defined in the provided comparator, and items may have duplicates.
-
-
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.- Specified by:
startin interfaceBasePipe- 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- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
next
public T next() throws PipeException, InterruptedException
- Specified by:
nextin interfacePipe<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()
-
getProgress
public float getProgress()
- Specified by:
getProgressin interfaceBasePipe- 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.
-
-