public final class TLcdDimensionInterval<T> extends Object implements Comparable<TLcdDimensionInterval<T>>
Intervals can be regular or singular (single-valued):
null
.null
is allowed to indicate unbounded.
Regular intervals can be unbounded at one or both ends, using null
as min and/or max value.
You can thus create an unbounded interval including all String
values for example using
TLcdDimensionInterval.create(String.class, null, null)
.
The union of such an unbounded interval with any other other interval will be the unbounded interval itself.
Modifier and Type | Class and Description |
---|---|
static class |
TLcdDimensionInterval.Closure
Denotes if a boundary of an interval is inclusive/exclusive.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(TLcdDimensionInterval<T> aInterval)
Compares the given dimension interval to this interval.
|
boolean |
contains(T aValue)
Returns whether or not the interval contains the given value.
|
static <T extends Comparable<? super T>> |
create(Class<T> aType,
T aMin,
T aMax)
Creates a
TLcdDimensionInterval instance using a min and
max value. |
static <T extends Comparable<? super T>> |
create(Class<T> aType,
T aMin,
TLcdDimensionInterval.Closure aClosureMin,
T aMax,
TLcdDimensionInterval.Closure aClosureMax)
Creates a
TLcdDimensionInterval instance using a min and
max value and closures. |
static <T extends Comparable<? super T>> |
createSingleValue(Class<T> aType,
T aValue)
Creates a
TLcdDimensionInterval instance that represents
a single value. |
boolean |
equals(Object aObject) |
TLcdDimensionInterval.Closure |
getClosureMax()
Returns the closure of the maximum value of this interval.
|
TLcdDimensionInterval.Closure |
getClosureMin()
Returns the closure of the minimum value of this interval.
|
T |
getMax()
Returns the maximum value of this interval.
|
T |
getMin()
Returns the minimum value of this interval.
|
Class<T> |
getType()
|
int |
hashCode() |
boolean |
isSingleValue()
Returns if this interval represents a single value.
|
static <T> boolean |
overlaps(TLcdDimensionInterval<T> aInterval1,
TLcdDimensionInterval<T> aInterval2)
Checks if the given intervals overlap, taking closure into account.
|
String |
toString() |
static <T> TLcdDimensionInterval<T> |
union(TLcdDimensionInterval<T> aInterval1,
TLcdDimensionInterval<T> aInterval2)
Returns the union of the given intervals.
|
public static <T extends Comparable<? super T>> TLcdDimensionInterval<T> createSingleValue(Class<T> aType, T aValue)
TLcdDimensionInterval
instance that represents
a single value. Its min and max value are equal and the
min and max closures are
CLOSED
.
null
is disallowed as a single value.aType
- the type of the value, which must not be null
.aValue
- the value, which must not be null
.public static <T extends Comparable<? super T>> TLcdDimensionInterval<T> create(Class<T> aType, T aMin, T aMax)
TLcdDimensionInterval
instance using a min and
max value. Its min and max closures are
CLOSED
.
The minimum must be less than or equal to the maximum.
When minimum and maximum are equal, the result will be a singular interval (single-valued).
The minimum and/or maximum may be null
to indicate unbounded.
Using null
for both min and max never represents a single-valued interval, it results in the
unbounded interval.aType
- the type of the min and max value, which must not be null
aMin
- the minimum value, which may be null
to indicate unbounded minaMax
- the maximum value, which may be null
to indicate unbounded maxpublic static <T extends Comparable<? super T>> TLcdDimensionInterval<T> create(Class<T> aType, T aMin, TLcdDimensionInterval.Closure aClosureMin, T aMax, TLcdDimensionInterval.Closure aClosureMax)
TLcdDimensionInterval
instance using a min and
max value and closures.
The minimum must be less than or equal to the maximum?
When minimum and maximum are equal, the result will be a singular interval (single-valued).
The minimum and/or maximum may be null
to indicate unbounded.
Using null
for both min and max never represents a single-valued interval, it results in the
unbounded interval.aType
- the type of the min and max value, which must not be null
.aMin
- the minimum value, which may be null
to indicate unbounded minaClosureMin
- the closure of the minimum value, which must not be null
aMax
- the maximum value, which may be null
to indicate unbounded maxaClosureMax
- the closure of the maximum value, which must not be null
public static <T> boolean overlaps(TLcdDimensionInterval<T> aInterval1, TLcdDimensionInterval<T> aInterval2)
null
, this method returns false
.
Both intervals must have the same type, otherwise an exception is thrown.
The type must be an extension of Comparable
, otherwise an exception is thrown.
Examples:
[1, 3]
overlaps with ]2, 4[
[1, 3]
overlaps with [3, 4[
[2]
overlaps with [2]
[1, 3]
does not overlap with ]3, 4]
because of the open closure of 3[Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY]
overlaps with [null, null]
[null, null
overlaps with any non-null intervalnull
does not overlap with anythingT
- the type must be an extension of Comparable
aInterval1
- an interval, which may be null
aInterval2
- another interval, which may be null
true
if and only if neither of the given intervals are null
and both overlap,
false
otherwiseIllegalArgumentException
- when both intervals have a different typeClassCastException
- when min or max cannot be cast to Comparable
public static <T> TLcdDimensionInterval<T> union(TLcdDimensionInterval<T> aInterval1, TLcdDimensionInterval<T> aInterval2)
IllegalArgumentException
when both intervals have a different type.
If one of the given intervals is null
, the other will be returned.
In case both given intervals are equal, either one may be returned.
The union of the unbounded interval will be the unbounded interval itself.T
- the type must be an extension of Comparable
aInterval1
- an interval, which may be null
aInterval2
- another interval, which may be null
IllegalArgumentException
- when both intervals have a different typeClassCastException
- when min or max cannot be cast to Comparable
public Class<T> getType()
public boolean isSingleValue()
public TLcdDimensionInterval.Closure getClosureMin()
CLOSED
, or excluded if the closure is
OPEN
.null
.public TLcdDimensionInterval.Closure getClosureMax()
CLOSED
, or excluded if the closure is
OPEN
.null
.public T getMin()
null
indicates an unbounded minimum.null
to indicate an unbounded min.public T getMax()
null
indicates an unbounded maximum.null
to indicate an unbounded max..public boolean contains(T aValue)
aValue
- the value to checkpublic int compareTo(TLcdDimensionInterval<T> aInterval)
Examples:
[0, 3[
< [1, 2]
[0, 3[
< ]0, 3]
[0, 3[
= [0, 3[
[null, 3]
< [Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY
.
compareTo
in interface Comparable<TLcdDimensionInterval<T>>
aInterval
- an other interval.