Class CombinedNumericRange

  • All Implemented Interfaces:
    Range<java.lang.Double>, java.lang.Comparable<Range>

    public class CombinedNumericRange
    extends AbstractNumericRange<java.lang.Double>
    A little convenience class to compute the maximum and minimum values of multiple ranges.
    Author:
    swhite@catalysoft.com
    • Constructor Detail

      • CombinedNumericRange

        public CombinedNumericRange()
        Using this constructor relies on the user subsequently calling add() to add a range
    • Method Detail

      • add

        public CombinedNumericRange add​(Range<java.lang.Double> range)
        Add a new range to this combined range. Notice the method returns this instance, so method calls can be chained together. If you pass null to this method the CombinedNumericRange remains unchanged; an Exception is NOT thrown.
        Parameters:
        range - the new range to add
        Returns:
        this instance
      • lower

        public java.lang.Double lower()
        The lower value in the range; here, the same as minimum
        Returns:
        the smallest value of the range
      • upper

        public java.lang.Double upper()
        The upper value in the range; here, the same as maximum()
        Returns:
        the largest value of the range
      • rangeCount

        public int rangeCount()
        Returns the number of sub-ranges contained by this range
        Returns:
        the number of sub-ranges in this range
      • adjust

        public void adjust​(java.lang.Double lower,
                           java.lang.Double upper)
        Calls to this method throw an UnsupportedOprationException. The idea is that in the case of this class we don't want to be able to mess with the lower and upper bounds as they are computed from the supplied range values. If the class needed to recompute the lower and upper bounds any previous adjustment that had been made through this method would have been lost.
        Parameters:
        lower - the new smallest value of the range
        upper - the new largest value of the range
        Throws:
        java.lang.UnsupportedOperationException
      • maximum

        public double maximum()
        Lazily calculates the maximum value in the range
        Returns:
        The numeric value of the largest value to include in the range.
      • minimum

        public double minimum()
        Lazily calculates the minimum value in the range
        Returns:
        the numeric value of the smallest value to include in the range.
      • contains

        public boolean contains​(java.lang.Double x)
        This range contains some point iff one or more of its sub-ranges contain that point
        Returns:
        a boolean to indicate whether the supplied point lies within the range
      • size

        public double size()
        The size of the range is computed as the maximum minus the minimum value.
      • getRange

        public NumericRange getRange​(double leadingMarginProportion,
                                     double trailingMarginProportion)
        Returns a new numeric range that is based on this range, but with a margin introduced at each end. The margin proportion is a value between 0 and 1. For example to add a 20% margin to each end use parameters of 0.2 for both the leading and trailing margin proportion.
        Parameters:
        leadingMarginProportion - how much margin to add at the low end of the range
        trailingMarginProportion - how much margin to add at the top end of the range
        Returns:
        a new NumericRange object with margins added
      • createIntermediate

        public Range<java.lang.Double> createIntermediate​(Range<java.lang.Double> targetRange,
                                                          double position)
        Specified by:
        createIntermediate in class AbstractRange<java.lang.Double>
      • toString

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