Github user britter commented on a diff in the pull request: https://github.com/apache/commons-lang/pull/87#discussion_r30061992 --- Diff: src/main/java/org/apache/commons/lang3/Validate.java --- @@ -874,7 +888,752 @@ public static void matchesPattern(final CharSequence input, final String pattern throw new IllegalArgumentException(String.format(message, values)); } } - + + // notNaN + //--------------------------------------------------------------------------------- + + /** + * <p>Validates that the specified argument is not {@code NaN}; otherwise + * throwing an exception.</p> + * + * <pre>Validate.notNaN(myDouble);</pre> + * + * <p>The message of the exception is "The validated value is not a + * number".</p> + * + * @param value the value to validate + * @throws IllegalArgumentException if the value is not a number + * @see #notNaN(double, java.lang.String, java.lang.Object...) + * + * @since 3.4 + */ + public static void notNaN(final double value) { + notNaN(value, DEFAULT_NOT_NAN_EX_MESSAGE); + } + + /** + * <p>Validates that the specified argument is not {@code NaN}; otherwise + * throwing an exception with the specified message.</p> + * + * <pre>Validate.notNaN(myDouble, "The value must be a number");</pre> + * + * @param value the value to validate + * @param message the {@link String#format(String, Object...)} exception message if invalid, not null + * @param values the optional values for the formatted exception message + * @throws IllegalArgumentException if the value is not a number + * @see #notNaN(double) + * + * @since 3.4 + */ + public static void notNaN(final double value, final String message, final Object... values) { + if (value != value) { + throw new IllegalArgumentException(String.format(message, values)); + } + } + + // finite + //--------------------------------------------------------------------------------- + + /** + * <p>Validates that the specified argument is not infinite or {@code NaN}; + * otherwise throwing an exception.</p> + * + * <pre>Validate.finite(myDouble);</pre> + * + * <p>The message of the exception is "The value is invalid: %f".</p> + * + * @param value the value to validate + * @throws IllegalArgumentException if the value is infinite or {@code NaN} + * @see #finite(double, java.lang.String, java.lang.Object...) + * + * @since 3.4 + */ + public static void finite(final double value) { + finite(value, DEFAULT_FINITE_EX_MESSAGE, value); + } + + /** + * <p>Validates that the specified argument is not infinite or {@code NaN}; + * otherwise throwing an exception with the specified message.</p> + * + * <pre>Validate.finite(myDouble, "The argument must contain a numeric value");</pre> + * + * @param value the value to validate + * @param message the {@link String#format(String, Object...)} exception message if invalid, not null + * @param values the optional values for the formatted exception message + * @throws IllegalArgumentException if the value is infinite or {@code NaN} + * @see #finite(double) + * + * @since 3.4 + */ + public static void finite(final double value, final String message, final Object... values) { + if (value != value || Double.isInfinite(value)) { + throw new IllegalArgumentException(String.format(message, values)); + } + } + + // greater + //--------------------------------------------------------------------------------- + + /** + * <p>Validates that the specified argument is strictly greater than a given + * reference; otherwise throwing an exception.</p> + * + * <pre>Validate.greaterObj(myObject, refObject);</pre> + * + * <p>The message of the exception is "The value {@code value} is not + * greater than {@code min}".</p> + * + * @param <T> the type of the argument object + * @param min the reference value + * @param value the object to validate + * @throws IllegalArgumentException if {@code value} is smaller than or equal to {@code min} + * @see #greaterObj(java.lang.Object, java.lang.Comparable, java.lang.String, java.lang.Object...) + * + * @since 3.4 + */ + public static <T> void greaterObj(final T min, final Comparable<T> value) { + greaterObj(min, value, DEFAULT_GREATER_EX_MESSAGE, value, min); + } + + /** + * <p>Validates that the specified argument is strictly greater than a given + * reference; otherwise throwing an exception with the specified message.</p> + * + * <pre>Validate.greaterObj(myObject, refObject, "The value must be greater than the reference");</pre> + * + * @param <T> the type of the argument object + * @param min the reference value + * @param value the object to validate + * @param message the {@link String#format(String, Object...)} exception message if invalid, not null + * @param values the optional values for the formatted exception message + * @throws IllegalArgumentException if {@code value} is smaller than or equal to {@code min} + * @see #greaterObj(java.lang.Object, java.lang.Comparable) + * + * @since 3.4 + */ + public static <T> void greaterObj(final T min, final Comparable<T> value, final String message, final Object... values) { + if (value.compareTo(min) <= 0) { + throw new IllegalArgumentException(String.format(message, values)); + } + } + + /** + * <p>Validates that the specified argument is strictly greater than a given + * reference; otherwise throwing an exception.</p> + * + * <pre>Validate.greater(myLong, 0);</pre> + * + * <p>The message of the exception is "The value {@code value} is not + * greater than {@code min}".</p> + * + * @param min the reference value + * @param value the value to validate + * @throws IllegalArgumentException if {@code value} is smaller than or equal to {@code min} + * @see #greater(long, long, java.lang.String, java.lang.Object...) + * + * @since 3.4 + */ + public static void greater(final long min, final long value) { + greater(min, value, DEFAULT_GREATER_EX_MESSAGE, value, min); + } + + /** + * <p>Validates that the specified argument is strictly greater than a given + * reference; otherwise throwing an exception with the specified message.</p> + * + * <pre>Validate.greater(myLong, 0);</pre> + * + * @param min the reference value + * @param value the value to validate + * @param message the {@link String#format(String, Object...)} exception message if invalid, not null + * @param values the optional values for the formatted exception message + * @throws IllegalArgumentException if {@code value} is smaller than or equal to {@code min} + * @see #greater(long, long) + * + * @since 3.4 + */ + public static void greater(final long min, final long value, final String message, final Object... values) { + if (value <= min) { + throw new IllegalArgumentException(String.format(message, values)); + } + } + + /** + * <p>Validates that the specified argument is strictly greater than a given + * reference; otherwise throwing an exception.</p> + * + * <p>If {@code min} or {@code value} is {@code NaN}, the test will fail and + * the exception will be thrown.</p> + * + * <pre>Validate.greater(myDouble, 0.0);</pre> + * + * <p>The message of the exception is "The value {@code value} is not + * greater than {@code min}".</p> + * + * @param min the reference value + * @param value the value to validate + * @throws IllegalArgumentException if {@code value} is smaller than or equal to {@code min} + * @see #greater(double, double, java.lang.String, java.lang.Object...) + * + * @since 3.4 + */ + public static void greater(final double min, final double value) { + greater(min, value, DEFAULT_GREATER_EX_MESSAGE, value, min); + } + + /** + * <p>Validates that the specified argument is strictly greater than a given + * reference; otherwise throwing an exception with the specified message.</p> + * + * <p>If {@code min} or {@code value} is {@code NaN}, the test will fail and + * the exception will be thrown.</p> + * + * <pre>Validate.greater(myDouble, 0.0);</pre> + * + * @param min the reference value + * @param value the value to validate + * @param message the {@link String#format(String, Object...)} exception message if invalid, not null + * @param values the optional values for the formatted exception message + * @throws IllegalArgumentException if {@code value} is smaller than or equal to {@code min} + * @see #greater(double, double) + * + * @since 3.4 + */ + public static void greater(final double min, final double value, final String message, final Object... values) { + if (!(value > min)) { + throw new IllegalArgumentException(String.format(message, values)); + } + } + + // greaterOrEqual + //--------------------------------------------------------------------------------- + + /** + * <p>Validates that the specified argument is greater than, or equal to, a + * given reference; otherwise throwing an exception.</p> + * + * <pre>Validate.greaterOrEqualObj(myObject, refObject);</pre> + * + * <p>The message of the exception is "The value {@code value} is not + * greater than or equal to {@code min}".</p> + * + * @param <T> the type of the argument object + * @param min the reference value + * @param value the object to validate + * @throws IllegalArgumentException if {@code value} is smaller than {@code min} + * @see #greaterOrEqualObj(java.lang.Object, java.lang.Comparable, java.lang.String, java.lang.Object...) + * + * @since 3.4 + */ + public static <T> void greaterOrEqualObj(final T min, final Comparable<T> value) { --- End diff -- Again, the "Obj" can be dropped.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---