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

    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

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

    • min

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

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

      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

      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

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

      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

      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

      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

      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