public final class Preconditions extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
check(boolean expression)
Checks whether the given expression evaluates to
true. |
static void |
check(boolean expression,
String message)
Checks whether the given expression evaluates to
true. |
static void |
check(boolean expression,
java.util.function.Supplier<String> messageSupplier)
Checks whether the given expression evaluates to
true. |
static <T> Collection<T> |
doesNotContainNull(Collection<T> collection)
Checks if the given
Collection contains any null element. |
static <T> Collection<T> |
doesNotContainNull(Collection<T> collection,
String message)
Checks if the given
Collection contains any null element. |
static <T> Collection<T> |
doesNotContainNull(Collection<T> collection,
java.util.function.Supplier<String> messageSupplier)
Checks if the given
Collection contains any null element. |
static <T> T |
notNull(T object)
Checks if the given object is
null. |
static <T> T |
notNull(T object,
String message)
Checks if the given object if
null. |
static <T> T |
notNull(T object,
java.util.function.Supplier<String> messageSupplier)
Checks if the given object is
null. |
public static <T> T notNull(T object)
null. If this is the case,
a NullPointerException is thrown.T - the type of the object. This is needed to return the correct
type againobject - the object to be checkednullNullPointerException - if the passed object is nullpublic static <T> T notNull(T object,
String message)
null. If this is the case,
a NullPointerException with the given message is thrown.T - the type of the object. This is needed to returned the correct
type againobject - the object to be checkedmessage - the message for the exception if the object is
nullnullNullPointerException - if the passed object is nullpublic static <T> T notNull(T object,
java.util.function.Supplier<String> messageSupplier)
null. If this is the case,
a NullPointerException with the message provided by the
Supplier is thrown.T - the type of the object. This is needed to returned the correct
* type againobject - the object to be checkedmessageSupplier - a supplier for the message of the exception
which will be thrown if object is nullnullNullPointerException - if the passed object is nullpublic static <T> Collection<T> doesNotContainNull(Collection<T> collection)
Collection contains any null element.
If this is the case, a IllegalArgumentException is thrown.T - the type of the collectioncollection - to be examined for a null element.
Must not be nullIllegalArgumentException - if collection contains nullNullPointerException - if the collection it was null
itself. Note that some Collection
implementations may throw a
NullPointerException during the
check if they do not permit the null
typepublic static <T> Collection<T> doesNotContainNull(Collection<T> collection, String message)
Collection contains any null element.
If this is the case, a IllegalArgumentException with the given
message is thrown.T - the type of the collectioncollection - to be examined for a null element.
Must not be nullmessage - for the exception if it is thrownIllegalArgumentException - if collection contains nullNullPointerException - if the collection it was null
itself. Note that some Collection
implementations may throw a
NullPointerException during the
check if they do not permit the null
typepublic static <T> Collection<T> doesNotContainNull(Collection<T> collection, java.util.function.Supplier<String> messageSupplier)
Collection contains any null element.
If this is the case, a IllegalArgumentException with the message
given by the supplier.T - the type of the collectioncollection - to be examined for a null element.
Must not be nullmessageSupplier - for the exception message if it is thrownIllegalArgumentException - if collection contains nullNullPointerException - if the collection it was null
itself. Note that some Collection
implementations may throw a
NullPointerException during the
check if they do not permit the null
typepublic static void check(boolean expression)
true. If this is
not the case, an IllegalArgumentException is thrown.expression - the expression to be evaluatedIllegalArgumentException - if the expression evaluates to
falsepublic static void check(boolean expression,
String message)
true. If this is
not the case, an IllegalArgumentException with the given message
is thrown.expression - the expression to be evaluatedmessage - the message for the exceptionIllegalArgumentException - if the expression evaluates to
falsepublic static void check(boolean expression,
java.util.function.Supplier<String> messageSupplier)
true. If this is
not the case, an IllegalArgumentException with the message given
by the Supplier is thrown.expression - the expression to be evaluatedmessageSupplier - the supplier for the exception messageIllegalArgumentException - if the expression evaluates to
falseCopyright © 2019. All rights reserved.