Package org.pipecraft.pipes.terminal
Class PercentilePipe<T,C extends Comparable<C>>
- java.lang.Object
-
- org.pipecraft.pipes.terminal.TerminalPipe
-
- org.pipecraft.pipes.terminal.PercentilePipe<T,C>
-
- Type Parameters:
T- The input items typeC- The type of the sorting component. Must be comparable and must be suitable for hash keys.
- All Implemented Interfaces:
Closeable,AutoCloseable,BasePipe
public class PercentilePipe<T,C extends Comparable<C>> extends TerminalPipe
A terminal pipe that finds a given percentile p in the input pipe. Each item is mapped to a 'sorting component', specifying the metric by which the order is defined. This implementation uses O(K) memory, where k is the number of unique sorting-component values. Therefore, it's not safe to use this pipe when K is large, but very efficient when K items can be stored in memory.- Author:
- Eyal Schneider
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()CgetPercentileValue()voidstart()Performs pre-processing prior to item flow throw the pipe.-
Methods inherited from class org.pipecraft.pipes.terminal.TerminalPipe
getProgress
-
-
-
-
Constructor Detail
-
PercentilePipe
public PercentilePipe(Pipe<T> input, double p, Function<T,C> sortingComponentExtractor)
Constructor- Parameters:
input- The input pipep- The required percentile. Must be between 0.0 and 1.0.sortingComponentExtractor- Extracts the sorting component from input items. Must not return null. The sorting component but be suitable for hash keys!
-
-
Method Detail
-
close
public void close() throws IOException- Throws:
IOException
-
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.
-
getPercentileValue
public C getPercentileValue()
- Returns:
- The required percentile value, or null if the input is empty. Call this method after start() completes running.
-
-