T
- the nature of ending pointspublic class ComparableInterval<T extends Comparable<T>> extends GenericInterval<T> implements Comparable<ComparableInterval<T>>
Comparable
data.
This class is copy of ComparableInterval
. It adds the methods
mergeTo(ComparableInterval)
, getIntersectionWith(ComparableInterval)
and
extendTo(Comparable)
, as well as an additional constructor.
The upper and lower boundaries have to be Comparable, so that the correct order can be checked. This class can be
extended and GenericInterval.toString()
may be overridden.
The generic class must implement java.lang.Comparable
It is HIGHLY recommended this class be immutable!
Interval
Constructor and Description |
---|
ComparableInterval(IntervalEndpointType lowerEndpointIn,
T lowerDataIn,
T upperDataIn,
IntervalEndpointType upperEndpointIn)
Constructor.
|
ComparableInterval(T lowerData,
T upperData)
Builds a new
ComparableInterval with closed endpoints. |
Modifier and Type | Method and Description |
---|---|
int |
compareLowerEndTo(ComparableInterval<T> interval)
Compares the lower end point with the lower end point of the given interval.
|
int |
compareTo(ComparableInterval<T> interval)
Compares this interval with the specified interval.
|
int |
compareUpperEndTo(ComparableInterval<T> interval)
Compares the upper end point with the upper end point of the given interval.
|
boolean |
contains(Comparable<T> cmp)
Returns true if the provided value belongs to the interval.
|
boolean |
equals(Object interval)
Checks if the instance represents the same
ComparableInterval as another instance. |
ComparableInterval<T> |
extendTo(T value)
Returns the interval after extending it so that it includes (closed endpoint) or is
connected (open endpoint) to the specified value.
|
ComparableInterval<T> |
getIntersectionWith(ComparableInterval<T> interval)
Returns the intersection with another interval.
|
int |
hashCode() |
boolean |
includes(ComparableInterval<T> interval)
Returns true if this interval includes the other.
|
boolean |
isConnectedTo(ComparableInterval<T> interval)
Returns true when this interval's lower end-point connects with another interval's upper
end-point.
|
ComparableInterval<T> |
mergeTo(ComparableInterval<T> interval)
Returns this interval merged with another interval (if they can be merged).
|
boolean |
overlaps(ComparableInterval<T> interval)
Returns true if the two intervals overlap.
|
getLowerData, getLowerEndpoint, getUpperData, getUpperEndpoint, toString
public ComparableInterval(T lowerData, T upperData)
ComparableInterval
with closed endpoints.
The input parameters must not be null. The lower and upper endpoints must also be properly ordered. Otherwise a
MathIllegalArgumentException
is thrown.
lowerData
- the lower end data valueupperData
- the upper end data valueMathIllegalArgumentException
- when the interval is invalid (unchecked exception)public ComparableInterval(IntervalEndpointType lowerEndpointIn, T lowerDataIn, T upperDataIn, IntervalEndpointType upperEndpointIn)
MathIllegalArgumentException
is thrown.lowerDataIn
- lower end data valueupperDataIn
- upper end data valuelowerEndpointIn
- lower end point stateupperEndpointIn
- upper end point stateMathIllegalArgumentException
- when the interval is invalid (unchecked exception)public final boolean contains(Comparable<T> cmp)
cmp
- the tested valuepublic final boolean overlaps(ComparableInterval<T> interval)
The intervals [l1 ; u1] and [l2 ; u2] overlap if u1>=l2 AND l1<=u2. If one of the end-points is open, the comparison is strict.
interval
- the other intervalpublic final boolean includes(ComparableInterval<T> interval)
The interval [l1; u1] includes the interval [l2; u2] if l1<=l2 and u1>=u2. If the end-point of the including interval is open and the end-point of the included interval is closed, the comparison is strict.
interval
- the interval tested for inclusionpublic final boolean isConnectedTo(ComparableInterval<T> interval)
Two end-points connects if their values are identical and their end-points have different types (one is open and the other is closed).
interval
- the interval tested for connectionpublic ComparableInterval<T> mergeTo(ComparableInterval<T> interval)
To be merged, the two intervals must overlap or be connected. If that is not the case, the method returns
null
.
interval
- the other intervalpublic ComparableInterval<T> getIntersectionWith(ComparableInterval<T> interval)
If the intervals do not overlap, the method returns null.
interval
- the other intervalpublic ComparableInterval<T> extendTo(T value)
value
- the target valuepublic final int compareLowerEndTo(ComparableInterval<T> interval)
It returns a negative integer if the lower end point is inferior than the lower end point of the given interval, zero if they are equal, or a positive integer if is it superior. The method also compares the lower end point type of the two intervals.
interval
- the interval tested for lower end point comparisonpublic final int compareUpperEndTo(ComparableInterval<T> interval)
It returns a negative integer if the upper end point is inferior than the upper end point of the given interval, zero if they are equal, or a positive integer if is it superior. The method also compares the upper end point type of the two intervals.
interval
- the interval tested for upper end point comparisonpublic int compareTo(ComparableInterval<T> interval)
compareTo
in interface Comparable<ComparableInterval<T extends Comparable<T>>>
interval
- the time interval to be compared.ClassCastException
- if the specified object's type prevents it
from being compared to this object.public boolean equals(Object interval)
ComparableInterval
as another instance.Copyright © 2019 CNES. All rights reserved.