Class RangeStream

java.lang.Object
org.monte.media.util.stream.RangeStream

public class RangeStream extends Object
RangeStream processes a range of integer sequentially or in parallel sub-ranges.
Author:
Werner Randelshofer
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    forEach(IntConsumer consumer)
    Invokes the consumer to process an integer from the range until the entire reange is consumed.
    void
    Invokes the consumer to process sub-ranges until the entire range has been processed.
    Converts this stream to a parallel stream which will be recursively split up into ranges down to a threshold of 128.
    parallel(int threshold)
    Converts this stream to a parallel stream which will be recursively split up into ranges down to the specified treshold.
    range(int startInclusive, int endExclusive)
    Returns a range stream which will execute the the integers from startInclusive to endExclusive.
    Converts this stream back to a serial stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • parallel

      public RangeStream parallel()
      Converts this stream to a parallel stream which will be recursively split up into ranges down to a threshold of 128.
      Returns:
      this stream
    • parallel

      public RangeStream parallel(int threshold)
      Converts this stream to a parallel stream which will be recursively split up into ranges down to the specified treshold.
      Parameters:
      threshold - for recursive splitting, a value smaller or equal 0 convert this stream back into a serial stream
      Returns:
      this stream
    • serial

      public RangeStream serial()
      Converts this stream back to a serial stream.
      Returns:
      this stream
    • forEach

      public void forEach(IntConsumer consumer)
      Invokes the consumer to process an integer from the range until the entire reange is consumed.

      If this stream is parallel, the consumer is invoked in parallel.

      If this stream is sequential, the consumer is invoked sequentially.

      Parameters:
      consumer -
    • forEach

      public void forEach(BiIntConsumer consumer)
      Invokes the consumer to process sub-ranges until the entire range has been processed.

      If this stream is parallel, the range is split up into sub-ranges and the consumer is invoked for each sub-range in parallel.

      If this stream is sequential, the consumer is invoked with the entire range.

      Parameters:
      consumer -
    • range

      public static RangeStream range(int startInclusive, int endExclusive)
      Returns a range stream which will execute the the integers from startInclusive to endExclusive.
      Parameters:
      startInclusive -
      endExclusive -
      Returns:
      RangeStream