Package org.eclipse.draw2d.geometry

# Record Class Interval

java.lang.Object
java.lang.Record
org.eclipse.draw2d.geometry.Interval

All Implemented Interfaces:
  `Serializable`

public record Interval(int begin, int length) extends Record implements Serializable
Represents interval in 1-dimensional space.

Since:
  3.13
See Also:
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`static final Interval`
`INFINITE`

## Constructor Summary

Constructors
Constructor
Description
`Interval()`
Creates a new Interval with zero length and starting at the origin.
`Interval(int begin, int length)`
Creates an instance of a `Interval` record class.
`Interval(Interval interval)`
Creates a new Interval exact same parameters as the given Interval.

## Method Summary

Modifier and Type
Method
Description
`int`
`begin()`
Returns the value of the `begin` record component.
`int`
`center()`
Returns the center of this Interval.
`boolean`
`contains(int value)`
Returns whether the given value is within [begin, begin + length).
`int`
`distance(int point)`
Calculates the distance to given `point`.
`int`
`end()`
Returns the end of this Interval.
`final boolean`
`equals(Object o)`
Indicates whether some other object is "equal to" this one.
`Interval`
`getCopy()`
Returns a new Interval which has the exact same parameters as this Interval.
`Interval`
`getIntersection(Interval interval)`
Calculates the intersection of the input `Interval` and this `Interval`.
`static int`
`getRightMostIntervalIndex(Interval[] intervals, int value)`
We can use this method for example for span support.
`Interval`
`growLeading(int delta)`
Calculates a new interval where its leading direction has been increased by the given `delta` (ex., grow left for horizontal interval).
`Interval`
`growTrailing(int delta)`
Calculates a new interval where its trailing direction has been increased by the given `delta` (ex., grow right for horizontal interval).
`final int`
`hashCode()`
Returns a hash code value for this object.
`boolean`
`intersects(Interval interval)`
Returns whether the input `Interval` intersects this `Interval`.
`boolean`
`isEmpty()`
Checks whether the Interval has zero length.
`boolean`
`isLeadingOf(Interval interval)`
Checks whether the input `Interval` starts before this `Interval`.
`boolean`
`isTrailingOf(Interval interval)`
Checks whether the input `Interval` starts after this `Interval`.
`int`
`length()`
Returns the value of the `length` record component.
`final String`
`toString()`
Returns a string representation of this record class.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Field Details

### INFINITE

public static final Interval INFINITE

## Constructor Details

### Interval

public Interval()
Creates a new Interval with zero length and starting at the origin.

Since:
  3.13

### Interval

public Interval(Interval interval)
Creates a new Interval exact same parameters as the given Interval.

Parameters:
  `interval` - The interval to copy
Since:
  3.13

### Interval

public Interval(int begin, int length)
Creates an instance of a `Interval` record class.

Parameters:
  `begin` - the value for the `begin` record component
  `length` - the value for the `length` record component

## Method Details

### center

public int center()
Returns the center of this Interval. The center is the middle of the begin and the end.

Returns:
  the center of this `Interval`.
Since:
  3.13

### contains

public boolean contains(int value)
Returns whether the given value is within [begin, begin + length).

Parameters:
  `value` - A position somewhere within 1-dimensional space.
Returns:
  `true` if the value is contained by this interval.
Since:
  3.13

### distance

public int distance(int point)
Calculates the distance to given `point`. Example:

      Let x=[10, 100]:
            distance for point 3 is 7.
            distance for point 10 is 0.
            distance for point 50 is 0.
            distance for point 110 is 0.
            distance for point 150 is 40.

Parameters:
  `point` - the point to calculate the distance to.
Returns:
  the calculated distance.
Since:
  3.13

### end

public int end()
Returns the end of this Interval. The end is the sum of the begin and the length of this Interval.

Returns:
  end of this Interval
Since:
  3.13

### getCopy

public Interval getCopy()
Returns a new Interval which has the exact same parameters as this Interval.

Returns:
  copy of this Interval
Since:
  3.13

### getIntersection

public Interval getIntersection(Interval interval)
Calculates the intersection of the input `Interval` and this `Interval`. I.e. the interval that is shared by both Intervals. If both Intervals are disjoint, an empty Interval is returned.

Parameters:
  `interval` - The Interval to intersect with.
Returns:
  The intersection of the input Interval and this Interval.
Since:
  3.13

### growLeading

public Interval growLeading(int delta)
Calculates a new interval where its leading direction has been increased by the given `delta` (ex., grow left for horizontal interval).

Parameters:
  `delta` - the value to increase the interval to.
Returns:
  The new interval with adjusted `begin` and `length`.
Since:
  3.13

### growTrailing

public Interval growTrailing(int delta)
Calculates a new interval where its trailing direction has been increased by the given `delta` (ex., grow right for horizontal interval).

Parameters:
  `delta` - the value to increase the interval to.
Returns:
  The new interval with adjusted `length`.
Since:
  3.13

### isEmpty

public boolean isEmpty()
Checks whether the Interval has zero length.

Returns:
  `true` if this `Interval` is empty.
Since:
  3.13

### intersects

public boolean intersects(Interval interval)
Returns whether the input `Interval` intersects this `Interval`.

Parameters:
  `interval` - The Interval to intersect with.
Returns:
  `true` if the input `Interval` intersects this `Interval`.
Since:
  3.13

### isLeadingOf

public boolean isLeadingOf(Interval interval)
Checks whether the input `Interval` starts before this `Interval`.

Parameters:
  `interval` - The Interval to compare with.
Returns:
  `true` if this interval leads the given `interval`, i.e. for horizontal interval `isLeadingOf()` returns `true` if this interval begins at the left of the given interval.
Since:
  3.13

### isTrailingOf

public boolean isTrailingOf(Interval interval)
Checks whether the input `Interval` starts after this `Interval`.

Parameters:
  `interval` - The Interval to compare with.
Returns:
  `true` if this interval trails the given `interval`, i.e. for horizontal interval `isTrailingOf()` returns `true` if this interval ends at the right of the given interval.
Since:
  3.13

### getRightMostIntervalIndex

public static int getRightMostIntervalIndex(Interval[] intervals, int value)
We can use this method for example for span support.

Parameters:
  `intervals` - sorted, disjoint array of intervals
Returns:
  index of rightmost interval that contains given value in its right half or `-1` if there is not such interval.
Since:
  3.13

### toString

public final 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.

### begin

public int begin()
Returns the value of the `begin` record component.

Returns:
  the value of the `begin` record component

### length

public int length()
Returns the value of the `length` record component.

Returns:
  the value of the `length` record component