Class Range


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

      Fields 
      Modifier and Type Field Description
      private double lower  
      private double upper  
      static Range ZERO_TO_INFINITY
      The full scale range from zero to infinity
    • Constructor Summary

      Constructors 
      Constructor Description
      Range​(double lower, double upper)
      Constructs a new Range.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(double x)
      Check if a number is contained in this range
      static Range cut​(Range a, Range b)
      provides the intersection of 2 overlapping ranges
      boolean equals​(java.lang.Object o)  
      double getLower()
      Gets the lower bound
      double getUpper()
      Gets the upper bound
      int hashCode()  
      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.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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:
        java.lang.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
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object