Class PortionSamplerPipe<T>

  • All Implemented Interfaces:
    Closeable, AutoCloseable, BasePipe, Pipe<T>

    public class PortionSamplerPipe<T>
    extends FilterBasePipe<T>
    A pipe sampling about x% of the incoming items. The exact number of sampled items depends on the input pipe length and on the provided randomizer.
    Author:
    Eyal Schneider
    • Constructor Detail

      • PortionSamplerPipe

        public PortionSamplerPipe​(Pipe<T> input,
                                  double p,
                                  Random rnd)
        Constructor
        Parameters:
        input - The input pipe
        p - The portion of input items to sample. Must be between 0.0 and 1.0.
        rnd - The randomizer to use, if consistency is required
      • PortionSamplerPipe

        public PortionSamplerPipe​(Pipe<T> input,
                                  double p)
        Constructor
        Parameters:
        input - The input pipe
        p - The portion of input items to sample. Must be between 0.0 and 1.0.
    • Method Detail

      • shouldSelect

        protected boolean shouldSelect​(T item)
        Specified by:
        shouldSelect in class FilterBasePipe<T>
        Parameters:
        item - The next item from the input stream
        Returns:
        true if and only if the item should be selected