Class Range


  • public class Range
    extends Object
    A scale interval of the form "lower < x <= upper" where 0 <= lower < upper. (upper can be Double.POSITIVE_INFINITY) immutable class
    • Field Detail

      • lower

        private final double lower
      • upper

        private final double upper
      • ZERO_TO_INFINITY

        public static final Range ZERO_TO_INFINITY
        The full scale range from zero to infinity
    • Constructor Detail

      • Range

        public Range​(double lower,
                     double upper)
        Constructs a new Range.
        Parameters:
        lower - Lower bound. Must be positive or zero
        upper - Upper bound
        Throws:
        IllegalArgumentException - if the range is invalid (lower < 0 || lower >= upper)
    • Method Detail

      • contains

        public boolean contains​(double x)
        Check if a number is contained in this range
        Parameters:
        x - The number to test
        Returns:
        true if it is in this range
      • cut

        public static Range cut​(Range a,
                                Range b)
        provides the intersection of 2 overlapping ranges
        Parameters:
        a - first range
        b - second range
        Returns:
        intersection of a and b
      • reduceAround

        public Range reduceAround​(double x,
                                  Range other)
        under the premise, that x is within this range, and not within the other range, it shrinks this range in a way to exclude the other range, but still contain x. x | this (------------------------------] other (-------] or (-----------------] result (----------------]
        Parameters:
        x - value
        other - other range
        Returns:
        reduced range
      • getLower

        public double getLower()
        Gets the lower bound
        Returns:
        The lower, exclusive, bound
      • getUpper

        public double getUpper()
        Gets the upper bound
        Returns:
        The upper, inclusive, bound