Class IntRange

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

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

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

    Methods inherited from class java.lang.Object Link icon

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

    • min Link icon

      public int min()
      Return the minimum value of the integer range.
      Returns:
      the minimum value of the integer range
    • max Link icon

      public int max()
      Return the maximum value of the integer range.
      Returns:
      the maximum value of the integer range
    • contains Link icon

      public boolean contains(int 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 Link icon

      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
    • size Link icon

      public int size()
      Return the size of the IntRange: max - min.
      Returns:
      the size of the int range
      Since:
      3.9
    • stream Link icon

      public IntStream stream()
      Returns a sequential ordered IntStream 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 (int i = range.min(); i < range.max(); ++i) {
          // ...
      }
      
      Returns:
      a sequential IntStream for the range of int elements
      Since:
      3.4
    • of Link icon

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

      public static IntRange of(int 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 Link icon

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

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

      public String toString()
      Overrides:
      toString in class Object