Record Class Interval<T extends Comparable<T>>

java.lang.Object
java.lang.Record
org.djutils.math.functions.Interval<T>
Type Parameters:
T - the payload type
Record Components:
low - low limit of the domain
lowInclusive - if true; the low limit is included; if false, the low limit is not included
high - high limit of the domain (inclusive)
highInclusive - if true; the high limit is included; if false; the high limit is not included
payload - the payload of this Interval. This is can be anything, but it is usually the MathFunction that is active in this Interval. When the Interval field is not used, supply any comparable class (e.g. String) and provide a null value to the constructor of Interval
All Implemented Interfaces:
Comparable<Interval<T>>

record Interval<T extends Comparable<T>>(double low, boolean lowInclusive, double high, boolean highInclusive, T extends Comparable<T> payload) extends Record implements Comparable<Interval<T>>
Immutable double interval, optionally including none, one, or both boundary values.

Copyright (c) 2024-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.

Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
  • Constructor Summary

    Constructors
    Constructor
    Description
    Interval(double low, boolean lowInclusive, double high, boolean highInclusive, T payload)
    Construct a new Interval.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    boolean
    covers(double x)
    Check if a value falls on this Interval.
    boolean
    covers(Interval<?> other)
    Check if this Interval completely covers some other Interval.
    boolean
    disjunct(Interval<?> other)
    Check if this Interval is completely disjunct of some other Interval.
    boolean
    Indicates whether some other object is "equal to" this one.
    int
    Returns a hash code value for this object.
    double
    Returns the value of the high record component.
    boolean
    Returns the value of the highInclusive record component.
    Compute the intersection of this Interval and some other Interval.
    double
    low()
    Returns the value of the low record component.
    boolean
    Returns the value of the lowInclusive record component.
    Returns the value of the payload record component.
    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

    • Interval

      Interval(double low, boolean lowInclusive, double high, boolean highInclusive, T payload)
      Construct a new Interval.
      Parameters:
      low - low limit of the domain
      lowInclusive - if true; the low limit is included; if false, the low limit is not included
      high - high limit of the domain (inclusive)
      highInclusive - if true; the high limit is included; if false; the high limit is not included
      payload - the payload of this Interval
  • Method Details

    • covers

      public boolean covers(Interval<?> other)
      Check if this Interval completely covers some other Interval.
      Parameters:
      other - the other Interval (not necessarily carrying a similarly typed pay load)
      Returns:
      boolean; true if this Interval completely covers the other Interval; false if any part of other Interval (which may be infinitesimally small) is outside this Interval
    • disjunct

      public boolean disjunct(Interval<?> other)
      Check if this Interval is completely disjunct of some other Interval.
      Parameters:
      other - the other Interval (not necessarily carrying a similarly typed pay load)
      Returns:
      boolean; true if this Interval is completely disjunct of the other Interval; false if any part of this Interval (which may be infinitesimally small) covers the other Interval
    • compareTo

      public int compareTo(Interval<T> other)
      Specified by:
      compareTo in interface Comparable<T extends Comparable<T>>
    • covers

      public boolean covers(double x)
      Check if a value falls on this Interval.
      Parameters:
      x - the value to check
      Returns:
      true if x lies on this Interval
    • intersection

      public Interval<T> intersection(Interval<?> other)
      Compute the intersection of this Interval and some other Interval. The other Interval need not have the same type of payload.
      Parameters:
      other - the other Interval
      Returns:
      the intersection of the intervals (can be null). If not null, the payload is the payload of this interval
    • 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 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 boolean equals(Object obj)
      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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      obj - the object with which to compare
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • low

      public double low()
      Returns the value of the low record component.
      Returns:
      the value of the low record component
    • lowInclusive

      public boolean lowInclusive()
      Returns the value of the lowInclusive record component.
      Returns:
      the value of the lowInclusive record component
    • high

      public double high()
      Returns the value of the high record component.
      Returns:
      the value of the high record component
    • highInclusive

      public boolean highInclusive()
      Returns the value of the highInclusive record component.
      Returns:
      the value of the highInclusive record component
    • payload

      public T payload()
      Returns the value of the payload record component.
      Returns:
      the value of the payload record component