Interface Range<V extends Comparable<?>>

Type Parameters:
V - type of the contained values.
All Known Subinterfaces:
WritableRange<V>
All Known Implementing Classes:
AbstractRange, NumberRangeType, RangeType

public interface Range<V extends Comparable<?>>
This class represents a range from minimum to maximum. Implementations shall validate at construction so a given Range should always be valid.
ATTENTION:
The minimum and maximum may be null for unbounded ranges. It is still recommended to use fixed bounds such as Long.MAX_VALUE. However, for types such as BigDecimal this is not possible.
Since:
1.0.0
  • Field Details

    • BOUND_START_INCLUSIVE

      static final char BOUND_START_INCLUSIVE
      Char indicating start with inclusive minimum.
      See Also:
    • BOUND_START_EXCLUSIVE

      static final char BOUND_START_EXCLUSIVE
      Char indicating start with exclusive minimum.
      See Also:
    • BOUND_END_INCLUSIVE

      static final char BOUND_END_INCLUSIVE
      Char indicating end with inclusive maximum.
      See Also:
    • BOUND_END_EXCLUSIVE

      static final char BOUND_END_EXCLUSIVE
      Char indicating end with exclusive maximum.
      See Also:
    • BOUND_SEPARATOR

      static final char BOUND_SEPARATOR
      Char to separate minimum and maximum. Mathematical convention would be to use a comma (','), but this causes problems when parsing string representations as a comma may also occur in the minimum or maximum value.
      See Also:
    • MIN_UNBOUND

      static final String MIN_UNBOUND
      The unbound minimum.
      See Also:
    • MAX_UNBOUND

      static final String MAX_UNBOUND
      The unbound maximum.
      See Also:
    • PROPERTY_MIN

      static final String PROPERTY_MIN
      Property name of getMin().
      See Also:
    • PROPERTY_MAX

      static final String PROPERTY_MAX
      Property name of getMax().
      See Also:
  • Method Details

    • getMin

      V getMin()
      Returns:
      the lower bound of this range or null if no lower bound is defined. Has to be less than max if both boundaries are not null.
    • getMax

      V getMax()
      Returns:
      the upper bound of this range or null if no upper bound is defined. Has to be greater than min if both boundaries are not null.
    • getComparator

      default Comparator<? super V> getComparator()
      Returns:
      the Comparator used to compare values of this Range. The default implementation assumes that the value type implements Comparable. If you want to use other value types you need to override this method.
    • contains

      default boolean contains(V value)
      This method determines if the given value is within this Range from minimum to maximum.
      Parameters:
      value - is the vale to check.
      Returns:
      true if contained (minimum <= value >= maximum), false otherwise. If the given value is null, false will be returned.
    • clip

      default V clip(V value)
      This method clips the given value so the result is contained in this Range unless the given value is null.
      Parameters:
      value - is the vale to clip. May be null.
      Returns:
      the given value clipped to this range. If the given value is less than the minimum, that minimum will be returned. If the given value is greater than the maximum, that maximum will be returned. Otherwise the given value is returned.
    • withMin

      Range<V> withMin(V minimum)
      Parameters:
      minimum - the new minimum.
      Returns:
      a new RangeType where the minimum is set to the given minimum value.
    • withMax

      Range<V> withMax(V maximum)
      Parameters:
      maximum - the new maximum.
      Returns:
      a new RangeType where the maximum is set to the given maximum value.
    • intersection

      Range<V> intersection(Range<V> range)
      Parameters:
      range - the Range to build the intersection with.
      Returns:
      the intersection of this Range with the given Range that is a Range with the highest minimum and the lowest maximum of the two ranges to intersect. In case the Ranges the intersection of
    • isUnbounded

      default boolean isUnbounded()
      Returns:
      true if this Range is unbounded.
    • of

      static <T extends Comparable<?>> Range<T> of(T min, T max)
      Type Parameters:
      T - type of the contained value.
      Parameters:
      min - the minimum.
      max - the maximum.
      Returns:
      the specified Range.
    • unbounded

      static <T extends Comparable<?>> Range<T> unbounded()
      Type Parameters:
      T - type of the contained value.
      Returns:
      the unbounded Range instance containing all values (with getMin() and getMax() being null).
    • invalid

      static <T extends Comparable<?>> Range<T> invalid()
      Type Parameters:
      T - type of the contained value.
      Returns:
      the invalid Range instance containing no values at all (with getMin() and getMax() being null).