Class NumberRange<T extends Number & Comparable<? super T>>

    • Constructor Detail

      • NumberRange

        public NumberRange​(Class<T> type,
                           T minimum,
                           T maximum)
        Constructs an inclusive range of Number objects.
        Parameters:
        type - The element class, usually one of Byte, Short, Integer, Long, Float or Double.
        minimum - The minimum value, inclusive.
        maximum - The maximum value, inclusive.
      • NumberRange

        public NumberRange​(Class<T> type,
                           T minimum,
                           boolean isMinIncluded,
                           T maximum,
                           boolean isMaxIncluded)
        Constructs a range of Number objects.
        Parameters:
        type - The element class, usually one of Byte, Short, Integer, Long, Float or Double.
        minimum - The minimum value.
        isMinIncluded - Defines whether the minimum value is included in the range.
        maximum - The maximum value.
        isMaxIncluded - Defines whether the maximum value is included in the range.
      • NumberRange

        public NumberRange​(Range<T> range)
        Constructs a range with the same type and the same values than the specified range. This is a copy constructor.
        Parameters:
        range - The range to copy. The elements must be Number instances.
        Since:
        2.4
    • Method Detail

      • create

        public static NumberRange<Byte> create​(byte minimum,
                                               byte maximum)
        Constructs an inclusive range of byte values.
        Parameters:
        minimum - The minimum value, inclusive.
        maximum - The maximum value, inclusive.
        Since:
        2.5
      • create

        public static NumberRange<Byte> create​(byte minimum,
                                               boolean isMinIncluded,
                                               byte maximum,
                                               boolean isMaxIncluded)
        Constructs a range of byte values.
        Parameters:
        minimum - The minimum value.
        isMinIncluded - Defines whether the minimum value is included in the range.
        maximum - The maximum value.
        isMaxIncluded - Defines whether the maximum value is included in the range.
        Since:
        2.5
      • create

        public static NumberRange<Short> create​(short minimum,
                                                short maximum)
        Constructs an inclusive range of short values.
        Parameters:
        minimum - The minimum value, inclusive.
        maximum - The maximum value, inclusive.
        Since:
        2.5
      • create

        public static NumberRange<Short> create​(short minimum,
                                                boolean isMinIncluded,
                                                short maximum,
                                                boolean isMaxIncluded)
        Constructs a range of short values.
        Parameters:
        minimum - The minimum value.
        isMinIncluded - Defines whether the minimum value is included in the range.
        maximum - The maximum value.
        isMaxIncluded - Defines whether the maximum value is included in the range.
        Since:
        2.5
      • create

        public static NumberRange<Integer> create​(int minimum,
                                                  int maximum)
        Constructs an inclusive range of int values.
        Parameters:
        minimum - The minimum value, inclusive.
        maximum - The maximum value, inclusive.
        Since:
        2.5
      • create

        public static NumberRange<Integer> create​(int minimum,
                                                  boolean isMinIncluded,
                                                  int maximum,
                                                  boolean isMaxIncluded)
        Constructs a range of int values.
        Parameters:
        minimum - The minimum value.
        isMinIncluded - Defines whether the minimum value is included in the range.
        maximum - The maximum value.
        isMaxIncluded - Defines whether the maximum value is included in the range.
        Since:
        2.5
      • create

        public static NumberRange<Long> create​(long minimum,
                                               long maximum)
        Constructs an inclusive range of long values.
        Parameters:
        minimum - The minimum value, inclusive.
        maximum - The maximum value, inclusive.
        Since:
        2.5
      • create

        public static NumberRange<Long> create​(long minimum,
                                               boolean isMinIncluded,
                                               long maximum,
                                               boolean isMaxIncluded)
        Constructs a range of long values.
        Parameters:
        minimum - The minimum value.
        isMinIncluded - Defines whether the minimum value is included in the range.
        maximum - The maximum value.
        isMaxIncluded - Defines whether the maximum value is included in the range.
        Since:
        2.5
      • create

        public static NumberRange<Float> create​(float minimum,
                                                float maximum)
        Constructs an inclusive range of float values.
        Parameters:
        minimum - The minimum value, inclusive.
        maximum - The maximum value, inclusive.
        Since:
        2.5
      • create

        public static NumberRange<Float> create​(float minimum,
                                                boolean isMinIncluded,
                                                float maximum,
                                                boolean isMaxIncluded)
        Constructs a range of float values.
        Parameters:
        minimum - The minimum value.
        isMinIncluded - Defines whether the minimum value is included in the range.
        maximum - The maximum value.
        isMaxIncluded - Defines whether the maximum value is included in the range.
        Since:
        2.5
      • create

        public static NumberRange<Double> create​(double minimum,
                                                 double maximum)
        Constructs an inclusive range of double values.
        Parameters:
        minimum - The minimum value, inclusive.
        maximum - The maximum value, inclusive.
        Since:
        2.5
      • create

        public static NumberRange<Double> create​(double minimum,
                                                 boolean isMinIncluded,
                                                 double maximum,
                                                 boolean isMaxIncluded)
        Constructs a range of double values.
        Parameters:
        minimum - The minimum value.
        isMinIncluded - Defines whether the minimum value is included in the range.
        maximum - The maximum value.
        isMaxIncluded - Defines whether the maximum value is included in the range.
        Since:
        2.5
      • wrap

        public static <N extends Number & Comparable<? super N>> NumberRange<N> wrap​(Range<N> range)
        Wraps the specified Range in a NumberRange object. If the specified range is already an instance of NumberRange, then it is returned unchanged.
        Type Parameters:
        N - The type of elements in the given range.
        Parameters:
        range - The range to wrap.
        Returns:
        The same range than range as a NumberRange object.
      • contains

        public boolean contains​(Number value)
                         throws IllegalArgumentException
        Returns true if the specified value is within this range.
        Parameters:
        value - The value to check for inclusion.
        Returns:
        true if the given value is withing this range.
        Throws:
        IllegalArgumentException - if the given value is not comparable.
      • contains

        public boolean contains​(Range<?> range)
        Returns true if the supplied range is fully contained within this range.
        Overrides:
        contains in class Range<T extends Number & Comparable<? super T>>
        Parameters:
        range - The range to check for inclusion in this range.
        Returns:
        true if the given range is included in this range.
      • intersects

        public boolean intersects​(Range<?> range)
        Returns true if this range intersects the given range.
        Overrides:
        intersects in class Range<T extends Number & Comparable<? super T>>
        Parameters:
        range - The range to check for intersection with this range.
        Returns:
        true if the given range intersects this range.
        See Also:
        Range.intersects(javax.media.jai.util.Range)
      • union

        public NumberRange<?> union​(Range<?> range)
        Returns the union of this range with the given range. Widening conversions will be applied as needed.
        Overrides:
        union in class Range<T extends Number & Comparable<? super T>>
        Parameters:
        range - The range to add to this range.
        Returns:
        The union of this range with the given range.
        See Also:
        Range.union(javax.media.jai.util.Range)
      • intersect

        public NumberRange<?> intersect​(Range<?> range)
        Returns the intersection of this range with the given range. Widening conversions will be applied as needed.
        Overrides:
        intersect in class Range<T extends Number & Comparable<? super T>>
        Parameters:
        range - The range to intersect.
        Returns:
        The intersection of this range with the provided range.
        See Also:
        Range.intersect(javax.media.jai.util.Range)
      • subtract

        public NumberRange<?>[] subtract​(Range<?> range)
        Returns the range of values that are in this range but not in the given range.
        Overrides:
        subtract in class Range<T extends Number & Comparable<? super T>>
        Parameters:
        range - The range to substract.
        Returns:
        This range without the given range.
        See Also:
        Range.subtract(javax.media.jai.util.Range)
      • getMinimum

        public double getMinimum​(boolean inclusive)
        Returns the minimum value with the specified inclusive or exclusive state. If this range is unbounded, then Double.NEGATIVE_INFINITY is returned.
        Parameters:
        inclusive - true for the minimum value inclusive, or false for the minimum value exclusive.
        Returns:
        The minimum value, inclusive or exclusive as requested.
      • getMaximum

        public double getMaximum​(boolean inclusive)
        Returns the maximum value with the specified inclusive or exclusive state. If this range is unbounded, then Double.POSITIVE_INFINITY is returned.
        Parameters:
        inclusive - true for the maximum value inclusive, or false for the maximum value exclusive.
        Returns:
        The maximum value, inclusive or exclusive as requested.