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
  • Method Details

    • createSingleValue

      public static <T extends Comparable<? super T>> TLcdDimensionInterval<T> createSingleValue(Class<T> aType, T aValue)
      Creates a 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.
      Parameters:
      aType - the type of the value, which must not be null.
      aValue - the value, which must not be null.
      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 a 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.
      Parameters:
      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 min
      aMax - the maximum value, which may be null 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 a 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.
      Parameters:
      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 min
      aClosureMin - the closure of the minimum value, which must not be null
      aMax - the maximum value, which may be null to indicate unbounded max
      aClosureMax - the closure of the maximum value, which must not be null
      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 is 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 interval
      • null does not overlap with anything

      Type Parameters:
      T - the type must be an extension of Comparable
      Parameters:
      aInterval1 - an interval, which may be null
      aInterval2 - another interval, which may be null
      Returns:
      true if and only if neither of the given intervals are null and both overlap, false otherwise
      Throws:
      IllegalArgumentException - when both intervals have a different type
      ClassCastException - when min or max cannot be cast to Comparable
      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 an 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.
      Type Parameters:
      T - the type must be an extension of Comparable
      Parameters:
      aInterval1 - an interval, which may be null
      aInterval2 - another interval, which may be null
      Returns:
      the union of the given intervals.
      Throws:
      IllegalArgumentException - when both intervals have a different type
      ClassCastException - when min or max cannot be cast to Comparable
    • getType

      public Class<T> getType()
      Returns the type of the min and max values that define this interval.
      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

      public TLcdDimensionInterval.Closure getClosureMin()
      Returns the closure of the minimum value of this interval. The minimum value can be included, if the closure is CLOSED, or excluded if the closure is OPEN.
      Returns:
      the closure of the minimum value of this interval, never null.
    • getClosureMax

      public TLcdDimensionInterval.Closure getClosureMax()
      Returns the closure of the maximum value of this interval. The maximum value can be included, if the closure is CLOSED, or excluded if the closure is OPEN.
      Returns:
      the closure of the maximum value of this interval, never null.
    • getMin

      public T 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

      public T 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

      public boolean contains(T aValue)
      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

      public boolean equals(Object aObject)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(TLcdDimensionInterval<T> aInterval)
      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 interface Comparable<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

      public String toString()
      Overrides:
      toString in class Object