public final class Validate
extends java.lang.Object
Created for code shortening and for making legible code. Make fail-fast methods.
| Modifier and Type | Method and Description |
|---|---|
static void |
argument(boolean expression)
Validates that the specified expression is true,
if it is false, the method throws a
IllegalArgumentException |
static void |
argument(boolean expression,
java.lang.String message,
java.lang.Object... parameters)
Validates that the specified expression is true,
if it is false, the method throws a
IllegalArgumentException
with the specified message |
static <T> void |
doesntRequiresContext(Key<T> key) |
static java.lang.String |
notEmpty(java.lang.String string)
Validates that the specified string is
not null and not empty.
|
static java.lang.String |
notEmpty(java.lang.String string,
java.lang.String message,
java.lang.Object... parameters)
Validates that the specified string is
not null and not empty.
|
static <T> T |
notNull(T object)
Validates that the provided object isn't null,
if it is, the method throws an
NullPointerException |
static <T> T |
notNull(T object,
java.lang.String message,
java.lang.Object... parameters)
Validates that the provided object isn't null,
if it is, the method throws an
NullPointerException
with the specified message. |
static void |
state(boolean expression)
Validates that the specified expression is true,
if it is false, the method throws a
IllegalStateException |
static void |
state(boolean expression,
java.lang.String message,
java.lang.Object... parameters)
Validates that the specified expression is true,
if it is false, the method throws a
IllegalStateException
with the specified message. |
public static <T> T notNull(T object,
java.lang.String message,
java.lang.Object... parameters)
NullPointerException
with the specified message.T - The type of the checked objectobject - The checked objectmessage - The exception messageparameters - Parameters for the message,
message is formatted using
String.format(java.lang.String, java.lang.Object...).java.lang.NullPointerException - if object is nullpublic static <T> T notNull(T object)
NullPointerExceptionT - The type of the checked objectobject - The checked objectjava.lang.NullPointerException - if object is nullpublic static void state(boolean expression,
java.lang.String message,
java.lang.Object... parameters)
IllegalStateException
with the specified message.expression - The checked expressionmessage - The message for the thrown exceptionparameters - The parameters for the exception
message. The message is formatted
using String.format(java.lang.String, java.lang.Object...).java.lang.IllegalStateException - If expression is falsepublic static void state(boolean expression)
IllegalStateExceptionexpression - The checked expressionjava.lang.IllegalStateException - If expression is falsepublic static void argument(boolean expression,
java.lang.String message,
java.lang.Object... parameters)
IllegalArgumentException
with the specified messageexpression - The checked expressionmessage - The message for the thrown exceptionparameters - The parameters for the exception
message. The message is formatted
using String.format(java.lang.String, java.lang.Object...).java.lang.IllegalArgumentException - If expression is falsepublic static void argument(boolean expression)
IllegalArgumentExceptionexpression - The checked expressionjava.lang.IllegalArgumentException - If expression is falsepublic static java.lang.String notEmpty(java.lang.String string,
java.lang.String message,
java.lang.Object... parameters)
NullPointerException,
if the string is empty, throws a
IllegalArgumentException.string - The checked stringmessage - The message used for the messagesparameters - The parameters for the exception
message. The message is formatted
using String.format(java.lang.String, java.lang.Object...).java.lang.NullPointerException - if the string is nulljava.lang.IllegalArgumentException - If the string is emptypublic static java.lang.String notEmpty(java.lang.String string)
NullPointerException,
if the string is empty, throws a
IllegalArgumentException.string - The checked stringjava.lang.NullPointerException - if the string is nulljava.lang.IllegalArgumentException - If the string is emptypublic static <T> void doesntRequiresContext(Key<T> key)