Package com.luciad.multidimensional
Class TLcdDimensionInterval<T>
java.lang.Object
com.luciad.multidimensional.TLcdDimensionInterval<T>
- All Implemented Interfaces:
Comparable<TLcdDimensionInterval<T>>
public final class TLcdDimensionInterval<T>
extends Object
implements Comparable<TLcdDimensionInterval<T>>
This class represents an interval defined by a minimum and maximum value or a single value.
Intervals can be regular or singular (single-valued):
- Singular intervals have an equal min and max and neither is
null
. - Regular intervals have a min which is strictly less than max.
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.
- Since:
- 2015.0
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Denotes if a boundary of an interval is inclusive/exclusive. -
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(TLcdDimensionInterval<T> aInterval) Compares the given dimension interval to this interval.boolean
Returns whether or not the interval contains the given value.static <T extends Comparable<? super T>>
TLcdDimensionInterval<T> create
(Class<T> aType, T aMin, TLcdDimensionInterval.Closure aClosureMin, T aMax, TLcdDimensionInterval.Closure aClosureMax) Creates aTLcdDimensionInterval
instance using a min and max value and closures.static <T extends Comparable<? super T>>
TLcdDimensionInterval<T> Creates aTLcdDimensionInterval
instance using a min and max value.static <T extends Comparable<? super T>>
TLcdDimensionInterval<T> createSingleValue
(Class<T> aType, T aValue) Creates aTLcdDimensionInterval
instance that represents a single value.boolean
Returns the closure of the maximum value of this interval.Returns the closure of the minimum value of this interval.getMax()
Returns the maximum value of this interval.getMin()
Returns the minimum value of this interval.getType()
int
hashCode()
boolean
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.toString()
static <T> TLcdDimensionInterval
<T> union
(TLcdDimensionInterval<T> aInterval1, TLcdDimensionInterval<T> aInterval2) Returns the union of the given intervals.
-
Method Details
-
createSingleValue
public static <T extends Comparable<? super T>> TLcdDimensionInterval<T> createSingleValue(Class<T> aType, T aValue) Creates aTLcdDimensionInterval
instance that represents a single value. Its min and max value are equal and the min and max closures areCLOSED
.null
is disallowed as a single value.- Parameters:
aType
- the type of the value, which must not benull
.aValue
- the value, which must not benull
.- Returns:
- a dimension interval that represents a single value.
-
create
public static <T extends Comparable<? super T>> TLcdDimensionInterval<T> create(Class<T> aType, T aMin, T aMax) Creates aTLcdDimensionInterval
instance using a min and max value. Its min and max closures areCLOSED
. 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 benull
to indicate unbounded. Usingnull
for both min and max never represents a single-valued interval, it results in the unbounded interval.- Parameters:
aType
- the type of the min and max value, which must not benull
aMin
- the minimum value, which may benull
to indicate unbounded minaMax
- the maximum value, which may benull
to indicate unbounded max- Returns:
- a closed dimension interval.
-
create
public static <T extends Comparable<? super T>> TLcdDimensionInterval<T> create(Class<T> aType, T aMin, TLcdDimensionInterval.Closure aClosureMin, T aMax, TLcdDimensionInterval.Closure aClosureMax) Creates aTLcdDimensionInterval
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 benull
to indicate unbounded. Usingnull
for both min and max never represents a single-valued interval, it results in the unbounded interval.- Parameters:
aType
- the type of the min and max value, which must not benull
.aMin
- the minimum value, which may benull
to indicate unbounded minaClosureMin
- the closure of the minimum value, which must not benull
aMax
- the maximum value, which may benull
to indicate unbounded maxaClosureMax
- the closure of the maximum value, which must not benull
- Returns:
- a dimension interval using the given min/max values and closures.
-
overlaps
public static <T> boolean overlaps(TLcdDimensionInterval<T> aInterval1, TLcdDimensionInterval<T> aInterval2) Checks if the given intervals overlap, taking closure into account. If either of the given intervals isnull
, this method returnsfalse
. Both intervals must have the same type, otherwise an exception is thrown. The type must be an extension ofComparable
, 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 anything
- Type Parameters:
T
- the type must be an extension ofComparable
- Parameters:
aInterval1
- an interval, which may benull
aInterval2
- another interval, which may benull
- Returns:
true
if and only if neither of the given intervals arenull
and both overlap,false
otherwise- Throws:
IllegalArgumentException
- when both intervals have a different typeClassCastException
- when min or max cannot be cast toComparable
- Since:
- 2016.0
-
union
public static <T> TLcdDimensionInterval<T> union(TLcdDimensionInterval<T> aInterval1, TLcdDimensionInterval<T> aInterval2) Returns the union of the given intervals. This method throws anIllegalArgumentException
when both intervals have a different type. If one of the given intervals isnull
, 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.- Type Parameters:
T
- the type must be an extension ofComparable
- Parameters:
aInterval1
- an interval, which may benull
aInterval2
- another interval, which may benull
- Returns:
- the union of the given intervals.
- Throws:
IllegalArgumentException
- when both intervals have a different typeClassCastException
- when min or max cannot be cast toComparable
-
getType
- Returns:
- the type of the min and max values that define this interval.
-
isSingleValue
public boolean isSingleValue()Returns if this interval represents a single value. In that case, the min and max values that define this interval are equal.- Returns:
- if this interval represents a single value.
-
getClosureMin
Returns the closure of the minimum value of this interval. The minimum value can be included, if the closure isCLOSED
, or excluded if the closure isOPEN
.- Returns:
- the closure of the minimum value of this interval, never
null
.
-
getClosureMax
Returns the closure of the maximum value of this interval. The maximum value can be included, if the closure isCLOSED
, or excluded if the closure isOPEN
.- Returns:
- the closure of the maximum value of this interval, never
null
.
-
getMin
Returns the minimum value of this interval.null
indicates an unbounded minimum.- Returns:
- the minimum value of this interval, possibly
null
to indicate an unbounded min.
-
getMax
Returns the maximum value of this interval.null
indicates an unbounded maximum.- Returns:
- the maximum value of this interval, possibly
null
to indicate an unbounded max..
-
contains
Returns whether or not the interval contains the given value.- Parameters:
aValue
- the value to check- Returns:
- true if the interval includes the given value
- Since:
- 2021.0
-
equals
-
hashCode
public int hashCode() -
compareTo
Compares the given dimension interval to this interval. This implementation first compares the minimum value and its closure. If these are equal, it compares the maximum value and its closure.Examples:
[0, 3[
<[1, 2]
[0, 3[
<]0, 3]
[0, 3[
=[0, 3[
[null, 3]
<[Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY
.
- Specified by:
compareTo
in interfaceComparable<T>
- Parameters:
aInterval
- an other interval.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
-
toString
-