Class Checker


  • public final class Checker
    extends Object
    Utility which provides a set o methods to check the values of numbers.
    Author:
    Andrea "Stock" Stocchero
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void assertCheck​(boolean value)
      Checks if the value passed as argument is true.
      If not, throw a IllegalArgumentException.
      static void assertCheck​(boolean value, String what)
      Checks if the value passed as argument is true.
      If not, throw a IllegalArgumentException.
      static double betweenOrDefault​(double value, double minimum, double maximum, double defaultValue)
      Checks if the value is between minimum and maximum passed values and returns it.
      static int betweenOrDefault​(int value, int minimum, int maximum, int defaultValue)
      Checks if the value is between minimum and maximum passed values and returns it.
      static double betweenOrMaximum​(double value, double minimum, double maximum)
      Checks if the value is between minimum and maximum passed values and returns it.
      static int betweenOrMaximum​(int value, int minimum, int maximum)
      Checks if the value is between minimum and maximum passed values and returns it.
      static double betweenOrMinimum​(double value, double minimum, double maximum)
      Checks if the value is between minimum and maximum passed values and returns it.
      static int betweenOrMinimum​(int value, int minimum, int maximum)
      Checks if the value is between minimum and maximum passed values and returns it.
      static double checkAndGetIfBetween​(double value, double minimum, double maximum, String what)
      Checks if the value passed as argument is between minimum and maximum values, passed as argument (inclusive).
      If not, throw a IllegalArgumentException.
      static int checkAndGetIfBetween​(int value, int minimum, int maximum, String what)
      Checks if the value passed as argument is between minimum and maximum values, passed as argument (inclusive).
      If not, throw a IllegalArgumentException.
      static double checkAndGetIfGreaterThan​(double value, double threshold, String what)
      Checks if the value passed as argument is greater than the threshold passed as argument (inclusive).
      If not, throw a IllegalArgumentException.
      static int checkAndGetIfGreaterThan​(int value, int threshold, String what)
      Checks if the value passed as argument is greater than the threshold passed as argument (inclusive).
      If not, throw a IllegalArgumentException.
      static double checkAndGetIfLessThan​(double value, double threshold, String what)
      Checks if the value passed as argument is less than the threshold passed as argument (inclusive).
      If not, throw a IllegalArgumentException.
      static int checkAndGetIfLessThan​(int value, int threshold, String what)
      Checks if the value passed as argument is less than the threshold passed as argument (inclusive).
      If not, throw a IllegalArgumentException.
      static double checkAndGetIfNegative​(double value, String what)
      Checks if value passed as argument is a negative number (zero is excluded).
      If not, throw a IllegalArgumentException.
      static int checkAndGetIfNegative​(int value, String what)
      Checks if value passed as argument is a negative number (zero is excluded).
      If not, throw a IllegalArgumentException.
      static double checkAndGetIfPositive​(double value, String what)
      Checks if value passed as argument is a positive number (zero is included).
      If not, throw a IllegalArgumentException.
      static int checkAndGetIfPositive​(int value, String what)
      Checks if value passed as argument is a positive number (zero is included).
      If not, throw a IllegalArgumentException.
      static double checkAndGetIfValid​(double value, String what)
      Checks if value passed as argument is valid and, if valid, returns the argument.
      If not, throw a IllegalArgumentException.
      static int checkAndGetIfValid​(int value, String what)
      Checks if value passed as argument is valid and, if valid, returns the argument.
      If not, throw a IllegalArgumentException.
      static <T> T checkAndGetIfValid​(T value, String what)
      Checks if value passed as argument is valid and, if valid, returns the argument.
      If not, throw a IllegalArgumentException.
      static void checkIfBetween​(double value, double minimum, double maximum, String what)
      Checks if the value passed as argument is between minimum and maximum values, passed as argument (inclusive).
      If not, throw a IllegalArgumentException.
      static void checkIfBetween​(int value, int minimum, int maximum, String what)
      Checks if the value passed as argument is between minimum and maximum values, passed as argument (inclusive).
      If not, throw a IllegalArgumentException.
      static void checkIfEqualTo​(double value, double target, String what)
      Checks if both values passed as argument are equals.
      If not, throw a IllegalArgumentException.
      static void checkIfEqualTo​(int value, int target, String what)
      Checks if both values passed as argument are equals.
      If not, throw a IllegalArgumentException.
      static void checkIfGreaterThan​(double value, double threshold, String what)
      Checks if the value passed as argument is greater than the threshold passed as argument (inclusive).
      If not, throw a IllegalArgumentException.
      static void checkIfGreaterThan​(int value, int threshold, String what)
      Checks if the value passed as argument is greater than the threshold passed as argument (inclusive).
      If not, throw a IllegalArgumentException.
      static void checkIfLessThan​(double value, double threshold, String what)
      Checks if the value passed as argument is less than the threshold passed as argument (inclusive).
      If not, throw a IllegalArgumentException.
      static void checkIfLessThan​(int value, int threshold, String what)
      Checks if the value passed as argument is less than the threshold passed as argument (inclusive).
      If not, throw a IllegalArgumentException.
      static void checkIfNegative​(double value, String what)
      Checks if value passed as argument is a negative number (zero is excluded).
      If not, throw a IllegalArgumentException.
      static void checkIfNegative​(int value, String what)
      Checks if value passed as argument is a negative number (zero is excluded).
      If not, throw a IllegalArgumentException.
      static void checkIfNotEqualTo​(double value, double target, String what)
      Checks if both values passed as argument are not equals.
      If not, throw a IllegalArgumentException.
      static void checkIfNotEqualTo​(int value, int target, String what)
      Checks if both values passed as argument are not equals.
      If not, throw a IllegalArgumentException.
      static void checkIfPositive​(double value, String what)
      Checks if value passed as argument is a positive number (zero is included).
      If not, throw a IllegalArgumentException.
      static void checkIfPositive​(int value, String what)
      Checks if value passed as argument is a positive number (zero is included).
      If not, throw a IllegalArgumentException.
      static void checkIfValid​(double value, String what)
      Checks if value passed as argument is valid.
      If not, throw a IllegalArgumentException.
      static void checkIfValid​(int value, String what)
      Checks if value passed as argument is valid.
      If not, throw a IllegalArgumentException.
      static void checkIfValid​(Object value, String what)
      Checks if value passed as argument is valid.
      If not, throw a IllegalArgumentException.
      static double greaterThanOrDefault​(double value, double threshold, double defaultValue)
      Checks if the value is greater than number and returns it.
      static int greaterThanOrDefault​(int value, int threshold, int defaultValue)
      Checks if the value is greater than number and returns it.
      static double greaterThanOrThreshold​(double value, double threshold)
      Checks if the value is greater than number and returns it.
      static int greaterThanOrThreshold​(int value, int threshold)
      Checks if the value is greater than number and returns it.
      static double greaterThanOrZero​(double value, double threshold)
      Checks if the value is greater than number and returns it.
      static int greaterThanOrZero​(int value, int threshold)
      Checks if the value is greater than number and returns it.
      static boolean isBetween​(double value, double minimum, double maximum)
      Checks if the value passed as argument is between minimum and maximum values, passed as argument (inclusive).
      static boolean isBetween​(int value, int minimum, int maximum)
      Checks if the value passed as argument is between minimum and maximum values, passed as argument (inclusive).
      static boolean isEqualTo​(double value, double target)
      Checks if both values passed as argument are equals.
      static boolean isEqualTo​(int value, int target)
      Checks if both values passed as argument are equals.
      static boolean isGreaterThan​(double value, double threshold)
      Checks if the value passed as argument is greater than the threshold passed as argument (inclusive).
      static boolean isGreaterThan​(int value, int threshold)
      Checks if the value passed as argument is greater than the threshold passed as argument (inclusive).
      static boolean isLessThan​(double value, double threshold)
      Checks if the value passed as argument is less than the threshold passed as argument (inclusive).
      static boolean isLessThan​(int value, int threshold)
      Checks if the value passed as argument is less than the threshold passed as argument (inclusive).
      static boolean isNegative​(double value)
      Checks if value passed as argument is a negative number (zero is excluded).
      static boolean isNegative​(int value)
      Checks if value passed as argument is a negative number (zero is excluded).
      static boolean isNotEqualTo​(double value, double target)
      Checks if both values passed as argument are not equals.
      static boolean isNotEqualTo​(int value, int target)
      Checks if both values passed as argument are not equals.
      static boolean isPositive​(double value)
      Checks if value passed as argument is a positive number (zero is included).
      static boolean isPositive​(int value)
      Checks if value passed as argument is a positive number (zero is included).
      static double lessThanOrDefault​(double value, double threshold, double defaultValue)
      Checks if the value is less than number and returns it.
      static int lessThanOrDefault​(int value, int threshold, int defaultValue)
      Checks if the value is less than number and returns it.
      static double lessThanOrThreshold​(double value, double threshold)
      Checks if the value is less than number and returns it.
      static int lessThanOrThreshold​(int value, int threshold)
      Checks if the value is less than number and returns it.
      static double lessThanOrZero​(double value, double threshold)
      Checks if the value is less than number and returns it.
      static int lessThanOrZero​(int value, int threshold)
      Checks if the value is less than number and returns it.
      static double negativeOrDefault​(double value, double defaultValue)
      Checks if the value is a negative number and returns it.
      static int negativeOrDefault​(int value, int defaultValue)
      Checks if the value is a negative number and returns it.
      static double negativeOrZero​(double value)
      Checks if the value is a negative number and returns it.
      static int negativeOrZero​(int value)
      Checks if the value is a negative number and returns it.
      static double positiveOrDefault​(double value, double defaultValue)
      Checks if the value is a positive number and returns it.
      static int positiveOrDefault​(int value, int defaultValue)
      Checks if the value is a positive number and returns it.
      static double positiveOrZero​(double value)
      Checks if the value is a positive number and returns it.
      static int positiveOrZero​(int value)
      Checks if the value is a positive number and returns it.
      static double validOrDefault​(double value, double defaultValue)
      Checks if the value is a consistent number and returns it.
      static int validOrDefault​(int value, int defaultValue)
      Checks if the value is a consistent number and returns it.
      static <T> T validOrDefault​(T value, T defaultValue)
      Checks if the value is a consistent object and returns it.
      static double validOrZero​(double value)
      Checks if the value is a consistent number and returns it.
      static int validOrZero​(int value)
      Checks if the value is a consistent number and returns it.
    • Method Detail

      • assertCheck

        public static void assertCheck​(boolean value)
        Checks if the value passed as argument is true.
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
      • assertCheck

        public static void assertCheck​(boolean value,
                                       String what)
        Checks if the value passed as argument is true.
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        what - name of the value to put in the exception message
      • validOrZero

        public static int validOrZero​(int value)
        Checks if the value is a consistent number and returns it. If not a consistent number, returns 0.
        Parameters:
        value - value to be checked
        Returns:
        the value passed as argument if is a consistent number or 0.
      • validOrDefault

        public static int validOrDefault​(int value,
                                         int defaultValue)
        Checks if the value is a consistent number and returns it. If not a consistent number, returns the default.
        Parameters:
        value - value to be checked
        defaultValue - value to return if the value is not a consistent number
        Returns:
        the value passed as argument if is a consistent number or the default.
      • positiveOrZero

        public static int positiveOrZero​(int value)
        Checks if the value is a positive number and returns it. If not a positive number, returns 0.
        Parameters:
        value - value to be checked
        Returns:
        the value passed as argument if is a positive number or 0.
      • positiveOrDefault

        public static int positiveOrDefault​(int value,
                                            int defaultValue)
        Checks if the value is a positive number and returns it. If not a positive number, returns the default.
        Parameters:
        value - value to be checked
        defaultValue - value to return if the value is not a positive number
        Returns:
        the value passed as argument if is a positive number or the default.
      • negativeOrZero

        public static int negativeOrZero​(int value)
        Checks if the value is a negative number and returns it. If not a negative number, returns 0.
        Parameters:
        value - value to be checked
        Returns:
        the value passed as argument if is a negative number or 0.
      • negativeOrDefault

        public static int negativeOrDefault​(int value,
                                            int defaultValue)
        Checks if the value is a negative number and returns it. If not a negative number, returns the default.
        Parameters:
        value - value to be checked
        defaultValue - value to return if the value is not a negative number
        Returns:
        the value passed as argument if is a negative number or the default.
      • greaterThanOrZero

        public static int greaterThanOrZero​(int value,
                                            int threshold)
        Checks if the value is greater than number and returns it. If not greater than, returns 0.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        Returns:
        the value passed as argument if is greater than the number or 0.
      • greaterThanOrThreshold

        public static int greaterThanOrThreshold​(int value,
                                                 int threshold)
        Checks if the value is greater than number and returns it. If not greater than, returns the threshold.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        Returns:
        the value passed as argument if is greater than the number or the threshold.
      • greaterThanOrDefault

        public static int greaterThanOrDefault​(int value,
                                               int threshold,
                                               int defaultValue)
        Checks if the value is greater than number and returns it. If not greater than, returns the default.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        defaultValue - value to return if the value is not greater than the number
        Returns:
        the value passed as argument if is greater than the number or the default.
      • lessThanOrZero

        public static int lessThanOrZero​(int value,
                                         int threshold)
        Checks if the value is less than number and returns it. If not less than, returns 0.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        Returns:
        the value passed as argument if is less than the number or 0.
      • lessThanOrThreshold

        public static int lessThanOrThreshold​(int value,
                                              int threshold)
        Checks if the value is less than number and returns it. If not less than, returns the threshold.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        Returns:
        the value passed as argument if is less than the number or the threshold.
      • lessThanOrDefault

        public static int lessThanOrDefault​(int value,
                                            int threshold,
                                            int defaultValue)
        Checks if the value is less than number and returns it. If not less than, returns the default.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        defaultValue - value to return if the value is not less than the number
        Returns:
        the value passed as argument if is less than the number or the default.
      • betweenOrMaximum

        public static int betweenOrMaximum​(int value,
                                           int minimum,
                                           int maximum)
        Checks if the value is between minimum and maximum passed values and returns it. If not between, returns the maximum.
        Parameters:
        value - value to be checked
        minimum - minimum limit to compare to the value
        maximum - maximum limit to compare to the value
        Returns:
        the value passed as argument if is between minimum and maximum passed values or the maximum.
      • betweenOrMinimum

        public static int betweenOrMinimum​(int value,
                                           int minimum,
                                           int maximum)
        Checks if the value is between minimum and maximum passed values and returns it. If not between, returns the minimum.
        Parameters:
        value - value to be checked
        minimum - minimum limit to compare to the value
        maximum - maximum limit to compare to the value
        Returns:
        the value passed as argument if is between minimum and maximum passed values or the minimum.
      • betweenOrDefault

        public static int betweenOrDefault​(int value,
                                           int minimum,
                                           int maximum,
                                           int defaultValue)
        Checks if the value is between minimum and maximum passed values and returns it. If not between, returns the default.
        Parameters:
        value - value to be checked
        minimum - minimum limit to compare to the value
        maximum - maximum limit to compare to the value
        defaultValue - value to return if the value is not between minimum and maximum
        Returns:
        the value passed as argument if is between minimum and maximum passed values or the default.
      • validOrZero

        public static double validOrZero​(double value)
        Checks if the value is a consistent number and returns it. If not a consistent number, returns 0.
        Parameters:
        value - value to be checked
        Returns:
        the value passed as argument if is a consistent number or 0.
      • validOrDefault

        public static double validOrDefault​(double value,
                                            double defaultValue)
        Checks if the value is a consistent number and returns it. If not a consistent number, returns the default.
        Parameters:
        value - value to be checked
        defaultValue - value to return if the value is not a consistent number
        Returns:
        the value passed as argument if is a consistent number or the default.
      • positiveOrZero

        public static double positiveOrZero​(double value)
        Checks if the value is a positive number and returns it. If not a positive number, returns 0.
        Parameters:
        value - value to be checked
        Returns:
        the value passed as argument if is a positive number or 0.
      • positiveOrDefault

        public static double positiveOrDefault​(double value,
                                               double defaultValue)
        Checks if the value is a positive number and returns it. If not a positive number, returns the default.
        Parameters:
        value - value to be checked
        defaultValue - value to return if the value is not a positive number
        Returns:
        the value passed as argument if is a positive number or the default.
      • negativeOrZero

        public static double negativeOrZero​(double value)
        Checks if the value is a negative number and returns it. If not a negative number, returns 0.
        Parameters:
        value - value to be checked
        Returns:
        the value passed as argument if is a negative number or 0.
      • negativeOrDefault

        public static double negativeOrDefault​(double value,
                                               double defaultValue)
        Checks if the value is a negative number and returns it. If not a negative number, returns the default.
        Parameters:
        value - value to be checked
        defaultValue - value to return if the value is not a negative number
        Returns:
        the value passed as argument if is a negative number or the default.
      • greaterThanOrZero

        public static double greaterThanOrZero​(double value,
                                               double threshold)
        Checks if the value is greater than number and returns it. If not greater than, returns 0.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        Returns:
        the value passed as argument if is greater than the number or 0.
      • greaterThanOrThreshold

        public static double greaterThanOrThreshold​(double value,
                                                    double threshold)
        Checks if the value is greater than number and returns it. If not greater than, returns the threshold.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        Returns:
        the value passed as argument if is greater than the number or the threshold.
      • greaterThanOrDefault

        public static double greaterThanOrDefault​(double value,
                                                  double threshold,
                                                  double defaultValue)
        Checks if the value is greater than number and returns it. If not greater than, returns the default.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        defaultValue - value to return if the value is not greater than the number
        Returns:
        the value passed as argument if is greater than the number or the default.
      • lessThanOrZero

        public static double lessThanOrZero​(double value,
                                            double threshold)
        Checks if the value is less than number and returns it. If not less than, returns 0.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        Returns:
        the value passed as argument if is less than the number or 0.
      • lessThanOrThreshold

        public static double lessThanOrThreshold​(double value,
                                                 double threshold)
        Checks if the value is less than number and returns it. If not less than, returns the threshold.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        Returns:
        the value passed as argument if is less than the number or the threshold.
      • lessThanOrDefault

        public static double lessThanOrDefault​(double value,
                                               double threshold,
                                               double defaultValue)
        Checks if the value is less than number and returns it. If not less than, returns the default.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        defaultValue - value to return if the value is not less than the number
        Returns:
        the value passed as argument if is less than the number or the default.
      • betweenOrMaximum

        public static double betweenOrMaximum​(double value,
                                              double minimum,
                                              double maximum)
        Checks if the value is between minimum and maximum passed values and returns it. If not between, returns the maximum.
        Parameters:
        value - value to be checked
        minimum - minimum limit to compare to the value
        maximum - maximum limit to compare to the value
        Returns:
        the value passed as argument if is between minimum and maximum passed values or the maximum.
      • betweenOrMinimum

        public static double betweenOrMinimum​(double value,
                                              double minimum,
                                              double maximum)
        Checks if the value is between minimum and maximum passed values and returns it. If not between, returns the minimum.
        Parameters:
        value - value to be checked
        minimum - minimum limit to compare to the value
        maximum - maximum limit to compare to the value
        Returns:
        the value passed as argument if is between minimum and maximum passed values or the minimum.
      • betweenOrDefault

        public static double betweenOrDefault​(double value,
                                              double minimum,
                                              double maximum,
                                              double defaultValue)
        Checks if the value is between minimum and maximum passed values and returns it. If not between, returns the default.
        Parameters:
        value - value to be checked
        minimum - minimum limit to compare to the value
        maximum - maximum limit to compare to the value
        defaultValue - value to return if the value is not between minimum and maximum
        Returns:
        the value passed as argument if is between minimum and maximum passed values or the default.
      • checkIfValid

        public static void checkIfValid​(int value,
                                        String what)
        Checks if value passed as argument is valid.
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        what - name of the value to put in the exception message
      • checkAndGetIfValid

        public static int checkAndGetIfValid​(int value,
                                             String what)
        Checks if value passed as argument is valid and, if valid, returns the argument.
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        what - name of the value to put in the exception message
        Returns:
        the value passed as argument
      • isPositive

        public static boolean isPositive​(int value)
        Checks if value passed as argument is a positive number (zero is included).
        Parameters:
        value - value to be checked
        Returns:
        true if the value is positive number (zero is included)
      • checkIfPositive

        public static void checkIfPositive​(int value,
                                           String what)
        Checks if value passed as argument is a positive number (zero is included).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        what - name of the value to put in the exception message
      • checkAndGetIfPositive

        public static int checkAndGetIfPositive​(int value,
                                                String what)
        Checks if value passed as argument is a positive number (zero is included).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        what - name of the value to put in the exception message
        Returns:
        the value passed as argument
      • isNegative

        public static boolean isNegative​(int value)
        Checks if value passed as argument is a negative number (zero is excluded).
        Parameters:
        value - value to be checked
        Returns:
        true if the value is positive number (zero is excluded)
      • checkIfNegative

        public static void checkIfNegative​(int value,
                                           String what)
        Checks if value passed as argument is a negative number (zero is excluded).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        what - name of the value to put in the exception message
      • checkAndGetIfNegative

        public static int checkAndGetIfNegative​(int value,
                                                String what)
        Checks if value passed as argument is a negative number (zero is excluded).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        what - name of the value to put in the exception message
        Returns:
        the value passed as argument
      • isNotEqualTo

        public static boolean isNotEqualTo​(int value,
                                           int target)
        Checks if both values passed as argument are not equals.
        Parameters:
        value - value to be checked
        target - value to be compared to the value
        Returns:
        true if the arguments are not equals
      • checkIfNotEqualTo

        public static void checkIfNotEqualTo​(int value,
                                             int target,
                                             String what)
        Checks if both values passed as argument are not equals.
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        target - value to be compared to the value
        what - name of the value to put in the exception message
      • isEqualTo

        public static boolean isEqualTo​(int value,
                                        int target)
        Checks if both values passed as argument are equals.
        Parameters:
        value - value to be checked
        target - value to be compared to the value
        Returns:
        true if the arguments are equals
      • checkIfEqualTo

        public static void checkIfEqualTo​(int value,
                                          int target,
                                          String what)
        Checks if both values passed as argument are equals.
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        target - value to be compared to the value
        what - name of the value to put in the exception message
      • isGreaterThan

        public static boolean isGreaterThan​(int value,
                                            int threshold)
        Checks if the value passed as argument is greater than the threshold passed as argument (inclusive).
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        Returns:
        true if the value is greater than the threshold (inclusive)
      • checkIfGreaterThan

        public static void checkIfGreaterThan​(int value,
                                              int threshold,
                                              String what)
        Checks if the value passed as argument is greater than the threshold passed as argument (inclusive).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        what - name of the value to put in the exception message
      • checkAndGetIfGreaterThan

        public static int checkAndGetIfGreaterThan​(int value,
                                                   int threshold,
                                                   String what)
        Checks if the value passed as argument is greater than the threshold passed as argument (inclusive).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        what - name of the value to put in the exception message
        Returns:
        the value passed as argument
      • isLessThan

        public static boolean isLessThan​(int value,
                                         int threshold)
        Checks if the value passed as argument is less than the threshold passed as argument (inclusive).
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        Returns:
        true if the value is less than the threshold (inclusive)
      • checkIfLessThan

        public static void checkIfLessThan​(int value,
                                           int threshold,
                                           String what)
        Checks if the value passed as argument is less than the threshold passed as argument (inclusive).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        what - name of the value to put in the exception message
      • checkAndGetIfLessThan

        public static int checkAndGetIfLessThan​(int value,
                                                int threshold,
                                                String what)
        Checks if the value passed as argument is less than the threshold passed as argument (inclusive).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        what - name of the value to put in the exception message
        Returns:
        the value passed as argument
      • isBetween

        public static boolean isBetween​(int value,
                                        int minimum,
                                        int maximum)
        Checks if the value passed as argument is between minimum and maximum values, passed as argument (inclusive).
        Parameters:
        value - value to be checked
        minimum - minimum limit to compare to the value
        maximum - maximum limit to compare to the value
        Returns:
        true if the value passed as argument is between minimum and maximum values, passed as argument (inclusive)
      • checkIfBetween

        public static void checkIfBetween​(int value,
                                          int minimum,
                                          int maximum,
                                          String what)
        Checks if the value passed as argument is between minimum and maximum values, passed as argument (inclusive).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        minimum - minimum limit to compare to the value
        maximum - maximum limit to compare to the value
        what - name of the value to put in the exception message
      • checkAndGetIfBetween

        public static int checkAndGetIfBetween​(int value,
                                               int minimum,
                                               int maximum,
                                               String what)
        Checks if the value passed as argument is between minimum and maximum values, passed as argument (inclusive).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        minimum - minimum limit to compare to the value
        maximum - maximum limit to compare to the value
        what - name of the value to put in the exception message
        Returns:
        the value passed as argument
      • checkIfValid

        public static void checkIfValid​(double value,
                                        String what)
        Checks if value passed as argument is valid.
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        what - name of the value to put in the exception message
      • checkAndGetIfValid

        public static double checkAndGetIfValid​(double value,
                                                String what)
        Checks if value passed as argument is valid and, if valid, returns the argument.
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        what - name of the value to put in the exception message
        Returns:
        the value passed as argument
      • isPositive

        public static boolean isPositive​(double value)
        Checks if value passed as argument is a positive number (zero is included).
        Parameters:
        value - value to be checked
        Returns:
        true if the value is positive number (zero is included)
      • checkIfPositive

        public static void checkIfPositive​(double value,
                                           String what)
        Checks if value passed as argument is a positive number (zero is included).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        what - name of the value to put in the exception message
      • checkAndGetIfPositive

        public static double checkAndGetIfPositive​(double value,
                                                   String what)
        Checks if value passed as argument is a positive number (zero is included).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        what - name of the value to put in the exception message
        Returns:
        the value passed as argument
      • isNegative

        public static boolean isNegative​(double value)
        Checks if value passed as argument is a negative number (zero is excluded).
        Parameters:
        value - value to be checked
        Returns:
        true if the value is positive number (zero is excluded)
      • checkIfNegative

        public static void checkIfNegative​(double value,
                                           String what)
        Checks if value passed as argument is a negative number (zero is excluded).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        what - name of the value to put in the exception message
      • checkAndGetIfNegative

        public static double checkAndGetIfNegative​(double value,
                                                   String what)
        Checks if value passed as argument is a negative number (zero is excluded).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        what - name of the value to put in the exception message
        Returns:
        the value passed as argument
      • isNotEqualTo

        public static boolean isNotEqualTo​(double value,
                                           double target)
        Checks if both values passed as argument are not equals.
        Parameters:
        value - value to be checked
        target - value to be compared to the value
        Returns:
        true if the arguments are not equals
      • checkIfNotEqualTo

        public static void checkIfNotEqualTo​(double value,
                                             double target,
                                             String what)
        Checks if both values passed as argument are not equals.
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        target - value to be compared to the value
        what - name of the value to put in the exception message
      • isEqualTo

        public static boolean isEqualTo​(double value,
                                        double target)
        Checks if both values passed as argument are equals.
        Parameters:
        value - value to be checked
        target - value to be compared to the value
        Returns:
        true if the arguments are equals
      • checkIfEqualTo

        public static void checkIfEqualTo​(double value,
                                          double target,
                                          String what)
        Checks if both values passed as argument are equals.
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        target - value to be compared to the value
        what - name of the value to put in the exception message
      • isGreaterThan

        public static boolean isGreaterThan​(double value,
                                            double threshold)
        Checks if the value passed as argument is greater than the threshold passed as argument (inclusive).
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        Returns:
        true if the value is greater than the threshold (inclusive)
      • checkIfGreaterThan

        public static void checkIfGreaterThan​(double value,
                                              double threshold,
                                              String what)
        Checks if the value passed as argument is greater than the threshold passed as argument (inclusive).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        what - name of the value to put in the exception message
      • checkAndGetIfGreaterThan

        public static double checkAndGetIfGreaterThan​(double value,
                                                      double threshold,
                                                      String what)
        Checks if the value passed as argument is greater than the threshold passed as argument (inclusive).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        what - name of the value to put in the exception message
        Returns:
        the value passed as argument
      • isLessThan

        public static boolean isLessThan​(double value,
                                         double threshold)
        Checks if the value passed as argument is less than the threshold passed as argument (inclusive).
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        Returns:
        true if the value is less than the threshold (inclusive)
      • checkIfLessThan

        public static void checkIfLessThan​(double value,
                                           double threshold,
                                           String what)
        Checks if the value passed as argument is less than the threshold passed as argument (inclusive).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        what - name of the value to put in the exception message
      • checkAndGetIfLessThan

        public static double checkAndGetIfLessThan​(double value,
                                                   double threshold,
                                                   String what)
        Checks if the value passed as argument is less than the threshold passed as argument (inclusive).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        threshold - value to be compared to the value
        what - name of the value to put in the exception message
        Returns:
        the value passed as argument
      • isBetween

        public static boolean isBetween​(double value,
                                        double minimum,
                                        double maximum)
        Checks if the value passed as argument is between minimum and maximum values, passed as argument (inclusive).
        Parameters:
        value - value to be checked
        minimum - minimum limit to compare to the value
        maximum - maximum limit to compare to the value
        Returns:
        true if the value passed as argument is between minimum and maximum values, passed as argument (inclusive
      • checkIfBetween

        public static void checkIfBetween​(double value,
                                          double minimum,
                                          double maximum,
                                          String what)
        Checks if the value passed as argument is between minimum and maximum values, passed as argument (inclusive).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        minimum - minimum limit to compare to the value
        maximum - maximum limit to compare to the value
        what - name of the value to put in the exception message
      • checkAndGetIfBetween

        public static double checkAndGetIfBetween​(double value,
                                                  double minimum,
                                                  double maximum,
                                                  String what)
        Checks if the value passed as argument is between minimum and maximum values, passed as argument (inclusive).
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        minimum - minimum limit to compare to the value
        maximum - maximum limit to compare to the value
        what - name of the value to put in the exception message
        Returns:
        the value passed as argument
      • validOrDefault

        public static <T> T validOrDefault​(T value,
                                           T defaultValue)
        Checks if the value is a consistent object and returns it. If not a consistent object, returns the default.
        Type Parameters:
        T - type of the object to check
        Parameters:
        value - value to be checked
        defaultValue - value to return if the value is not a consistent object
        Returns:
        the value passed as argument if is a consistent object or the default.
      • checkIfValid

        public static void checkIfValid​(Object value,
                                        String what)
        Checks if value passed as argument is valid.
        If not, throw a IllegalArgumentException.
        Parameters:
        value - value to be checked
        what - name of the value to put in the exception message
      • checkAndGetIfValid

        public static <T> T checkAndGetIfValid​(T value,
                                               String what)
        Checks if value passed as argument is valid and, if valid, returns the argument.
        If not, throw a IllegalArgumentException.
        Type Parameters:
        T - type of the value to be checked
        Parameters:
        value - value to be checked
        what - name of the value to put in the exception message
        Returns:
        the value passed as argument