Class DoubleRange

  • All Implemented Interfaces:
    java.io.Serializable

    public final class DoubleRange
    extends NumberRange<java.lang.Double>
    Specializes NumberRange for Doubles.

    This class is not designed to interoperate with other NumberRanges

    Since:
    3.13.0
    See Also:
    Serialized Form
    • Constructor Detail

      • DoubleRange

        private DoubleRange​(java.lang.Double number1,
                            java.lang.Double number2)
        Creates an instance.
        Parameters:
        number1 - the first element, not null
        number2 - the second element, not null
        Throws:
        java.lang.NullPointerException - when element1 is null.
        java.lang.NullPointerException - when element2 is null.
    • Method Detail

      • of

        public static DoubleRange of​(double fromInclusive,
                                     double toInclusive)
        Creates a range with the specified minimum and maximum values (both inclusive).

        The range uses the natural ordering of the elements to determine where values lie in the range.

        The arguments may be passed in the order (min,max) or (max,min). The getMinimum and getMaximum methods will return the correct values.

        Parameters:
        fromInclusive - the first value that defines the edge of the range, inclusive.
        toInclusive - the second value that defines the edge of the range, inclusive.
        Returns:
        the range object, not null.
      • of

        public static DoubleRange of​(java.lang.Double fromInclusive,
                                     java.lang.Double toInclusive)
        Creates a range with the specified minimum and maximum values (both inclusive).

        The range uses the natural ordering of the elements to determine where values lie in the range.

        The arguments may be passed in the order (min,max) or (max,min). The getMinimum and getMaximum methods will return the correct values.

        Parameters:
        fromInclusive - the first value that defines the edge of the range, inclusive.
        toInclusive - the second value that defines the edge of the range, inclusive.
        Returns:
        the range object, not null.
        Throws:
        java.lang.IllegalArgumentException - if either element is null.
      • fit

        public double fit​(double element)
        Fits the given value into this range by returning the given value or, if out of bounds, the range minimum if below, or the range maximum if above.
        
         LongRange range = LongRange.of(16, 64);
         range.fit(-9) -->  16
         range.fit(0)  -->  16
         range.fit(15) -->  16
         range.fit(16) -->  16
         range.fit(17) -->  17
         ...
         range.fit(63) -->  63
         range.fit(64) -->  64
         range.fit(99) -->  64
         
        Parameters:
        element - the element to test.
        Returns:
        the minimum, the element, or the maximum depending on the element's location relative to the range.
        Since:
        3.19.0