diff --git a/README.md b/README.md index e240171..7bfb6ad 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,21 @@ of a number, methods for checking and validating if a number is less than or gre number falls in a given range. ## Get Started +There are different ways you can use the library:- + +### Maven +Add the following dependency to your `pom` file. +```xml + + com.kori_47 + utils + 1.2.0 + pom + +``` -To use the library, make sure you have jcenter in your repositories closure: +### Gradle +Make sure you have jcenter in your repositories closure. ```gradle repositories { @@ -31,14 +44,22 @@ repositories { } ``` -Then add the following dependency to your `build.gradle`: +Then add the following dependency to your `build.gradle`. ```gradle dependencies { - api 'com.kori_47:utils:1.1.0' + api 'com.kori_47:utils:1.2.0' } ``` +### Ivy +```xml + + + +``` + +### Building the library Or alternatively, you can use [gradle](https://gradle.org/) to compile and build the library. Just follow the steps bellow: * Clone the project from [github](https://github.com/kennedykori/JavaUtils). diff --git a/build.gradle b/build.gradle index c93ed76..4434026 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ sourceCompatibility = 1.8 targetCompatibility = 1.8 group = 'com.kori_47' -version = '1.1.0' +version = '1.2.0' repositories { // Use jcenter for resolving dependencies. @@ -78,7 +78,6 @@ def pomConfig = { email 'kennedykori47@gmail.com' } } - scm { url 'https://github.com/kennedykori/JavaUtils' } @@ -91,11 +90,11 @@ publishing { // Attach sources and javadoc Jars to the main maven publication artifact sourcesJar artifact javadocJar - + groupId 'com.kori_47' artifactId 'utils' - version '1.1.0' - + version '1.2.0' + pom.withXml { def root = asNode() root.appendNode('description', 'This library contains a utility class that is composed of static methods that can be used for checking and validation of both objects and primitives.') @@ -112,32 +111,32 @@ bintray { key = System.getenv('BINTRAY_KEY') publications = ['UtilsPublication'] pkg { - repo = 'kori_47' - name = 'utils' - desc = 'This library contains a utility class that is composed of static methods that can be used for checking and validation of both objects and primitives.' - websiteUrl = 'https://github.com/kennedykori/JavaUtils' - issueTrackerUrl = 'https://github.com/kennedykori/JavaUtils/issues' - vcsUrl = 'https://github.com/kennedykori/JavaUtils.git' - licenses = ['MIT'] - labels = ['java', 'utils', 'utility'] - publicDownloadNumbers = true - - githubRepo = 'kennedykori/JavaUtils' - githubReleaseNotesFile = 'doc-files/release-notes-1.1.0.md' - - version { - name = '1.1.0' - desc = 'Utils 1.1.0' - released = new Date() - vcsTag = '1.1.0' - // GPG Signing - gpg { + repo = 'kori_47' + name = 'utils' + desc = 'This library contains a utility class that is composed of static methods that can be used for checking and validation of both objects and primitives.' + websiteUrl = 'https://github.com/kennedykori/JavaUtils' + issueTrackerUrl = 'https://github.com/kennedykori/JavaUtils/issues' + vcsUrl = 'https://github.com/kennedykori/JavaUtils.git' + licenses = ['MIT'] + labels = ['java', 'utils', 'utility'] + publicDownloadNumbers = true + + githubRepo = 'kennedykori/JavaUtils' + githubReleaseNotesFile = 'doc-files/release-notes-1.2.0.md' + + version { + name = '1.2.0' + desc = 'Utils 1.2.0' + released = new Date() + vcsTag = '1.2.0' + // GPG Signing + gpg { sign = true - } - // Maven Central Sync - mavenCentralSync { - sync = true - } - } + } + // Maven Central Sync + mavenCentralSync { + sync = true + } + } } } diff --git a/doc-files/release-notes-1.2.0.md b/doc-files/release-notes-1.2.0.md new file mode 100644 index 0000000..56add99 --- /dev/null +++ b/doc-files/release-notes-1.2.0.md @@ -0,0 +1,82 @@ +# Java Utils v1.2.0 + +## Introduction + +The following notes describe important changes and information about this release. + +## Upgrade Instructions + +For [gradle](https://gradle.org/) users, switch to version 1.2.0 by updating your `build.gradle` +dependencies to: + +```gradle +dependencies { + api 'com.kori_47:utils:1.2.0' + // other dependencies +} +``` + +For maven users, update your `pom` file to: + +```xml + + com.kori_47 + utils + 1.2.0 + pom + +``` + +### Compatibility Notes + +This release was tested on Java 8 and is expected to work well on Java 8 and later versions. +It may or may not work on earlier versions of Java. + +This version was tested with [junit 5](https://junit.org/junit5/). + +## What's New + +The following static utility methods were added in these release: + +* Methods for checking if a number is equal to a given base value. +* Methods for validating if a number is equal to a given base value. + +The utility methods above can be divided into _checkers_ and _validators_. + +### Checkers + +These are methods that take a value and check if it meets a given condition and if so, +returns `true`, else, returns `false`. These methods are: + +1. *__isEqualTo__* + + This are methods that check if a number is equal to a given baseValue. These methods + have the following form: + + ```java + public final static boolean isEqualTo( baseValue, value){ /* method body */ }; + ``` + + There are five variants of the method above, where `` can be one of the following: `int`, + `long`, `float`, `double` or `java.math.BigDecimal`. + +### Validators + +These are methods that take a value and validate if it meets a given condition and if so, +returns the value, else, throws a `java.lang.IllegalArgumentException`. These methods are: + +1. *__requireEqualTo__* + + This are methods that validate if a number is equal to a given baseValue. These methods + have the following form: + + ```java + public final static requireEqualTo( baseValue, value){ /* method body */ }; + ``` + + There are five variants of the method above, where `` can be one of the following: `int`, + `long`, `float`, `double` or `java.math.BigDecimal`. + +## Reporting Problems + +If you find a problem with this release, please file a bug on [GitHub Issues](https://github.com/kennedykori/JavaUtils/issues). diff --git a/src/main/java/com/kori_47/utils/ObjectUtils.java b/src/main/java/com/kori_47/utils/ObjectUtils.java index c11346a..3ce6e79 100644 --- a/src/main/java/com/kori_47/utils/ObjectUtils.java +++ b/src/main/java/com/kori_47/utils/ObjectUtils.java @@ -3,11 +3,14 @@ */ package com.kori_47.utils; -import static java.util.Objects.*; +import static java.util.Objects.isNull; +import static java.util.Objects.nonNull; +import static java.util.Objects.requireNonNull; import java.io.Serializable; import java.math.BigDecimal; + /** * This class consists of static utility methods(similar to * {@link java.util.Objects}) for operating on objects, and primitives. @@ -54,25 +57,104 @@ */ public final class ObjectUtils { - /*------------------------------------------------------------------------------------- + // ======================================================================== + // IS EQUAL CHECKS + // ======================================================================== + /** + * Checks if an {@code int} is equal to a supplied base value. Returns + * {@code true} if the given {@code int} is equal to the supplied base value. * - * NUMBERS - * - * ------------------------------------------------------------------------------------ + * @param baseValue the value to compare for equality to. + * @param value the value to check for equality. + * @return {@code true} if {@code value} is equal to {@code baseValue}. + * + * @since 1.2.0 + */ + public final static boolean isEqualTo(int baseValue, int value) { + return baseValue == value; + } + + /** + * Checks if a {@code long} is equal to a supplied base value. Returns + * {@code true} if the given {@code long} is equal to the supplied base value. + * + * @param baseValue the value to compare for equality to. + * @param value the value to check for equality. + * @return {@code true} if {@code value} is equal to {@code baseValue}. + * + * @since 1.2.0 */ - /* - * ------------------------------------ IS GREATER THAN - * ------------------------------------ + public final static boolean isEqualTo(long baseValue, long value) { + return baseValue == value; + } + + /** + * Checks if a {@code float} is equal to a supplied base value. Returns + * {@code true} if the given {@code float} is equal to the supplied base + * value.
+ *
+ * NOTE: This method uses + * {@link Float#compare(float, float)} to compare the given values. + * + * @param baseValue the value to compare for equality to. + * @param value the value to check for equality. + * + * @return {@code true} if {@code value} is equal to {@code baseValue}. + * + * @since 1.2.0 + */ + public final static boolean isEqualTo(float baseValue, float value) { + return Float.compare(value, baseValue) == 0; + } + + /** + * Checks if a {@code double} is equal to a supplied base value. Returns + * {@code true} if the given {@code double} is equal to the supplied base value. + *
+ *
+ * NOTE: This method uses + * {@link Double#compare(double, double)} to compare the given values. + * + * @param baseValue the value to compare for equality to. + * @param value the value to check for equality. + * + * @return {@code true} if {@code value} is equal to {@code baseValue}. + * + * @since 1.2.0 + */ + public final static boolean isEqualTo(double baseValue, double value) { + return Double.compare(value, baseValue) == 0; + } + + /** + * Checks if a {@link BigDecimal} is equal to a supplied base value. Returns + * {@code true} if the given {@code BigDecimal} is equal to the supplied base + * value. + * + * @param baseValue the value to compare for equality to. + * @param value the value to check for equality. + * + * @return {@code true} if {@code value} is greater than {@code baseValue}. + * + * @throws NullPointerException if any of the two arguments is/are {@code null}. + * + * @since 1.2.0 */ + public final static boolean isEqualTo(BigDecimal baseValue, BigDecimal value) { + return requireNonNull(value, "value cannot be null.") + .compareTo(requireNonNull(baseValue, "baseValue cannot be null.")) == 0; + } + + // ======================================================================== + // IS GREATER THAN CHECKS + // ======================================================================== /** * Checks if an {@code int} is greater than a supplied base value. Returns * {@code true} if the given {@code int} is greater than the supplied base * value. * - * @param baseValue - * the value to compare for greatness against. - * @param value - * the value to check for greatness. + * @param baseValue the value to compare for greatness against. + * @param value the value to check for greatness. * * @return {@code true} if {@code value} is greater than {@code baseValue}. * @@ -87,10 +169,8 @@ public final static boolean isGreaterThan(int baseValue, int value) { * {@code true} if the given {@code long} is greater than the supplied base * value. * - * @param baseValue - * the value to compare for greatness against. - * @param value - * the value to check for greatness. + * @param baseValue the value to compare for greatness against. + * @param value the value to check for greatness. * * @return {@code true} if {@code value} is greater than {@code baseValue}. * @@ -108,10 +188,8 @@ public final static boolean isGreaterThan(long baseValue, long value) { * NOTE: This method uses * {@link Float#compare(float, float)} to compare the given values. * - * @param baseValue - * the value to compare for greatness against. - * @param value - * the value to check for greatness. + * @param baseValue the value to compare for greatness against. + * @param value the value to check for greatness. * * @return {@code true} if {@code value} is greater than {@code baseValue}. * @@ -129,10 +207,8 @@ public final static boolean isGreaterThan(float baseValue, float value) { * NOTE: This method uses * {@link Double#compare(double, double)} to compare the given values. * - * @param baseValue - * the value to compare for greatness against. - * @param value - * the value to check for greatness. + * @param baseValue the value to compare for greatness against. + * @param value the value to check for greatness. * * @return {@code true} if {@code value} is greater than {@code baseValue}. * @@ -147,15 +223,12 @@ public final static boolean isGreaterThan(double baseValue, double value) { * {@code true} if the given {@code BigDecimal} is greater than the supplied * base value. * - * @param baseValue - * the value to compare for greatness against. - * @param value - * the value to check for greatness. + * @param baseValue the value to compare for greatness against. + * @param value the value to check for greatness. * * @return {@code true} if {@code value} is greater than {@code baseValue}. * - * @throws NullPointerException - * if any of the two arguments is/are {@code null}. + * @throws NullPointerException if any of the two arguments is/are {@code null}. * * @since 1.1.0 */ @@ -164,19 +237,16 @@ public final static boolean isGreaterThan(BigDecimal baseValue, BigDecimal value .compareTo(requireNonNull(baseValue, "baseValue cannot be null.")) > 0; } - /* - * ------------------------------------ IS GREATER THAN OR EQUAL TO - * ------------------------------------ - */ + // ======================================================================== + // IS GREATER THAN OR EQUAL TO CHECKS + // ======================================================================== /** * Checks if an {@code int} is greater than or equal to a supplied base value. * Returns {@code true} if the given {@code int} is greater than or equal to the * supplied base value. * - * @param baseValue - * the value to compare for greatness or equality against. - * @param value - * the value to check for greatness or equality. + * @param baseValue the value to compare for greatness or equality against. + * @param value the value to check for greatness or equality. * * @return {@code true} if {@code value} is greater than or equal to * {@code baseValue}. @@ -192,10 +262,8 @@ public final static boolean isGreaterThanOrEqualTo(int baseValue, int value) { * Returns {@code true} if the given {@code long} is greater than or equal to * the supplied base value. * - * @param baseValue - * the value to compare for greatness or equality against. - * @param value - * the value to check for greatness or equality. + * @param baseValue the value to compare for greatness or equality against. + * @param value the value to check for greatness or equality. * * @return {@code true} if {@code value} is greater than or equal to * {@code baseValue}. @@ -214,10 +282,8 @@ public final static boolean isGreaterThanOrEqualTo(long baseValue, long value) { * NOTE: This method uses * {@link Float#compare(float, float)} to compare the given values. * - * @param baseValue - * the value to compare for greatness or equality against. - * @param value - * the value to check for greatness or equality. + * @param baseValue the value to compare for greatness or equality against. + * @param value the value to check for greatness or equality. * * @return {@code true} if {@code value} is greater than or equal to * {@code baseValue}. @@ -236,10 +302,8 @@ public final static boolean isGreaterThanOrEqualTo(float baseValue, float value) * NOTE: This method uses * {@link Double#compare(double, double)} to compare the given values. * - * @param baseValue - * the value to compare for greatness or equality against. - * @param value - * the value to check for greatness or equality. + * @param baseValue the value to compare for greatness or equality against. + * @param value the value to check for greatness or equality. * * @return {@code true} if {@code value} is greater than or equal to * {@code baseValue}. @@ -255,16 +319,13 @@ public final static boolean isGreaterThanOrEqualTo(double baseValue, double valu * value. Returns {@code true} if the given {@code BigDecimal} is greater than * or equal to the supplied base value. * - * @param baseValue - * the value to compare for greatness or equality against. - * @param value - * the value to check for greatness or equality. + * @param baseValue the value to compare for greatness or equality against. + * @param value the value to check for greatness or equality. * * @return {@code true} if {@code value} is greater than or equal to * {@code baseValue}. * - * @throws NullPointerException - * if any of the two arguments is/are {@code null}. + * @throws NullPointerException if any of the two arguments is/are {@code null}. * * @since 1.1.0 */ @@ -273,17 +334,15 @@ public final static boolean isGreaterThanOrEqualTo(BigDecimal baseValue, BigDeci .compareTo(requireNonNull(baseValue, "baseValue cannot be null.")) >= 0; } - /* - * ------------------------------------ IS NEGATIVE - * ------------------------------------ - */ + // ======================================================================== + // IS NEGATIVE CHECKS + // ======================================================================== /** * Checks if an integer is negative, i.e, less than 0 and returns * true if the integer is negative, otherwise returns * false * - * @param value - * the integer to check + * @param value the integer to check * @return true if the integer is negative, otherwise returns * false */ @@ -295,8 +354,7 @@ public final static boolean isNegative(int value) { * Checks if a long is negative, i.e, less than 0 and returns true * if the long is negative, otherwise returns false * - * @param value - * the long to check + * @param value the long to check * @return true if the long is negative, otherwise returns * false */ @@ -308,8 +366,7 @@ public final static boolean isNegative(long value) { * Checks if a float is negative, i.e, less than 0 and returns true * if the float is negative, otherwise returns false * - * @param value - * the float to check + * @param value the float to check * @return true if the float is negative, otherwise returns * false */ @@ -322,8 +379,7 @@ public final static boolean isNegative(float value) { * true if the double is negative, otherwise returns * false * - * @param value - * the double to check + * @param value the double to check * @return true if the double is negative, otherwise returns * false */ @@ -335,31 +391,26 @@ public final static boolean isNegative(double value) { * Checks if a {@link BigDecimal} is negative, i.e, less than 0 and returns * true, otherwise returns false * - * @param value - * the BigDecimal to check + * @param value the BigDecimal to check * * @return true if the BigDecimal is negative, * otherwise returns false * - * @throws NullPointerException - * if value is null. + * @throws NullPointerException if value is null. */ public final static boolean isNegative(BigDecimal value) { return requireNonNull(value).signum() < 0; } - /* - * ------------------------------------ IS LESS THAN - * ------------------------------------ - */ + // ======================================================================== + // IS LESS THAN CHECKS + // ======================================================================== /** * Checks if an {@code int} is less than a supplied base value. Returns * {@code true} if the given {@code int} is less than the supplied base value. * - * @param baseValue - * the value to compare for smallness against. - * @param value - * the value to check for smallness. + * @param baseValue the value to compare for smallness against. + * @param value the value to check for smallness. * * @return {@code true} if {@code value} is less than {@code baseValue}. * @@ -373,10 +424,8 @@ public final static boolean isLessThan(int baseValue, int value) { * Checks if a {@code long} is less than a supplied base value. Returns * {@code true} if the given {@code long} is less than the supplied base value. * - * @param baseValue - * the value to compare for smallness against. - * @param value - * the value to check for smallness. + * @param baseValue the value to compare for smallness against. + * @param value the value to check for smallness. * * @return {@code true} if {@code value} is less than {@code baseValue}. * @@ -394,10 +443,8 @@ public final static boolean isLessThan(long baseValue, long value) { * NOTE: This method uses * {@link Float#compare(float, float)} to compare the given values. * - * @param baseValue - * the value to compare for smallness against. - * @param value - * the value to check for smallness. + * @param baseValue the value to compare for smallness against. + * @param value the value to check for smallness. * * @return {@code true} if {@code value} is less than {@code baseValue}. * @@ -415,10 +462,8 @@ public final static boolean isLessThan(float baseValue, float value) { * NOTE: This method uses * {@link Double#compare(double, double)} to compare the given values. * - * @param baseValue - * the value to compare for smallness against. - * @param value - * the value to check for smallness. + * @param baseValue the value to compare for smallness against. + * @param value the value to check for smallness. * * @return {@code true} if {@code value} is less than {@code baseValue}. * @@ -433,15 +478,12 @@ public final static boolean isLessThan(double baseValue, double value) { * {@code true} if the given {@code BigDecimal} is less than the supplied base * value. * - * @param baseValue - * the value to compare for smallness against. - * @param value - * the value to check for smallness. + * @param baseValue the value to compare for smallness against. + * @param value the value to check for smallness. * * @return {@code true} if {@code value} is less than {@code baseValue}. * - * @throws NullPointerException - * if any of the two arguments is/are {@code null}. + * @throws NullPointerException if any of the two arguments is/are {@code null}. * * @since 1.1.0 */ @@ -450,19 +492,16 @@ public final static boolean isLessThan(BigDecimal baseValue, BigDecimal value) { .compareTo(requireNonNull(baseValue, "baseValue cannot be null.")) < 0; } - /* - * ------------------------------------ IS LESS THAN OR EQUAL TO - * ------------------------------------ - */ + // ======================================================================== + // IS LESS THAN OR EQUAL TO CHECKS + // ======================================================================== /** * Checks if an {@code int} is less than or equal to a supplied base value. * Returns {@code true} if the given {@code int} is less than or equal to the * supplied base value. * - * @param baseValue - * the value to compare for smallness or equality against. - * @param value - * the value to check for smallness or equality. + * @param baseValue the value to compare for smallness or equality against. + * @param value the value to check for smallness or equality. * * @return {@code true} if {@code value} is less than or equal to * {@code baseValue}. @@ -478,10 +517,8 @@ public final static boolean isLessThanOrEqualTo(int baseValue, int value) { * Returns {@code true} if the given {@code long} is less than or equal to the * supplied base value. * - * @param baseValue - * the value to compare for smallness or equality against. - * @param value - * the value to check for smallness or equality. + * @param baseValue the value to compare for smallness or equality against. + * @param value the value to check for smallness or equality. * * @return {@code true} if {@code value} is less than or equal to * {@code baseValue}. @@ -500,10 +537,8 @@ public final static boolean isLessThanOrEqualTo(long baseValue, long value) { * NOTE: This method uses * {@link Float#compare(float, float)} to compare the given values. * - * @param baseValue - * the value to compare for smallness or equality against. - * @param value - * the value to check for smallness or equality. + * @param baseValue the value to compare for smallness or equality against. + * @param value the value to check for smallness or equality. * * @return {@code true} if {@code value} is less than or equal to * {@code baseValue}. @@ -522,10 +557,8 @@ public final static boolean isLessThanOrEqualTo(float baseValue, float value) { * NOTE: This method uses * {@link Double#compare(double, double)} to compare the given values. * - * @param baseValue - * the value to compare for smallness or equality against. - * @param value - * the value to check for smallness or equality. + * @param baseValue the value to compare for smallness or equality against. + * @param value the value to check for smallness or equality. * * @return {@code true} if {@code value} is less than or equal to * {@code baseValue}. @@ -541,16 +574,13 @@ public final static boolean isLessThanOrEqualTo(double baseValue, double value) * value. Returns {@code true} if the given {@code BigDecimal} is less than or * equal to the supplied base value. * - * @param baseValue - * the value to compare for smallness or equality against. - * @param value - * the value to check for smallness or equality. + * @param baseValue the value to compare for smallness or equality against. + * @param value the value to check for smallness or equality. * * @return {@code true} if {@code value} is less than or equal to * {@code baseValue}. * - * @throws NullPointerException - * if any of the two arguments is/are {@code null}. + * @throws NullPointerException if any of the two arguments is/are {@code null}. * * @since 1.1.0 */ @@ -559,10 +589,9 @@ public final static boolean isLessThanOrEqualTo(BigDecimal baseValue, BigDecimal .compareTo(requireNonNull(baseValue, "baseValue cannot be null.")) <= 0; } - /* - * ------------------------------------ IN RANGE - * ------------------------------------ - */ + // ======================================================================== + // IN RANGE CHECKS + // ======================================================================== /** * Checks that the specified Integer is in range of the specified * minimum value (inclusive) and maximum value (exclusive). Returns @@ -571,19 +600,16 @@ public final static boolean isLessThanOrEqualTo(BigDecimal baseValue, BigDecimal * otherwise. An {@link IllegalArgumentException} will be thrown if the maximum * value is less than the minimum value. * - * @param minValue - * the minimum value(inclusive) of the range. - * @param maxValue - * the maximum value(exclusive) of the range. - * @param value - * the integer to check. + * @param minValue the minimum value(inclusive) of the range. + * @param maxValue the maximum value(exclusive) of the range. + * @param value the integer to check. * * @return true if value is greater than or equal to * minValue and less than maxValue, * false otherwise. * - * @throws IllegalArgumentException - * if maxValue is less than minValue. + * @throws IllegalArgumentException if maxValue is less than + * minValue. */ public final static boolean inRange(int minValue, int maxValue, int value) { requireGreaterThanOrEqualTo(minValue, maxValue, @@ -599,19 +625,16 @@ public final static boolean inRange(int minValue, int maxValue, int value) { * otherwise. An {@link IllegalArgumentException} will be thrown if the maximum * value is less than the minimum value. * - * @param minValue - * the minimum value(inclusive) of the range. - * @param maxValue - * the maximum value(exclusive) of the range. - * @param value - * the long to check. + * @param minValue the minimum value(inclusive) of the range. + * @param maxValue the maximum value(exclusive) of the range. + * @param value the long to check. * * @return true if value is greater than or equal to * minValue and less than maxValue, * false otherwise. * - * @throws IllegalArgumentException - * if maxValue is less than minValue. + * @throws IllegalArgumentException if maxValue is less than + * minValue. */ public final static boolean inRange(long minValue, long maxValue, long value) { requireGreaterThanOrEqualTo(minValue, maxValue, @@ -627,19 +650,16 @@ public final static boolean inRange(long minValue, long maxValue, long value) { * otherwise. An {@link IllegalArgumentException} will be thrown if the maximum * value is less than the minimum value. * - * @param minValue - * the minimum value(inclusive) of the range. - * @param maxValue - * the maximum value(exclusive) of the range. - * @param value - * the float to check. + * @param minValue the minimum value(inclusive) of the range. + * @param maxValue the maximum value(exclusive) of the range. + * @param value the float to check. * * @return true if value is greater than or equal to * minValue and less than maxValue, * false otherwise. * - * @throws IllegalArgumentException - * if maxValue is less than minValue. + * @throws IllegalArgumentException if maxValue is less than + * minValue. */ public final static boolean inRange(float minValue, float maxValue, float value) { requireGreaterThanOrEqualTo(minValue, maxValue, @@ -655,19 +675,16 @@ public final static boolean inRange(float minValue, float maxValue, float value) * otherwise. An {@link IllegalArgumentException} will be thrown if the maximum * value is less than the minimum value. * - * @param minValue - * the minimum value(inclusive) of the range. - * @param maxValue - * the maximum value(exclusive) of the range. - * @param value - * the double to check. + * @param minValue the minimum value(inclusive) of the range. + * @param maxValue the maximum value(exclusive) of the range. + * @param value the double to check. * * @return true if value is greater than or equal to * minValue and less than maxValue, * false otherwise. * - * @throws IllegalArgumentException - * if maxValue is less than minValue. + * @throws IllegalArgumentException if maxValue is less than + * minValue. */ public final static boolean inRange(double minValue, double maxValue, double value) { requireGreaterThanOrEqualTo(minValue, maxValue, @@ -683,21 +700,18 @@ public final static boolean inRange(double minValue, double maxValue, double val * otherwise. An {@link IllegalArgumentException} will be thrown if the maximum * value is less than the minimum value. * - * @param minValue - * the minimum value(inclusive) of the range. - * @param maxValue - * the maximum value(exclusive) of the range. - * @param value - * the BigDecimal to check. + * @param minValue the minimum value(inclusive) of the range. + * @param maxValue the maximum value(exclusive) of the range. + * @param value the BigDecimal to check. * * @return true if value is greater than or equal to * minValue and less than maxValue, * false otherwise. * - * @throws NullPointerException - * if any of the arguments passed are null. - * @throws IllegalArgumentException - * if maxValue is less than minValue. + * @throws NullPointerException if any of the arguments passed are + * null. + * @throws IllegalArgumentException if maxValue is less than + * minValue. */ public final static boolean inRange(BigDecimal minValue, BigDecimal maxValue, BigDecimal value) { requireGreaterThanOrEqualTo(minValue, maxValue, @@ -705,25 +719,243 @@ public final static boolean inRange(BigDecimal minValue, BigDecimal maxValue, Bi return isGreaterThanOrEqualTo(minValue, value) && isLessThan(maxValue, value); } - /* - * ------------------------------------ REQUIRE GREATER THAN - * ------------------------------------ + // ======================================================================== + // REQUIRE EQUAL TO VALIDATORS + // ======================================================================== + /** + * Validates that an {@code int} is equal to a supplied base value. Returns the + * given {@code int} if it is equal to the given base value, otherwise, an + * {@code IllegalArgumentException} is thrown. + * + * @param baseValue the value to compare for equality to. + * @param value the value to check for equality. + * + * @return {@code value} if {@code value} is equal to {@code baseValue}. + * + * @throws IllegalArgumentException if {@code value} is not equal to + * {@code baseValue}. + * + * @since 1.2.0 + */ + public final static int requireEqualTo(int baseValue, int value) { + return requireEqualTo(baseValue, value, null); + } + + /** + * Validates that an {@code int} is equal to a supplied base value. Returns the + * given {@code int} if it is equal to the given base value, otherwise, an + * {@code IllegalArgumentException} is thrown. + * + * @param baseValue the value to compare for equality to. + * @param value the value to check for equality. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. + * + * @return {@code value} if {@code value} is equal to {@code baseValue}. + * + * @throws IllegalArgumentException if {@code value} is not equal to + * {@code baseValue}. + * + * @since 1.2.0 + */ + public final static int requireEqualTo(int baseValue, int value, String message) { + if (!isEqualTo(baseValue, value)) + throw new IllegalArgumentException( + (nonNull(message) ? message : String.format("value(%d) should be equal to %d.", value, baseValue))); + return value; + } + + /** + * Validates that a {@code long} is equal to a supplied base value. Returns the + * given {@code long} if it is equal to the given base value, otherwise, an + * {@code IllegalArgumentException} is thrown. + * + * @param baseValue the value to compare for equality to. + * @param value the value to check for equality. + * + * @return {@code value} if {@code value} is equal to {@code baseValue}. + * + * @throws IllegalArgumentException if {@code value} is not equal to + * {@code baseValue}. + * + * @since 1.2.0 + */ + public final static long requireEqualTo(long baseValue, long value) { + return requireEqualTo(baseValue, value, null); + } + + /** + * Validates that a {@code long} is equal to a supplied base value. Returns the + * given {@code long} if it is equal to the given base value, otherwise, an + * {@code IllegalArgumentException} is thrown. + * + * @param baseValue the value to compare for equality to. + * @param value the value to check for equality. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. + * + * @return {@code value} if {@code value} is equal to {@code baseValue}. + * + * @throws IllegalArgumentException if {@code value} is not equal to + * {@code baseValue}. + * + * @since 1.2.0 + */ + public final static long requireEqualTo(long baseValue, long value, String message) { + if (!isEqualTo(baseValue, value)) + throw new IllegalArgumentException( + (nonNull(message) ? message : String.format("value(%d) should be equal to %d.", value, baseValue))); + return value; + } + + /** + * Validates that a {@code long} is equal to a supplied base value. Returns the + * given {@code long} if it is equal to the given base value, otherwise, an + * {@code IllegalArgumentException} is thrown. + * + * @param baseValue the value to compare for equality to. + * @param value the value to check for equality. + * + * @return {@code value} if {@code value} is equal to {@code baseValue}. + * + * @throws IllegalArgumentException if {@code value} is not equal to + * {@code baseValue}. + * + * @since 1.2.0 + */ + public final static float requireEqualTo(float baseValue, float value) { + return requireEqualTo(baseValue, value, null); + } + + /** + * Validates that a {@code float} is equal to a supplied base value. Returns the + * given {@code float} if it is equal to the given base value, otherwise, an + * {@code IllegalArgumentException} is thrown. + * + * @param baseValue the value to compare for equality to. + * @param value the value to check for equality. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. + * + * @return {@code value} if {@code value} is equal to {@code baseValue}. + * + * @throws IllegalArgumentException if {@code value} is not equal to + * {@code baseValue}. + * + * @since 1.2.0 + */ + public final static float requireEqualTo(float baseValue, float value, String message) { + if (!isEqualTo(baseValue, value)) + throw new IllegalArgumentException( + (nonNull(message) ? message : String.format("value(%f) should be equal to %f.", value, baseValue))); + return value; + } + + /** + * Validates that a {@code double} is equal to a supplied base value. Returns + * the given {@code double} if it is equal to the given base value, otherwise, + * an {@code IllegalArgumentException} is thrown. + * + * @param baseValue the value to compare for equality to. + * @param value the value to check for equality. + * + * @return {@code value} if {@code value} is equal to {@code baseValue}. + * + * @throws IllegalArgumentException if {@code value} is not equal to + * {@code baseValue}. + * + * @since 1.2.0 + */ + public final static double requireEqualTo(double baseValue, double value) { + return requireEqualTo(baseValue, value, null); + } + + /** + * Validates that a {@code double} is equal to a supplied base value. Returns + * the given {@code double} if it is equal to the given base value, otherwise, + * an {@code IllegalArgumentException} is thrown. + * + * @param baseValue the value to compare for equality to. + * @param value the value to check for equality. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. + * + * @return {@code value} if {@code value} is equal to {@code baseValue}. + * + * @throws IllegalArgumentException if {@code value} is not equal to + * {@code baseValue}. + * + * @since 1.2.0 + */ + public final static double requireEqualTo(double baseValue, double value, String message) { + if (!isEqualTo(baseValue, value)) + throw new IllegalArgumentException( + (nonNull(message) ? message : String.format("value(%f) should be equal to %f.", value, baseValue))); + return value; + } + + /** + * Validates that a {@link BigDecimal} is equal to a supplied base value. + * Returns the given {@code BigDecimal} if it is equal to the given base value, + * otherwise, an {@code IllegalArgumentException} is thrown. + * + * @param baseValue the value to compare for equality to. + * @param value the value to check for equality. + * + * @return {@code value} if {@code value} is equal to {@code baseValue}. + * + * @throws IllegalArgumentException if {@code value} is not equal to + * {@code baseValue}. + * @throws NullPointerException if {@code baseValue} or/and {@code value} + * is/are {@code null}. + * + * @since 1.2.0 */ + public final static BigDecimal requireEqualTo(BigDecimal baseValue, BigDecimal value) { + return requireEqualTo(baseValue, value, null); + } + /** + * Validates that a {@link BigDecimal} is equal to a supplied base value. + * Returns the given {@code BigDecimal} if it is equal to the given base value, + * otherwise, an {@code IllegalArgumentException} is thrown. + * + * @param baseValue the value to compare for equality to. + * @param value the value to check for equality. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. + * + * @return {@code value} if {@code value} is equal to {@code baseValue}. + * + * @throws IllegalArgumentException if {@code value} is not equal to + * {@code baseValue}. + * @throws NullPointerException if {@code baseValue} or/and {@code value} + * is/are {@code null}. + * + * @since 1.2.0 + */ + public final static BigDecimal requireEqualTo(BigDecimal baseValue, BigDecimal value, String message) { + if (!isEqualTo(baseValue, value)) + throw new IllegalArgumentException( + (nonNull(message) ? message : String.format("value(%s) should be equal to %s.", value, baseValue))); + return value; + } + + // ======================================================================== + // REQUIRE GREATER THAN VALIDATORS + // ======================================================================== /** * Validates that an {@code int} is greater than a supplied base value. Returns * the given {@code int} if it is greater than the given base value, otherwise, * an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness against. - * @param value - * the value to check for greatness. + * @param baseValue the value to compare for greatness against. + * @param value the value to check for greatness. * * @return {@code value} if {@code value} is greater than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. * * @since 1.1.0 */ @@ -736,18 +968,15 @@ public final static int requireGreaterThan(int baseValue, int value) { * the given {@code int} if it is greater than the given base value, otherwise, * an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness against. - * @param value - * the value to check for greatness. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for greatness against. + * @param value the value to check for greatness. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is greater than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. * * @since 1.1.0 */ @@ -763,15 +992,13 @@ public final static int requireGreaterThan(int baseValue, int value, String mess * the given {@code long} if it is greater than the given base value, otherwise, * an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness against. - * @param value - * the value to check for greatness. + * @param baseValue the value to compare for greatness against. + * @param value the value to check for greatness. * * @return {@code value} if {@code value} is greater than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. * * @since 1.1.0 */ @@ -784,18 +1011,15 @@ public final static long requireGreaterThan(long baseValue, long value) { * the given {@code long} if it is greater than the given base value, otherwise, * an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness against. - * @param value - * the value to check for greatness. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for greatness against. + * @param value the value to check for greatness. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is greater than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. * * @since 1.1.0 */ @@ -811,15 +1035,13 @@ public final static long requireGreaterThan(long baseValue, long value, String m * the given {@code float} if it is greater than the given base value, * otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness against. - * @param value - * the value to check for greatness. + * @param baseValue the value to compare for greatness against. + * @param value the value to check for greatness. * * @return {@code value} if {@code value} is greater than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. * * @since 1.1.0 */ @@ -832,18 +1054,15 @@ public final static float requireGreaterThan(float baseValue, float value) { * the given {@code float} if it is greater than the given base value, * otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness against. - * @param value - * the value to check for greatness. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for greatness against. + * @param value the value to check for greatness. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is greater than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. * * @since 1.1.0 */ @@ -859,15 +1078,13 @@ public final static float requireGreaterThan(float baseValue, float value, Strin * Returns the given {@code double} if it is greater than the given base value, * otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness against. - * @param value - * the value to check for greatness. + * @param baseValue the value to compare for greatness against. + * @param value the value to check for greatness. * * @return {@code value} if {@code value} is greater than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. * * @since 1.1.0 */ @@ -880,18 +1097,15 @@ public final static double requireGreaterThan(double baseValue, double value) { * Returns the given {@code double} if it is greater than the given base value, * otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness against. - * @param value - * the value to check for greatness. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for greatness against. + * @param value the value to check for greatness. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is greater than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. * * @since 1.1.0 */ @@ -907,17 +1121,15 @@ public final static double requireGreaterThan(double baseValue, double value, St * Returns the given {@code BigDecimal} if it is greater than the given base * value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness against. - * @param value - * the value to check for greatness. + * @param baseValue the value to compare for greatness against. + * @param value the value to check for greatness. * * @return {@code value} if {@code value} is greater than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. - * @throws NullPointerException - * if {@code baseValue} or/and {@code value} is/are {@code null}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. + * @throws NullPointerException if {@code baseValue} or/and {@code value} + * is/are {@code null}. * * @since 1.1.0 */ @@ -930,20 +1142,17 @@ public final static BigDecimal requireGreaterThan(BigDecimal baseValue, BigDecim * Returns the given {@code BigDecimal} if it is greater than the given base * value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness against. - * @param value - * the value to check for greatness. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for greatness against. + * @param value the value to check for greatness. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is greater than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. - * @throws NullPointerException - * if {@code baseValue} or/and {@code value} is/are {@code null}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. + * @throws NullPointerException if {@code baseValue} or/and {@code value} + * is/are {@code null}. * * @since 1.1.0 */ @@ -954,26 +1163,22 @@ public final static BigDecimal requireGreaterThan(BigDecimal baseValue, BigDecim return value; } - /* - * ------------------------------------ REQUIRE GREATER THAN OR EQUAL TO - * ------------------------------------ - */ - + // ======================================================================== + // REQUIRE GREATER THAN OR EQUAL TO VALIDATORS + // ======================================================================== /** * Validates that an {@code int} is greater than or equal to a supplied base * value. Returns the given {@code int} if it is greater than or equal to the * given base value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness or equality against. - * @param value - * the value to check for greatness or equality. + * @param baseValue the value to compare for greatness or equality against. + * @param value the value to check for greatness or equality. * * @return {@code value} if {@code value} is greater than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. * * @since 1.1.0 */ @@ -986,19 +1191,16 @@ public final static int requireGreaterThanOrEqualTo(int baseValue, int value) { * value. Returns the given {@code int} if it is greater than or equal to the * given base value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness or equality against. - * @param value - * the value to check for greatness or equality. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for greatness or equality against. + * @param value the value to check for greatness or equality. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is greater than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. * * @since 1.1.0 */ @@ -1014,16 +1216,14 @@ public final static int requireGreaterThanOrEqualTo(int baseValue, int value, St * value. Returns the given {@code long} if it is greater than or equal to the * given base value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness or equality against. - * @param value - * the value to check for greatness or equality. + * @param baseValue the value to compare for greatness or equality against. + * @param value the value to check for greatness or equality. * * @return {@code value} if {@code value} is greater than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. * * @since 1.1.0 */ @@ -1036,19 +1236,16 @@ public final static long requireGreaterThanOrEqualTo(long baseValue, long value) * value. Returns the given {@code long} if it is greater than or equal to the * given base value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness or equality against. - * @param value - * the value to check for greatness or equality. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for greatness or equality against. + * @param value the value to check for greatness or equality. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is greater than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. * * @since 1.1.0 */ @@ -1064,16 +1261,14 @@ public final static long requireGreaterThanOrEqualTo(long baseValue, long value, * value. Returns the given {@code float} if it is greater than or equal to the * given base value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness or equality against. - * @param value - * the value to check for greatness or equality. + * @param baseValue the value to compare for greatness or equality against. + * @param value the value to check for greatness or equality. * * @return {@code value} if {@code value} is greater than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. * * @since 1.1.0 */ @@ -1086,19 +1281,16 @@ public final static float requireGreaterThanOrEqualTo(float baseValue, float val * value. Returns the given {@code float} if it is greater than or equal to the * given base value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness or equality against. - * @param value - * the value to check for greatness or equality. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for greatness or equality against. + * @param value the value to check for greatness or equality. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is greater than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. * * @since 1.1.0 */ @@ -1114,16 +1306,14 @@ public final static float requireGreaterThanOrEqualTo(float baseValue, float val * value. Returns the given {@code double} if it is greater than or equal to the * given base value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness or equality against. - * @param value - * the value to check for greatness or equality. + * @param baseValue the value to compare for greatness or equality against. + * @param value the value to check for greatness or equality. * * @return {@code value} if {@code value} is greater than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. * * @since 1.1.0 */ @@ -1136,19 +1326,16 @@ public final static double requireGreaterThanOrEqualTo(double baseValue, double * value. Returns the given {@code double} if it is greater than or equal to the * given base value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for greatness or equality against. - * @param value - * the value to check for greatness or equality. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for greatness or equality against. + * @param value the value to check for greatness or equality. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is greater than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. * * @since 1.1.0 */ @@ -1165,18 +1352,16 @@ public final static double requireGreaterThanOrEqualTo(double baseValue, double * equal to the given base value, otherwise, an {@code IllegalArgumentException} * is thrown. * - * @param baseValue - * the value to compare for greatness or equality against. - * @param value - * the value to check for greatness or equality. + * @param baseValue the value to compare for greatness or equality against. + * @param value the value to check for greatness or equality. * * @return {@code value} if {@code value} is greater than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. - * @throws NullPointerException - * if {@code baseValue} or/and {@code value} is/are {@code null}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. + * @throws NullPointerException if {@code baseValue} or/and {@code value} + * is/are {@code null}. * * @since 1.1.0 */ @@ -1190,21 +1375,18 @@ public final static BigDecimal requireGreaterThanOrEqualTo(BigDecimal baseValue, * equal to the given base value, otherwise, an {@code IllegalArgumentException} * is thrown. * - * @param baseValue - * the value to compare for greatness or equality against. - * @param value - * the value to check for greatness or equality. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for greatness or equality against. + * @param value the value to check for greatness or equality. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is greater than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is less than {@code baseValue}. - * @throws NullPointerException - * if {@code baseValue} or/and {@code value} is/are {@code null}. + * @throws IllegalArgumentException if {@code value} is less than + * {@code baseValue}. + * @throws NullPointerException if {@code baseValue} or/and {@code value} + * is/are {@code null}. * * @since 1.1.0 */ @@ -1215,10 +1397,9 @@ public final static BigDecimal requireGreaterThanOrEqualTo(BigDecimal baseValue, return value; } - /* - * ------------------------------------ REQUIRE IN RANGE - * ------------------------------------ - */ + // ======================================================================== + // REQUIRE IN RANGE VALIDATORS + // ======================================================================== /** * Validates that the specified {@code int} is in range of the specified minimum * value (inclusive) and maximum value @@ -1229,18 +1410,17 @@ public final static BigDecimal requireGreaterThanOrEqualTo(BigDecimal baseValue, * {@code IllegalArgumentException} will also be thrown if the maximum value is * less than the minimum value. * - * @param minValue - * the minimum value(inclusive) of the range. - * @param maxValue - * the maximum value(exclusive) of the range. - * @param value - * the {@code int} to check. + * @param minValue the minimum value(inclusive) of the + * range. + * @param maxValue the maximum value(exclusive) of the + * range. + * @param value the {@code int} to check. * * @return {@code value} if it is in the specified range. * - * @throws IllegalArgumentException - * if {@code value} is not in the specified range or if - * {@code maxValue} is less than {@code minValue}. + * @throws IllegalArgumentException if {@code value} is not in the specified + * range or if {@code maxValue} is less than + * {@code minValue}. */ public final static int requireInRange(int minValue, int maxValue, int value) { return requireInRange(minValue, maxValue, value, null); @@ -1257,21 +1437,19 @@ public final static int requireInRange(int minValue, int maxValue, int value) { * less than the minimum value. An optional message can also be given to be used * as the exception message. * - * @param minValue - * the minimum value(inclusive) of the range. - * @param maxValue - * the maximum value(exclusive) of the range. - * @param value - * the {@code int} to check. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param minValue the minimum value(inclusive) of the + * range. + * @param maxValue the maximum value(exclusive) of the + * range. + * @param value the {@code int} to check. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if it is in the specified range. * - * @throws IllegalArgumentException - * if {@code value} is not in the specified range or if - * {@code maxValue} is less than {@code minValue}. + * @throws IllegalArgumentException if {@code value} is not in the specified + * range or if {@code maxValue} is less than + * {@code minValue}. */ public final static int requireInRange(int minValue, int maxValue, int value, String message) { if (!inRange(minValue, maxValue, value)) @@ -1291,18 +1469,17 @@ public final static int requireInRange(int minValue, int maxValue, int value, St * {@code IllegalArgumentException} will also be thrown if the maximum value is * less than the minimum value. * - * @param minValue - * the minimum value(inclusive) of the range. - * @param maxValue - * the maximum value(exclusive) of the range. - * @param value - * the {@code long} to check. + * @param minValue the minimum value(inclusive) of the + * range. + * @param maxValue the maximum value(exclusive) of the + * range. + * @param value the {@code long} to check. * * @return {@code value} if it is in the specified range. * - * @throws IllegalArgumentException - * if {@code value} is not in the specified range or if - * {@code maxValue} is less than {@code minValue}. + * @throws IllegalArgumentException if {@code value} is not in the specified + * range or if {@code maxValue} is less than + * {@code minValue}. */ public final static long requireInRange(long minValue, long maxValue, long value) { return requireInRange(minValue, maxValue, value, null); @@ -1319,21 +1496,19 @@ public final static long requireInRange(long minValue, long maxValue, long value * less than the minimum value. An optional message can also be given to be used * as the exception message. * - * @param minValue - * the minimum value(inclusive) of the range. - * @param maxValue - * the maximum value(exclusive) of the range. - * @param value - * the {@code long} to check. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param minValue the minimum value(inclusive) of the + * range. + * @param maxValue the maximum value(exclusive) of the + * range. + * @param value the {@code long} to check. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if it is in the specified range. * - * @throws IllegalArgumentException - * if {@code value} is not in the specified range or if - * {@code maxValue} is less than {@code minValue}. + * @throws IllegalArgumentException if {@code value} is not in the specified + * range or if {@code maxValue} is less than + * {@code minValue}. */ public final static long requireInRange(long minValue, long maxValue, long value, String message) { if (!inRange(minValue, maxValue, value)) @@ -1353,18 +1528,17 @@ public final static long requireInRange(long minValue, long maxValue, long value * {@code IllegalArgumentException} will also be thrown if the maximum value is * less than the minimum value. * - * @param minValue - * the minimum value(inclusive) of the range. - * @param maxValue - * the maximum value(exclusive) of the range. - * @param value - * the {@code float} to check. + * @param minValue the minimum value(inclusive) of the + * range. + * @param maxValue the maximum value(exclusive) of the + * range. + * @param value the {@code float} to check. * * @return {@code value} if it is in the specified range. * - * @throws IllegalArgumentException - * if {@code value} is not in the specified range or if - * {@code maxValue} is less than {@code minValue}. + * @throws IllegalArgumentException if {@code value} is not in the specified + * range or if {@code maxValue} is less than + * {@code minValue}. */ public final static float requireInRange(float minValue, float maxValue, float value) { return requireInRange(minValue, maxValue, value, null); @@ -1381,21 +1555,19 @@ public final static float requireInRange(float minValue, float maxValue, float v * less than the minimum value. An optional message can also be given to be used * as the exception message. * - * @param minValue - * the minimum value(inclusive) of the range. - * @param maxValue - * the maximum value(exclusive) of the range. - * @param value - * the {@code float} to check. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param minValue the minimum value(inclusive) of the + * range. + * @param maxValue the maximum value(exclusive) of the + * range. + * @param value the {@code float} to check. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if it is in the specified range. * - * @throws IllegalArgumentException - * if {@code value} is not in the specified range or if - * {@code maxValue} is less than {@code minValue}. + * @throws IllegalArgumentException if {@code value} is not in the specified + * range or if {@code maxValue} is less than + * {@code minValue}. */ public final static float requireInRange(float minValue, float maxValue, float value, String message) { if (!inRange(minValue, maxValue, value)) @@ -1415,18 +1587,17 @@ public final static float requireInRange(float minValue, float maxValue, float v * {@code IllegalArgumentException} will also be thrown if the maximum value is * less than the minimum value. * - * @param minValue - * the minimum value(inclusive) of the range. - * @param maxValue - * the maximum value(exclusive) of the range. - * @param value - * the {@code double} to check. + * @param minValue the minimum value(inclusive) of the + * range. + * @param maxValue the maximum value(exclusive) of the + * range. + * @param value the {@code double} to check. * * @return {@code value} if it is in the specified range. * - * @throws IllegalArgumentException - * if {@code value} is not in the specified range or if - * {@code maxValue} is less than {@code minValue}. + * @throws IllegalArgumentException if {@code value} is not in the specified + * range or if {@code maxValue} is less than + * {@code minValue}. */ public final static double requireInRange(double minValue, double maxValue, double value) { return requireInRange(minValue, maxValue, value, null); @@ -1443,21 +1614,19 @@ public final static double requireInRange(double minValue, double maxValue, doub * less than the minimum value. An optional message can also be given to be used * as the exception message. * - * @param minValue - * the minimum value(inclusive) of the range. - * @param maxValue - * the maximum value(exclusive) of the range. - * @param value - * the {@code double} to check. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param minValue the minimum value(inclusive) of the + * range. + * @param maxValue the maximum value(exclusive) of the + * range. + * @param value the {@code double} to check. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if it is in the specified range. * - * @throws IllegalArgumentException - * if {@code value} is not in the specified range or if - * {@code maxValue} is less than {@code minValue}. + * @throws IllegalArgumentException if {@code value} is not in the specified + * range or if {@code maxValue} is less than + * {@code minValue}. */ public final static double requireInRange(double minValue, double maxValue, double value, String message) { if (!inRange(minValue, maxValue, value)) @@ -1477,20 +1646,18 @@ public final static double requireInRange(double minValue, double maxValue, doub * {@code IllegalArgumentException} will also be thrown if the maximum value is * less than the minimum value. * - * @param minValue - * the minimum value(inclusive) of the range. - * @param maxValue - * the maximum value(exclusive) of the range. - * @param value - * the {@code BigDecimal} to check. + * @param minValue the minimum value(inclusive) of the + * range. + * @param maxValue the maximum value(exclusive) of the + * range. + * @param value the {@code BigDecimal} to check. * * @return {@code value} if it is in the specified range. * - * @throws IllegalArgumentException - * if {@code value} is not in the specified range or if - * {@code maxValue} is less than {@code minValue}. - * @throws NullPointerException - * if any of the arguments is/are {@code null}. + * @throws IllegalArgumentException if {@code value} is not in the specified + * range or if {@code maxValue} is less than + * {@code minValue}. + * @throws NullPointerException if any of the arguments is/are {@code null}. * * @see BigDecimal */ @@ -1509,23 +1676,21 @@ public final static BigDecimal requireInRange(BigDecimal minValue, BigDecimal ma * less than the minimum value. An optional message can also be given to be used * as the exception message. * - * @param minValue - * the minimum value(inclusive) of the range. - * @param maxValue - * the maximum value(exclusive) of the range. - * @param value - * the {@code BigDecimal} to check. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param minValue the minimum value(inclusive) of the + * range. + * @param maxValue the maximum value(exclusive) of the + * range. + * @param value the {@code BigDecimal} to check. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if it is in the specified range. * - * @throws IllegalArgumentException - * if {@code value} is not in the specified range or if - * {@code maxValue} is less than {@code minValue}. - * @throws NullPointerException - * if any of the first three arguments is/are {@code null}. + * @throws IllegalArgumentException if {@code value} is not in the specified + * range or if {@code maxValue} is less than + * {@code minValue}. + * @throws NullPointerException if any of the first three arguments is/are + * {@code null}. * * @see BigDecimal */ @@ -1538,22 +1703,19 @@ public final static BigDecimal requireInRange(BigDecimal minValue, BigDecimal ma return value; } - /* - * ------------------------------------ REQUIRE NON NEGATIVE - * ------------------------------------ - */ + // ======================================================================== + // REQUIRE NON NEGATIVE VALIDATORS + // ======================================================================== /** * Validates that the specified {@code int} is not negative, i.e less than zero. * If {@code value} is negative, an {@code IllegalArgumentException} is thrown, * otherwise, {@code value} is returned. * - * @param value - * the {@code int} to check. + * @param value the {@code int} to check. * * @return {@code value} if it is NOT negative. * - * @throws IllegalArgumentException - * if {@code value} is negative. + * @throws IllegalArgumentException if {@code value} is negative. */ public final static int requireNonNegative(int value) { return requireNonNegative(value, null); @@ -1565,16 +1727,13 @@ public final static int requireNonNegative(int value) { * otherwise, {@code value} is returned. An optional message can also be passed * to be used as the {@code IllegalArgumentException} message. * - * @param value - * the {@code int} to check. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param value the {@code int} to check. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if it is NOT negative. * - * @throws IllegalArgumentException - * if {@code value} is negative + * @throws IllegalArgumentException if {@code value} is negative */ public final static int requireNonNegative(int value, String message) { if (isNegative(value)) @@ -1587,13 +1746,11 @@ public final static int requireNonNegative(int value, String message) { * zero. If {@code value} is negative, an {@code IllegalArgumentException} is * thrown, otherwise, {@code value} is returned. * - * @param value - * the {@code long} to check. + * @param value the {@code long} to check. * * @return {@code value} if it is NOT negative. * - * @throws IllegalArgumentException - * if {@code value} is negative. + * @throws IllegalArgumentException if {@code value} is negative. */ public final static long requireNonNegative(long value) { return requireNonNegative(value, null); @@ -1605,16 +1762,13 @@ public final static long requireNonNegative(long value) { * thrown, otherwise, {@code value} is returned. An optional message can also be * passed to be used as the {@code IllegalArgumentException} message. * - * @param value - * the {@code long} to check. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param value the {@code long} to check. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if it is NOT negative. * - * @throws IllegalArgumentException - * if {@code value} is negative + * @throws IllegalArgumentException if {@code value} is negative */ public final static long requireNonNegative(long value, String message) { if (isNegative(value)) @@ -1627,13 +1781,11 @@ public final static long requireNonNegative(long value, String message) { * zero. If {@code value} is negative, an {@code IllegalArgumentException} is * thrown, otherwise, {@code value} is returned. * - * @param value - * the {@code float} to check. + * @param value the {@code float} to check. * * @return {@code value} if it is NOT negative. * - * @throws IllegalArgumentException - * if {@code value} is negative. + * @throws IllegalArgumentException if {@code value} is negative. */ public final static float requireNonNegative(float value) { return requireNonNegative(value, null); @@ -1645,16 +1797,13 @@ public final static float requireNonNegative(float value) { * thrown, otherwise, {@code value} is returned. An optional message can also be * passed to be used as the {@code IllegalArgumentException} message. * - * @param value - * the {@code float} to check. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param value the {@code float} to check. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if it is NOT negative. * - * @throws IllegalArgumentException - * if {@code value} is negative + * @throws IllegalArgumentException if {@code value} is negative */ public final static float requireNonNegative(float value, String message) { if (isNegative(value)) @@ -1667,13 +1816,11 @@ public final static float requireNonNegative(float value, String message) { * zero. If {@code value} is negative, an {@code IllegalArgumentException} is * thrown, otherwise, {@code value} is returned. * - * @param value - * the {@code double} to check. + * @param value the {@code double} to check. * * @return {@code value} if it is NOT negative. * - * @throws IllegalArgumentException - * if {@code value} is negative. + * @throws IllegalArgumentException if {@code value} is negative. */ public final static double requireNonNegative(double value) { return requireNonNegative(value, null); @@ -1685,16 +1832,13 @@ public final static double requireNonNegative(double value) { * thrown, otherwise, {@code value} is returned. An optional message can also be * passed to be used as the {@code IllegalArgumentException} message. * - * @param value - * the {@code double} to check. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param value the {@code double} to check. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if it is NOT negative. * - * @throws IllegalArgumentException - * if {@code value} is negative + * @throws IllegalArgumentException if {@code value} is negative */ public final static double requireNonNegative(double value, String message) { if (isNegative(value)) @@ -1707,15 +1851,12 @@ public final static double requireNonNegative(double value, String message) { * than zero. If {@code value} is negative, an {@code IllegalArgumentException} * is thrown, otherwise, {@code value} is returned. * - * @param value - * the {@code BigDecimal} to check. + * @param value the {@code BigDecimal} to check. * * @return {@code value} if it is NOT negative. * - * @throws IllegalArgumentException - * if {@code value} is negative. - * @throws NullPointerException - * if value is {@code null}. + * @throws IllegalArgumentException if {@code value} is negative. + * @throws NullPointerException if value is {@code null}. * * @see BigDecimal */ @@ -1729,18 +1870,14 @@ public final static BigDecimal requireNonNegative(BigDecimal value) { * is thrown, otherwise, {@code value} is returned. An optional message can also * be passed to be used as the {@code IllegalArgumentException} message. * - * @param value - * the {@code BigDecimal} to check. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param value the {@code BigDecimal} to check. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if it is NOT negative. * - * @throws IllegalArgumentException - * if {@code value} is negative - * @throws NullPointerException - * if value is {@code null}. + * @throws IllegalArgumentException if {@code value} is negative + * @throws NullPointerException if value is {@code null}. * * @see BigDecimal */ @@ -1750,25 +1887,21 @@ public final static BigDecimal requireNonNegative(BigDecimal value, String messa return value; } - /* - * ------------------------------------ REQUIRE LESS THAN - * ------------------------------------ - */ - + // ======================================================================== + // REQUIRE LESS THAN VALIDATORS + // ======================================================================== /** * Validates that an {@code int} is less than a supplied base value. Returns the * given {@code int} if it is less than the given base value, otherwise, an * {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness against. - * @param value - * the value to check for smallness. + * @param baseValue the value to compare for smallness against. + * @param value the value to check for smallness. * * @return {@code value} if {@code value} is less than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. * * @since 1.1.0 */ @@ -1781,18 +1914,15 @@ public final static int requireLessThan(int baseValue, int value) { * given {@code int} if it is less than the given base value, otherwise, an * {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness against. - * @param value - * the value to check for smallness. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for smallness against. + * @param value the value to check for smallness. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is less than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. * * @since 1.1.0 */ @@ -1808,15 +1938,13 @@ public final static int requireLessThan(int baseValue, int value, String message * given {@code long} if it is less than the given base value, otherwise, an * {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness against. - * @param value - * the value to check for smallness. + * @param baseValue the value to compare for smallness against. + * @param value the value to check for smallness. * * @return {@code value} if {@code value} is less than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. * * @since 1.1.0 */ @@ -1829,18 +1957,15 @@ public final static long requireLessThan(long baseValue, long value) { * given {@code long} if it is less than the given base value, otherwise, an * {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness against. - * @param value - * the value to check for smallness. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for smallness against. + * @param value the value to check for smallness. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is less than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. * * @since 1.1.0 */ @@ -1856,15 +1981,13 @@ public final static long requireLessThan(long baseValue, long value, String mess * the given {@code float} if it is less than the given base value, otherwise, * an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness against. - * @param value - * the value to check for smallness. + * @param baseValue the value to compare for smallness against. + * @param value the value to check for smallness. * * @return {@code value} if {@code value} is less than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. * * @since 1.1.0 */ @@ -1877,18 +2000,15 @@ public final static float requireLessThan(float baseValue, float value) { * the given {@code float} if it is less than the given base value, otherwise, * an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness against. - * @param value - * the value to check for smallness. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for smallness against. + * @param value the value to check for smallness. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is less than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. * * @since 1.1.0 */ @@ -1904,15 +2024,13 @@ public final static float requireLessThan(float baseValue, float value, String m * the given {@code long} if it is less than the given base value, otherwise, an * {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness against. - * @param value - * the value to check for smallness. + * @param baseValue the value to compare for smallness against. + * @param value the value to check for smallness. * * @return {@code value} if {@code value} is less than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. * * @since 1.1.0 */ @@ -1925,18 +2043,15 @@ public final static double requireLessThan(double baseValue, double value) { * the given {@code double} if it is less than the given base value, otherwise, * an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness against. - * @param value - * the value to check for smallness. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for smallness against. + * @param value the value to check for smallness. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is less than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. * * @since 1.1.0 */ @@ -1952,17 +2067,15 @@ public final static double requireLessThan(double baseValue, double value, Strin * Returns the given {@code BigDecimal} if it is less than the given base value, * otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness against. - * @param value - * the value to check for smallness. + * @param baseValue the value to compare for smallness against. + * @param value the value to check for smallness. * * @return {@code value} if {@code value} is less than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. - * @throws NullPointerException - * if {@code baseValue} or/and {@code value} is/are {@code null}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. + * @throws NullPointerException if {@code baseValue} or/and {@code value} + * is/are {@code null}. * * @since 1.1.0 */ @@ -1975,20 +2088,17 @@ public final static BigDecimal requireLessThan(BigDecimal baseValue, BigDecimal * Returns the given {@code BigDecimal} if it is less than the given base value, * otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness against. - * @param value - * the value to check for smallness. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for smallness against. + * @param value the value to check for smallness. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is less than {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. - * @throws NullPointerException - * if {@code baseValue} or/and {@code value} is/are {@code null}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. + * @throws NullPointerException if {@code baseValue} or/and {@code value} + * is/are {@code null}. * * @since 1.1.0 */ @@ -1999,26 +2109,22 @@ public final static BigDecimal requireLessThan(BigDecimal baseValue, BigDecimal return value; } - /* - * ------------------------------------ REQUIRE LESS THAN OR EQUAL TO - * ------------------------------------ - */ - + // ======================================================================== + // REQUIRE LESS THAN OR EQUAL TO VALIDATORS + // ======================================================================== /** * Validates that an {@code int} is less than or equal to a supplied base value. * Returns the given {@code int} if it is less than or equal to the given base * value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness or equality against. - * @param value - * the value to check for smallness or equality. + * @param baseValue the value to compare for smallness or equality against. + * @param value the value to check for smallness or equality. * * @return {@code value} if {@code value} is less than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. * * @since 1.1.0 */ @@ -2031,19 +2137,16 @@ public final static int requireLessThanOrEqualTo(int baseValue, int value) { * Returns the given {@code int} if it is less than or equal to the given base * value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness or equality against. - * @param value - * the value to check for smallness or equality. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for smallness or equality against. + * @param value the value to check for smallness or equality. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is less than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. * * @since 1.1.0 */ @@ -2059,16 +2162,14 @@ public final static int requireLessThanOrEqualTo(int baseValue, int value, Strin * Returns the given {@code long} if it is less than or equal to the given base * value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness or equality against. - * @param value - * the value to check for smallness or equality. + * @param baseValue the value to compare for smallness or equality against. + * @param value the value to check for smallness or equality. * * @return {@code value} if {@code value} is less than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. * * @since 1.1.0 */ @@ -2081,19 +2182,16 @@ public final static long requireLessThanOrEqualTo(long baseValue, long value) { * Returns the given {@code long} if it is less than or equal to the given base * value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness or equality against. - * @param value - * the value to check for smallness or equality. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for smallness or equality against. + * @param value the value to check for smallness or equality. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is less than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. * * @since 1.1.0 */ @@ -2109,16 +2207,14 @@ public final static long requireLessThanOrEqualTo(long baseValue, long value, St * value. Returns the given {@code float} if it is less than or equal to the * given base value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness or equality against. - * @param value - * the value to check for smallness or equality. + * @param baseValue the value to compare for smallness or equality against. + * @param value the value to check for smallness or equality. * * @return {@code value} if {@code value} is less than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. * * @since 1.1.0 */ @@ -2131,19 +2227,16 @@ public final static float requireLessThanOrEqualTo(float baseValue, float value) * value. Returns the given {@code float} if it is less than or equal to the * given base value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness or equality against. - * @param value - * the value to check for smallness or equality. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for smallness or equality against. + * @param value the value to check for smallness or equality. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is less than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. * * @since 1.1.0 */ @@ -2159,16 +2252,14 @@ public final static float requireLessThanOrEqualTo(float baseValue, float value, * value. Returns the given {@code double} if it is less than or equal to the * given base value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness or equality against. - * @param value - * the value to check for smallness or equality. + * @param baseValue the value to compare for smallness or equality against. + * @param value the value to check for smallness or equality. * * @return {@code value} if {@code value} is less than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. * * @since 1.1.0 */ @@ -2181,19 +2272,16 @@ public final static double requireLessThanOrEqualTo(double baseValue, double val * value. Returns the given {@code double} if it is less than or equal to the * given base value, otherwise, an {@code IllegalArgumentException} is thrown. * - * @param baseValue - * the value to compare for smallness or equality against. - * @param value - * the value to check for smallness or equality. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for smallness or equality against. + * @param value the value to check for smallness or equality. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is less than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. * * @since 1.1.0 */ @@ -2210,18 +2298,16 @@ public final static double requireLessThanOrEqualTo(double baseValue, double val * the given base value, otherwise, an {@code IllegalArgumentException} is * thrown. * - * @param baseValue - * the value to compare for smallness or equality against. - * @param value - * the value to check for smallness or equality. + * @param baseValue the value to compare for smallness or equality against. + * @param value the value to check for smallness or equality. * * @return {@code value} if {@code value} is less than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. - * @throws NullPointerException - * if {@code baseValue} or/and {@code value} is/are {@code null}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. + * @throws NullPointerException if {@code baseValue} or/and {@code value} + * is/are {@code null}. * * @since 1.1.0 */ @@ -2235,21 +2321,18 @@ public final static BigDecimal requireLessThanOrEqualTo(BigDecimal baseValue, Bi * the given base value, otherwise, an {@code IllegalArgumentException} is * thrown. * - * @param baseValue - * the value to compare for smallness or equality against. - * @param value - * the value to check for smallness or equality. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param baseValue the value to compare for smallness or equality against. + * @param value the value to check for smallness or equality. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value} is less than or equal to * {@code baseValue}. * - * @throws IllegalArgumentException - * if {@code value} is greater than {@code baseValue}. - * @throws NullPointerException - * if {@code baseValue} or/and {@code value} is/are {@code null}. + * @throws IllegalArgumentException if {@code value} is greater than + * {@code baseValue}. + * @throws NullPointerException if {@code baseValue} or/and {@code value} + * is/are {@code null}. * * @since 1.1.0 */ @@ -2260,27 +2343,21 @@ public final static BigDecimal requireLessThanOrEqualTo(BigDecimal baseValue, Bi return value; } - /*------------------------------------------------------------------------------------- - * - * SERIALIZABLES - * - * ------------------------------------------------------------------------------------ - */ + // ======================================================================== + // SERIALIZABLES UTILS + // ======================================================================== /** * Checks if a given instance is serializable, i.e implements the * {@link Serializable} interface. Returns true if the instance is * serializable, otherwise returns false. * - * @param - * the type of the instance to be checked for serializability + * @param the type of the instance to be checked for serializability * - * @param value - * the instance to check for serializability + * @param value the instance to check for serializability * @return true if value is serializable or false * otherwise. * - * @throws NullPointerException - * if value is null. + * @throws NullPointerException if value is null. * * @see Serializable */ @@ -2297,18 +2374,14 @@ public final static boolean isSerializable(T value) { * is thrown. Also a {@code NullPointerException} will also be thrown if the * supplied instance is {@code null}. * - * @param - * the type of the instance to be checked for serializability. + * @param the type of the instance to be checked for serializability. * - * @param value - * the instance to check for serializability. + * @param value the instance to check for serializability. * * @return {@code value} if it's not null AND is serializable. * - * @throws NullPointerException - * if {@code value} is {@code null}. - * @throws IllegalArgumentException - * if {@code value} is not serializable. + * @throws NullPointerException if {@code value} is {@code null}. + * @throws IllegalArgumentException if {@code value} is not serializable. * * @see #requireSerializable(Object, String) * @see Serializable @@ -2325,21 +2398,16 @@ public final static T requireSerializable(T value) { * supplied instance is {@code null}. A message can optionally be passed to be * used in the construction of the {@code IllegalArgumentException}. * - * @param - * the type of the instance to be checked for serializability. + * @param the type of the instance to be checked for serializability. * - * @param value - * the instance to check for serializability. - * @param message - * an optional message to be used as the - * {@code IllegalArgumentException} message. + * @param value the instance to check for serializability. + * @param message an optional message to be used as the + * {@code IllegalArgumentException} message. * * @return value if it's not null AND is serializable. * - * @throws NullPointerException - * if {@code value} is {@code null}. - * @throws IllegalArgumentException - * if {@code value} is not serializable. + * @throws NullPointerException if {@code value} is {@code null}. + * @throws IllegalArgumentException if {@code value} is not serializable. * * @see Serializable */ @@ -2349,12 +2417,9 @@ public final static T requireSerializable(T value, String message) { return value; } - /*------------------------------------------------------------------------------------- - * - * STRINGS - * - * ------------------------------------------------------------------------------------ - */ + // ======================================================================== + // STRINGS UTILS + // ======================================================================== /** * Checks that the given String has characters between the given * minimum chars (inclusive) and the given maximum chars (exclusive). Returns @@ -2368,22 +2433,18 @@ public final static T requireSerializable(T value, String message) { *
  • maxChars is equal to minChars
  • * * - * @param minChars - * the minimum number of characters (inclusive) that the given - * String should have. - * @param maxChars - * the maximum number of characters (exclusive) that the given - * String should have. - * @param value - * the String to check. + * @param minChars the minimum number of characters (inclusive) that the given + * String should have. + * @param maxChars the maximum number of characters (exclusive) that the given + * String should have. + * @param value the String to check. * * @return true if the given String's length falls * within the specified range, false otherwise. * - * @throws NullPointerException - * if value is null. - * @throws IllegalArgumentException - * if any of the conditions stated above are/is met. + * @throws NullPointerException if value is null. + * @throws IllegalArgumentException if any of the conditions stated above are/is + * met. */ public final static boolean hasCharsInRange(int minChars, int maxChars, String value) { requireGreaterThan(requireNonNegative(minChars), requireNonNegative(maxChars), @@ -2399,17 +2460,14 @@ public final static boolean hasCharsInRange(int minChars, int maxChars, String v * {@link IllegalArgumentException} will be thrown if maxChars is * negative. * - * @param maxChars - * the maximum number of characters (exclusive) that the given - * String should have. - * @param value - * the String to check. + * @param maxChars the maximum number of characters (exclusive) that the given + * String should have. + * @param value the String to check. * * @return true if the given String's length is less * than maxChars, false otherwise. * - * @throws IllegalArgumentException - * if maxChars is negative. + * @throws IllegalArgumentException if maxChars is negative. */ public final static boolean hasLessThanChars(int maxChars, String value) { return requireNonNull(value).length() < requireNonNegative(maxChars); @@ -2423,18 +2481,15 @@ public final static boolean hasLessThanChars(int maxChars, String value) { * {@link IllegalArgumentException} will be thrown if minChars is * negative. * - * @param minChars - * the minimum number of characters (inclusive) that the given - * String should have. - * @param value - * the String to check. + * @param minChars the minimum number of characters (inclusive) that the given + * String should have. + * @param value the String to check. * * @return true if the given String's length is * greater than or equal to minChars, false * otherwise. * - * @throws IllegalArgumentException - * if minChars is negative. + * @throws IllegalArgumentException if minChars is negative. */ public final static boolean hasMoreThanChars(int minChars, String value) { return isGreaterThanOrEqualTo(requireNonNegative(minChars), requireNonNull(value).length()); @@ -2451,24 +2506,20 @@ public final static boolean hasMoreThanChars(int minChars, String value) { * {@code IllegalArgumentException} might be thrown if any of that methods * requirements are not met. * - * @param minChars - * the minimum number of characters - * (inclusive) that the given {@code String} - * should have. - * @param maxChars - * the maximum number of characters - * (exclusive) that the given {@code String} - * should have. - * @param value - * the {@code String} to check. + * @param minChars the minimum number of characters + * (inclusive) that the given + * {@code String} should have. + * @param maxChars the maximum number of characters + * (exclusive) that the given + * {@code String} should have. + * @param value the {@code String} to check. * * @return {@code value} if {@code value}'s length falls within the specified * range. * - * @throws NullPointerException - * if {@code value} is {@code null}. - * @throws IllegalArgumentException - * if any of the conditions stated above are/is met. + * @throws NullPointerException if {@code value} is {@code null}. + * @throws IllegalArgumentException if any of the conditions stated above are/is + * met. * * @see #hasCharsInRange(int, int, String) */ @@ -2490,27 +2541,22 @@ public final static String requireCharsInRange(int minChars, int maxChars, Strin * {@code IllegalArgumentException} might be thrown if any of that methods * requirements are not met. * - * @param minChars - * the minimum number of characters - * (inclusive) that the given {@code String} - * should have. - * @param maxChars - * the maximum number of characters - * (exclusive) that the given {@code String} - * should have. - * @param value - * the {@code String} to check. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param minChars the minimum number of characters + * (inclusive) that the given + * {@code String} should have. + * @param maxChars the maximum number of characters + * (exclusive) that the given + * {@code String} should have. + * @param value the {@code String} to check. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value}'s length falls within the specified * range. * - * @throws NullPointerException - * if {@code value} is {@code null}. - * @throws IllegalArgumentException - * if any of the conditions stated above are/is met. + * @throws NullPointerException if {@code value} is {@code null}. + * @throws IllegalArgumentException if any of the conditions stated above are/is + * met. * * @see #hasCharsInRange(int, int, String) */ @@ -2534,20 +2580,17 @@ public final static String requireCharsInRange(int minChars, int maxChars, Strin * {@code IllegalArgumentException}might be thrown if any of that methods * requirements are not met. * - * @param maxChars - * the maximum number of characters - * (exclusive) that the given {@code String} - * should have. - * @param value - * the {@code String} to check. + * @param maxChars the maximum number of characters + * (exclusive) that the given + * {@code String} should have. + * @param value the {@code String} to check. * * @return {@code value} if {@code value}'s length is less than * {@code maxChars}. * - * @throws NullPointerException - * if {@code value} is {@code null}. - * @throws IllegalArgumentException - * if any of the conditions stated above are/is met. + * @throws NullPointerException if {@code value} is {@code null}. + * @throws IllegalArgumentException if any of the conditions stated above are/is + * met. * * @see #hasLessThanChars(int, String) */ @@ -2568,23 +2611,19 @@ public final static String requireLessThanChars(int maxChars, String value) { * {@code IllegalArgumentException}might be thrown if any of that methods * requirements are not met. * - * @param maxChars - * the maximum number of characters - * (exclusive) that the given {@code String} - * should have. - * @param value - * the {@code String} to check. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param maxChars the maximum number of characters + * (exclusive) that the given + * {@code String} should have. + * @param value the {@code String} to check. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value}'s length is less than * {@code maxChars}. * - * @throws NullPointerException - * if {@code value} is {@code null}. - * @throws IllegalArgumentException - * if any of the conditions stated above are/is met. + * @throws NullPointerException if {@code value} is {@code null}. + * @throws IllegalArgumentException if any of the conditions stated above are/is + * met. * * @see #hasLessThanChars(int, String) */ @@ -2607,20 +2646,17 @@ public final static String requireLessThanChars(int maxChars, String value, Stri * {@code IllegalArgumentException}might be thrown if any of that methods * requirements are not met. * - * @param minChars - * the minimum number of characters - * (inclusive) that the given {@code String} - * should have. - * @param value - * the {@code String} to check. + * @param minChars the minimum number of characters + * (inclusive) that the given + * {@code String} should have. + * @param value the {@code String} to check. * * @return {@code value} if {@code value}'s length is greater than or equal to * {@code minChars}. * - * @throws NullPointerException - * if {@code value} is {@code null}. - * @throws IllegalArgumentException - * if any of the conditions stated above are/is met. + * @throws NullPointerException if {@code value} is {@code null}. + * @throws IllegalArgumentException if any of the conditions stated above are/is + * met. * * @see #hasMoreThanChars(int, String) */ @@ -2642,23 +2678,19 @@ public final static String requireMoreThanChars(int minChars, String value) { * {@code IllegalArgumentException}might be thrown if any of that methods * requirements are not met. * - * @param minChars - * the minimum number of characters - * (inclusive) that the given {@code String} - * should have. - * @param value - * the {@code String} to check. - * @param message - * an optional message to be used as as the - * {@code IllegalArgumentException} message. + * @param minChars the minimum number of characters + * (inclusive) that the given + * {@code String} should have. + * @param value the {@code String} to check. + * @param message an optional message to be used as as the + * {@code IllegalArgumentException} message. * * @return {@code value} if {@code value}'s length is greater than or equal to * {@code minChars}. * - * @throws NullPointerException - * if {@code value} is {@code null}. - * @throws IllegalArgumentException - * if any of the conditions stated above are/is met. + * @throws NullPointerException if {@code value} is {@code null}. + * @throws IllegalArgumentException if any of the conditions stated above are/is + * met. * * @see #hasMoreThanChars(int, String) */ @@ -2679,15 +2711,13 @@ public final static String requireMoreThanChars(int minChars, String value, Stri * {@link #requireNonEmptyString(String, String) requireNonEmptyString(value, * null)}. * - * @param value - * the {@code String} to be checked for validity. + * @param value the {@code String} to be checked for validity. * * @return value if it's not null AND/OR empty. * - * @throws NullPointerException - * if value is null. - * @throws IllegalArgumentException - * if value is empty(has a length of zero). + * @throws NullPointerException if value is null. + * @throws IllegalArgumentException if value is empty(has a length of + * zero). * * @see #requireNonEmptyString(String, String) */ @@ -2723,18 +2753,15 @@ public static final String requireNonEmptyString(String value) { * "value cannot be empty" * * - * @param value - * the {@code String} to be checked for validity. - * @param name - * the name of the {@code String} variable to be checked for - * validity. + * @param value the {@code String} to be checked for validity. + * @param name the name of the {@code String} variable to be checked for + * validity. * * @return value if it's not null AND/OR empty. * - * @throws NullPointerException - * if value is null. - * @throws IllegalArgumentException - * if value is empty(has a length of zero). + * @throws NullPointerException if value is null. + * @throws IllegalArgumentException if value is empty(has a length of + * zero). * * @see #requireNonEmptyString(String, String, String) */ @@ -2751,20 +2778,16 @@ public static final String requireNonEmptyString(String value, String name) { * as the second and third arguments to be used in the construction of * exceptions. * - * @param value - * the {@code String} to be checked for validity. - * @param nullMessage - * an optional message to be used when raising the - * {@code NullPointerException}. - * @param emptyMessage - * an optional message to be used when raising the - * {@code IllegalArgumentException}. + * @param value the {@code String} to be checked for validity. + * @param nullMessage an optional message to be used when raising the + * {@code NullPointerException}. + * @param emptyMessage an optional message to be used when raising the + * {@code IllegalArgumentException}. * @return value if it's not null AND/OR empty. * - * @throws NullPointerException - * if value is null. - * @throws IllegalArgumentException - * if value is empty(has a length of zero). + * @throws NullPointerException if value is null. + * @throws IllegalArgumentException if value is empty(has a length of + * zero). */ public static final String requireNonEmptyString(String value, String nullMessage, String emptyMessage) { // Check if messages are null and set defaults @@ -2775,6 +2798,7 @@ public static final String requireNonEmptyString(String value, String nullMessag return value; } + // private constructor to prevent initialization private ObjectUtils() { } } diff --git a/src/test/java/com/kori_47/utils/ObjectUtilsTest.java b/src/test/java/com/kori_47/utils/ObjectUtilsTest.java index 48ba5b6..7313fad 100644 --- a/src/test/java/com/kori_47/utils/ObjectUtilsTest.java +++ b/src/test/java/com/kori_47/utils/ObjectUtilsTest.java @@ -1,19 +1,42 @@ package com.kori_47.utils; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.Serializable; import java.math.BigDecimal; import org.junit.jupiter.api.Test; + public class ObjectUtilsTest { - /*------------------------------------------------------------------------------------- - * - * NUMBERS - * - * ------------------------------------------------------------------------------------ - */ + // ======================================================================== + // NUMBERS UTILITY METHODS TESTS + // ======================================================================== + @Test + public void testIsEqualTo() { + // Test returns true when number is equal to + assertTrue(ObjectUtils.isEqualTo(0, -0)); + assertTrue(ObjectUtils.isEqualTo(-435L, -435L)); + assertTrue(ObjectUtils.isEqualTo(-65.78724913F, -65.78724913F)); + assertTrue(ObjectUtils.isEqualTo(0.000000000000001D, 0.000000000000001D)); + assertTrue(ObjectUtils.isEqualTo(new BigDecimal("7"), new BigDecimal("7"))); + + // Test returns false when number is not equal to + assertFalse(ObjectUtils.isEqualTo(0, -1)); + assertFalse(ObjectUtils.isEqualTo(435L, -435L)); + assertFalse(ObjectUtils.isEqualTo(65.78724913F, -65.78724913F)); + assertFalse(ObjectUtils.isEqualTo(0.999999999999999D, 0.1D)); + assertFalse(ObjectUtils.isEqualTo(new BigDecimal("0.9999999999999999"), new BigDecimal("1"))); + + // Test that NullPointerException is thrown when null is given + assertThrows(NullPointerException.class, () -> ObjectUtils.isEqualTo(null, null)); + assertThrows(NullPointerException.class, () -> ObjectUtils.isEqualTo(null, new BigDecimal("1"))); + assertThrows(NullPointerException.class, () -> ObjectUtils.isEqualTo(new BigDecimal("1"), null)); + } + @Test public void testIsGreaterThan() { // Test returns true when a number is greater than @@ -155,12 +178,48 @@ public void testInRangeExceptions() { () -> assertFalse(ObjectUtils.inRange(new BigDecimal("0.01"), new BigDecimal("0.015"), null))); } + @Test + public void testRequireEqualTo() { + // Test returns value when equal + assertEquals(0, ObjectUtils.requireEqualTo(0, -0)); + assertEquals(-47L, ObjectUtils.requireEqualTo(-47L, -47L)); + assertEquals(-34.4535623F, ObjectUtils.requireEqualTo(-34.4535623F, -34.4535623F)); + assertEquals(0.999999999999999999D, ObjectUtils.requireEqualTo(0.999999999999999999D, 0.999999999999999999D)); + assertEquals(new BigDecimal("0.9999999999999999"), + ObjectUtils.requireEqualTo(new BigDecimal("0.9999999999999999"), new BigDecimal("0.9999999999999999"))); + + // Test throws IllegalArgumentException when not equal to + assertThrows(IllegalArgumentException.class, () -> ObjectUtils.requireEqualTo(0, -1)); + assertThrows(IllegalArgumentException.class, () -> ObjectUtils.requireEqualTo(78L, -3L)); + assertThrows(IllegalArgumentException.class, () -> ObjectUtils.requireEqualTo(7.99999F, 8F)); + assertThrows(IllegalArgumentException.class, () -> ObjectUtils.requireEqualTo(0.99999999999999D, 1)); + assertThrows(IllegalArgumentException.class, + () -> ObjectUtils.requireEqualTo(new BigDecimal("-1"), new BigDecimal("-1.00000000001"))); + + // Test exception message + final String errMessage = "value must be equal to base value."; // generic error message + assertEquals(errMessage, + assertThrows(IllegalArgumentException.class, () -> ObjectUtils.requireEqualTo(11, 123, errMessage)) + .getMessage()); + assertEquals(errMessage, + assertThrows(IllegalArgumentException.class, () -> ObjectUtils.requireEqualTo(-1L, 1L, errMessage)) + .getMessage()); + assertEquals(errMessage, assertThrows(IllegalArgumentException.class, + () -> ObjectUtils.requireEqualTo(-373234.08F, -373233.09F, errMessage)).getMessage()); + assertEquals(errMessage, assertThrows(IllegalArgumentException.class, + () -> ObjectUtils.requireEqualTo(6767.6767676767D, 7676.7676767676D, errMessage)).getMessage()); + assertEquals(errMessage, + assertThrows(IllegalArgumentException.class, + () -> ObjectUtils.requireEqualTo(new BigDecimal("56.74"), new BigDecimal("56.75"), errMessage)) + .getMessage()); + } + @Test public void testRequireInRangeReturnValues() { assertEquals(2, ObjectUtils.requireInRange(2, 3, 2)); - assertEquals(223l, ObjectUtils.requireInRange(10L, 3792L, 223L)); - assertEquals(-32.99f, ObjectUtils.requireInRange(-100.90F, 0.00F, -32.99F)); - assertEquals(-1.788738737d, ObjectUtils.requireInRange(-1.8673763D, 1.6D, -1.788738737D)); + assertEquals(223L, ObjectUtils.requireInRange(10L, 3792L, 223L)); + assertEquals(-32.99F, ObjectUtils.requireInRange(-100.90F, 0.00F, -32.99F)); + assertEquals(-1.788738737D, ObjectUtils.requireInRange(-1.8673763D, 1.6D, -1.788738737D)); assertEquals(new BigDecimal("45.10"), ObjectUtils.requireInRange(new BigDecimal("45.09"), new BigDecimal("45.11"), new BigDecimal("45.10"))); @@ -438,12 +497,9 @@ public void testNonNegativeExceptionMessages() { assertEquals("given BigDecimal must not be negative.", ex5.getMessage()); } - /*------------------------------------------------------------------------------------- - * - * SERIALIZABLES - * - * ------------------------------------------------------------------------------------ - */ + // ======================================================================== + // SERIALIZABLES UTILITY METHODS TESTS + // ======================================================================== @Test public void testIsSerializable() { assertFalse(ObjectUtils.isSerializable(new NonSerializableClass())); @@ -473,13 +529,9 @@ public void testRequireSerializableExceptionMessages() { assertEquals("instance must be serializable.", ex.getMessage()); } - /*------------------------------------------------------------------------------------- - * - * STRINGS - * - * ------------------------------------------------------------------------------------ - */ - + // ======================================================================== + // STRINGS UTILITY METHODS TESTS + // ======================================================================== @Test public void testHasCharsInRange() { assertTrue(ObjectUtils.hasCharsInRange(2, 3, "Hi")); // 2 chars