Class DoubleRangeUtil


  • public final class DoubleRangeUtil
    extends Object
    Utility class for checking invariants on double-values.
    Since:
    1.0.3
    Author:
    Emil Forslund
    • Method Detail

      • requirePositive

        public static double requirePositive​(double val)
        Returns the given value if it is positive (greater than 0).
        Parameters:
        val - to check
        Returns:
        the given value
        Throws:
        IllegalArgumentException - if the given value is not positive
      • requireNegative

        public static double requireNegative​(double val)
        Returns the given value if it is negative (less than 0).
        Parameters:
        val - to check
        Returns:
        the given value
        Throws:
        IllegalArgumentException - if the given value is not negative
      • requireZero

        public static double requireZero​(double val)
        Returns the given value if it is equal to 0.
        Parameters:
        val - to check
        Returns:
        the given value
        Throws:
        IllegalArgumentException - if the given value is not 0
      • requireNonPositive

        public static double requireNonPositive​(double val)
        Returns the given value if it is not positive (less than or equal to 0).
        Parameters:
        val - to check
        Returns:
        the given value
        Throws:
        IllegalArgumentException - if the given value is positive
      • requireNonNegative

        public static double requireNonNegative​(double val)
        Returns the given value if it is not negative (greater than or equal to 0).
        Parameters:
        val - to check
        Returns:
        the given value
        Throws:
        IllegalArgumentException - if the given value is negative
      • requireNonZero

        public static double requireNonZero​(double val)
        Returns the given value if it is not 0.
        Parameters:
        val - to check
        Returns:
        the given value
        Throws:
        IllegalArgumentException - if the given value is zero
      • requireEquals

        public static double requireEquals​(double val,
                                           double otherVal)
      • requireNotEquals

        public static double requireNotEquals​(double val,
                                              double otherVal)
      • requireInRange

        public static double requireInRange​(double val,
                                            double first,
                                            double lastExclusive)
      • requireInRangeClosed

        public static double requireInRangeClosed​(double val,
                                                  double first,
                                                  double lastInclusive)
      • requirePositive

        public static <E extends RuntimeException> double requirePositive​(double val,
                                                                          Function<String,​E> exceptionConstructor)
        Returns the given value if it is positive.
        Type Parameters:
        E - RuntimeException type
        Parameters:
        val - to check
        exceptionConstructor - to use when throwing exception
        Returns:
        the given value
        Throws:
        RuntimeException - if the given value is not positive
      • requireNonPositive

        public static <E extends RuntimeException> double requireNonPositive​(double val,
                                                                             Function<String,​E> exceptionConstructor)
      • requireNonNegative

        public static <E extends RuntimeException> double requireNonNegative​(double val,
                                                                             Function<String,​E> exceptionConstructor)
      • requireEquals

        public static <E extends RuntimeException> double requireEquals​(double val,
                                                                        double otherVal,
                                                                        Function<String,​E> exceptionConstructor)
      • requireNotEquals

        public static <E extends RuntimeException> double requireNotEquals​(double val,
                                                                           double otherVal,
                                                                           Function<String,​E> exceptionConstructor)
      • requireInRange

        public static <E extends RuntimeException> double requireInRange​(double val,
                                                                         double first,
                                                                         double lastExclusive,
                                                                         Function<String,​E> exceptionConstructor)
      • requireInRangeClosed

        public static <E extends RuntimeException> double requireInRangeClosed​(double val,
                                                                               double first,
                                                                               double lastInclusive,
                                                                               Function<String,​E> exceptionConstructor)