java.lang.Object
de.zabuza.fastcdc4j.internal.util.Validations
public final class Validations
extends java.lang.Object
Utility class providing validation methods.
- Author:
- Daniel Tischner <zabuza.dev@gmail.com>
-
Method Summary
Modifier and Type Method Description static voidrequire(boolean predicate, java.lang.String message)ThrowsIllegalArgumentExceptionif the given predicate resolves to false.static <E extends java.lang.RuntimeException>
voidrequire(boolean predicate, java.util.function.Function<? super java.lang.String,E> exceptionSupplier, java.lang.String message)Throws the given exception if the predicate resolves to false.static <T> Trequire(java.util.function.Predicate<? super T> predicate, T object, java.lang.String message)ThrowsIllegalArgumentExceptionif the given predicate resolves to true.static <T, E extends java.lang.RuntimeException>
Trequire(java.util.function.Predicate<? super T> predicate, T object, java.util.function.Function<? super java.lang.String,E> exceptionSupplier, java.lang.String message)Throws the given exception if the predicate resolves to false.static <E extends java.lang.RuntimeException>
voidrequireNotThrow(java.lang.Class<E> expectedException, java.lang.Runnable runnable, java.lang.String message)ThrowsIllegalArgumentExceptionif the runnable throws the given expected exception.static intrequirePositive(int value, java.lang.String valueName)ThrowsIllegalArgumentExceptionif the given value is not positive, i.e. when it is negative.static longrequirePositive(long value, java.lang.String valueName)ThrowsIllegalArgumentExceptionif the given value is not positive, i.e. when it is negative.static intrequirePositiveNonZero(int value, java.lang.String valueName)ThrowsIllegalArgumentExceptionif the given value is not positive or zero, i.e. when it is negative or zero.static longrequirePositiveNonZero(long value, java.lang.String valueName)ThrowsIllegalArgumentExceptionif the given value is not positive or zero, i.e. when it is negative or zero.
-
Method Details
-
requirePositive
public static long requirePositive(long value, java.lang.String valueName)ThrowsIllegalArgumentExceptionif the given value is not positive, i.e. when it is negative.- Parameters:
value- The value to testvalueName- The name of the value, used to describe it in the exception reason, not null- Returns:
- The given value for convenient chaining
-
requirePositiveNonZero
public static long requirePositiveNonZero(long value, java.lang.String valueName)ThrowsIllegalArgumentExceptionif the given value is not positive or zero, i.e. when it is negative or zero.- Parameters:
value- The value to testvalueName- The name of the value, used to describe it in the exception reason, not null- Returns:
- The given value for convenient chaining
-
requirePositive
public static int requirePositive(int value, java.lang.String valueName)ThrowsIllegalArgumentExceptionif the given value is not positive, i.e. when it is negative.- Parameters:
value- The value to testvalueName- The name of the value, used to describe it in the exception reason, not null- Returns:
- The given value for convenient chaining
-
requirePositiveNonZero
public static int requirePositiveNonZero(int value, java.lang.String valueName)ThrowsIllegalArgumentExceptionif the given value is not positive or zero, i.e. when it is negative or zero.- Parameters:
value- The value to testvalueName- The name of the value, used to describe it in the exception reason, not null- Returns:
- The given value for convenient chaining
-
requireNotThrow
public static <E extends java.lang.RuntimeException> void requireNotThrow(java.lang.Class<E> expectedException, java.lang.Runnable runnable, java.lang.String message)ThrowsIllegalArgumentExceptionif the runnable throws the given expected exception.- Type Parameters:
E- The type of the exception to expect- Parameters:
expectedException- The exception for which to throw if it happens, not nullrunnable- The runnable to execute, not nullmessage- The message to provide in the exception as reason, not null
-
require
public static <T> T require(java.util.function.Predicate<? super T> predicate, T object, java.lang.String message)ThrowsIllegalArgumentExceptionif the given predicate resolves to true.- Type Parameters:
T- The type of the object to test- Parameters:
predicate- The predicate to test, not nullobject- The object to test the predicate againstmessage- The message to provide in the exception, not null- Returns:
- The given value for convenient chaining
-
require
public static void require(boolean predicate, java.lang.String message)ThrowsIllegalArgumentExceptionif the given predicate resolves to false.- Parameters:
predicate- The predicate to testmessage- The message to provide in the exception, not null
-
require
public static <T, E extends java.lang.RuntimeException> T require(java.util.function.Predicate<? super T> predicate, T object, java.util.function.Function<? super java.lang.String,E> exceptionSupplier, java.lang.String message)Throws the given exception if the predicate resolves to false.- Type Parameters:
T- The type of the object to testE- The type of the exception to throw- Parameters:
predicate- The predicate to test, not nullobject- The object to test the predicate againstexceptionSupplier- The supplier to use for getting the exception to throw, not nullmessage- The message to provide in the exception, not null- Returns:
- The given value for convenient chaining
-
require
public static <E extends java.lang.RuntimeException> void require(boolean predicate, java.util.function.Function<? super java.lang.String,E> exceptionSupplier, java.lang.String message)Throws the given exception if the predicate resolves to false.- Type Parameters:
E- The type of the exception to throw- Parameters:
predicate- The predicate to testexceptionSupplier- The supplier to use for getting the exception to throw, not nullmessage- The message to provide in the exception, not null
-