Class LongRange

java.lang.Object
io.jenetics.util.LongRange
All Implemented Interfaces:
Serializable

public final class LongRange extends Object implements Serializable
Long range class.
Since:
3.2
Version:
6.0
See Also:
Implementation Note:
This class is immutable and thread-safe.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(long value)
    Checks whether the given value is within the range [min, max).
    boolean
     
    int
     
    Return the intersection of this range with the other.
    long
    max()
    Return the maximum value of the long range.
    long
    min()
    Return the minimum value of the long range.
    static LongRange
    of(long value)
    Return a new (half-open) range, which contains only the given value: [value, value + 1).
    static LongRange
    of(long min, long max)
    Create a new LongRange object with the given min and max values.
    Returns a sequential ordered LongStream from min() (inclusive) to max() (exclusive) by an incremental step of 1.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • min

      public long min()
      Return the minimum value of the long range.
      Returns:
      the minimum value of the long range
    • max

      public long max()
      Return the maximum value of the long range.
      Returns:
      the maximum value of the long range
    • contains

      public boolean contains(long value)
      Checks whether the given value is within the range [min, max).
      Parameters:
      value - the value to check
      Returns:
      true if the value is with the range [min, max), false otherwise
      Since:
      8.0
    • intersect

      Return the intersection of this range with the other.
      Parameters:
      other - the intersection range or Optional.empty() if there is none
      Returns:
      the range intersection
      Since:
      8.0
    • stream

      public LongStream stream()
      Returns a sequential ordered LongStream from min() (inclusive) to max() (exclusive) by an incremental step of 1.

      An equivalent sequence of increasing values can be produced sequentially using a for loop as follows:

      for (long i = range.min(); i < range.max(); ++i) {
          // ...
      }
      
      Returns:
      a sequential LongStream for the range of long elements
      Since:
      3.4
    • of

      public static LongRange of(long min, long max)
      Create a new LongRange object with the given min and max values.
      Parameters:
      min - the lower bound of the long range
      max - the upper bound of the long range
      Returns:
      a new LongRange object
      Throws:
      IllegalArgumentException - if min > max
    • of

      public static LongRange of(long value)
      Return a new (half-open) range, which contains only the given value: [value, value + 1).
      Parameters:
      value - the value of the created (half-open) integer range
      Returns:
      a new (half-open) range, which contains only the given value
      Since:
      4.0
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object