Record Class LongRange

java.lang.Object
java.lang.Record
io.jenetics.util.LongRange
Record Components:
min - the minimum value of the range
max - the maximum value of the range
All Implemented Interfaces:
Serializable

public record LongRange(long min, long max) extends Record implements Serializable
Long range class.
Since:
3.2
Version:
8.3
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    LongRange(long value)
    Create a new (half-open) range, which contains only the given value: [value, value + 1).
    LongRange(long min, long max)
    Create a new LongRange object with the given min and max values.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(long value)
    Checks whether the given value is within the range [min, max).
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Return the intersection of this range with the other.
    long
    max()
    Returns the value of the max record component.
    long
    min()
    Returns the value of the min record component.
    static LongRange
    of(long value)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Class is a record now, and this factory method will be removed in the next major version.
    static LongRange
    of(long min, long max)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Class is a record now, and this factory method will be removed in the next major version.
    Returns a sequential ordered LongStream from min() (inclusive) to max() (exclusive) by an incremental step of 1.
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

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

    • LongRange

      public LongRange(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
      Throws:
      IllegalArgumentException - if min > max
    • LongRange

      public LongRange(long value)
      Create 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
  • Method Details

    • 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

      @Deprecated(since="8.2", forRemoval=true) public static LongRange of(long min, long max)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Class is a record now, and this factory method will be removed in the next major version. Use LongRange(long, long) instead.
      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

      @Deprecated(since="8.2", forRemoval=true) public static LongRange of(long value)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Class is a record now, and this factory method will be removed in the next major version. Use LongRange(long) instead.
      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
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • min

      public long min()
      Returns the value of the min record component.
      Returns:
      the value of the min record component
    • max

      public long max()
      Returns the value of the max record component.
      Returns:
      the value of the max record component