Class DoubleRange

  • All Implemented Interfaces:
    Constraint<java.lang.Double>

    public final class DoubleRange
    extends java.lang.Object
    implements Constraint<java.lang.Double>
    A range of doubles. Like all ranges, it is immutable and its span always includes a minimum of one value.

    Construct using one of the static methods (inclusive(double, double), exclusive(double, double)),

    or by using from(double):

     DoubleRange.from(0.0).to(10.0)      // inclusive upper bound
     DoubleRange.from(0.0).until(10.0)   // exclusive upper bound
     
    • Method Detail

      • from

        public static DoubleRange.DoubleRangeFrom from​(double minInclusive)
        Partially constructs a DoubleRange with its lower bound.

        With the result, you can call to or until with the upper bound to create the DoubleRange.

        Parameters:
        minInclusive - the lower bound (inclusive) of the range
        Returns:
        a DoubleRange.DoubleRangeFrom
      • fromExclusive

        public static DoubleRange.DoubleRangeFrom fromExclusive​(double minExclusive)
        Partially constructs a DoubleRange with its lower bound.

        With the result, you can call to or until with the upper bound to create the DoubleRange.

        Parameters:
        minExclusive - the lower bound (exclusive) of the range
        Returns:
        a DoubleRange.DoubleRangeFrom
      • inclusive

        public static DoubleRange inclusive​(double minInclusive,
                                            double maxInclusive)
        Creates a DoubleRange from minInclusive..maxInclusive.
      • exclusive

        public static DoubleRange exclusive​(double minInclusive,
                                            double maxExclusive)
        Creates a DoubleRange from minInclusive..maxExclusive.
      • exclusive

        public static DoubleRange exclusive​(double maxExclusive)
        Creates a DoubleRange from 0..maxExclusive.
      • doubleRange

        public static DoubleRange doubleRange​(double min,
                                              boolean minIncluded,
                                              double max,
                                              boolean maxIncluded)
        Creates a DoubleRange.
      • min

        public double min()
      • max

        public double max()
      • minIncluded

        public boolean minIncluded()
      • maxIncluded

        public boolean maxIncluded()
      • includes

        public boolean includes​(java.lang.Double value)
        Description copied from interface: Constraint
        Tests if a value is included by this Constraint.
        Specified by:
        includes in interface Constraint<java.lang.Double>
        Parameters:
        value - the value
        Returns:
        a boolean
      • minInclusive

        public double minInclusive()
      • minExclusive

        public double minExclusive()
      • maxInclusive

        public double maxInclusive()
      • maxExclusive

        public double maxExclusive()
      • withMinInclusive

        public DoubleRange withMinInclusive​(double minInclusive)
        Creates a new DoubleRange that is the same as this one, with a new lower bound.
        Parameters:
        minInclusive - the new lower bound (inclusive) for the range; must not exceed this range's upper bound
        Returns:
        a DoubleRange
      • withMaxInclusive

        public DoubleRange withMaxInclusive​(double maxInclusive)
        Creates a new DoubleRange that is the same as this one, with a new upper bound.
        Parameters:
        maxInclusive - the new upper bound (inclusive) for the range; must not be less than this range's lower bound
        Returns:
        a DoubleRange
      • withMinExclusive

        public DoubleRange withMinExclusive​(double minExclusive)
        Creates a new DoubleRange that is the same as this one, with a new lower bound.
        Parameters:
        minExclusive - the new lower bound (exclusive) for the range; must be less than this range's upper bound
        Returns:
        a DoubleRange
      • withMaxExclusive

        public DoubleRange withMaxExclusive​(double maxExclusive)
        Creates a new DoubleRange that is the same as this one, with a new upper bound.
        Parameters:
        maxExclusive - the new upper bound (exclusive) for the range; must be greater than this range's lower bound
        Returns:
        a DoubleRange
      • 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
      • toString

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