public final class RequestValidations
extends java.lang.Object
This class use overloaded methods to allow to specify different numbers of message arguments. While this introduces some clutter in the API, it avoids array allocation, initialization, and garbage collection overhead that is incurred by varargs calls.
Warning about performanceThe goal of this class is to improve readability of code, but in some circumstances this may come at a significant performance cost. Remember that argument values for message construction must all be computed eagerly, and autoboxing may happen as well, even when the check succeeds. If the message arguments are expensive to create you should use the customary form:
if (value < 0.0) throw RequestValidations.invalidRequest("negative value: %s", toReadableText(value));
Modifier and Type | Method and Description |
---|---|
static void |
checkBindValueSet(java.nio.ByteBuffer b,
java.lang.String messageTemplate,
java.lang.Object messageArg)
Checks that the specified bind marker value is set to a meaningful value.
|
static void |
checkContainsNoDuplicates(java.util.List<?> list,
java.lang.String message)
Checks that the specified list does not contains duplicates.
|
static <E> void |
checkContainsOnly(java.util.List<E> list,
java.util.List<E> expectedElements,
java.lang.String message)
Checks that the specified list contains only the specified elements.
|
static void |
checkFalse(boolean expression,
java.lang.String message)
Checks that the specified expression is
false . |
static void |
checkFalse(boolean expression,
java.lang.String messageTemplate,
java.lang.Object messageArg)
Checks that the specified expression is
false . |
static void |
checkFalse(boolean expression,
java.lang.String messageTemplate,
java.lang.Object arg1,
java.lang.Object arg2)
Checks that the specified expression is
false . |
static void |
checkFalse(boolean expression,
java.lang.String messageTemplate,
java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3)
Checks that the specified expression is
false . |
static <T extends java.util.Collection<E>,E> |
checkNotEmpty(T collection,
java.lang.String messageTemplate,
java.lang.Object messageArg)
Checks that the specified collections is NOT
empty . |
static <T extends java.util.Collection<E>,E> |
checkNotEmpty(T collection,
java.lang.String messageTemplate,
java.lang.Object arg1,
java.lang.Object arg2)
Checks that the specified collections is NOT
empty . |
static <T> T |
checkNotNull(T object,
java.lang.String message)
Checks that the specified object is NOT
null . |
static <T> T |
checkNotNull(T object,
java.lang.String messageTemplate,
java.lang.Object messageArg)
Checks that the specified object is NOT
null . |
static <T> T |
checkNotNull(T object,
java.lang.String messageTemplate,
java.lang.Object arg1,
java.lang.Object arg2)
Checks that the specified object is NOT
null . |
static void |
checkNull(java.lang.Object object,
java.lang.String message)
Checks that the specified object is
null . |
static void |
checkNull(java.lang.Object object,
java.lang.String messageTemplate,
java.lang.Object messageArg)
Checks that the specified object is
null . |
static void |
checkTrue(boolean expression,
java.lang.String message)
Checks that the specified expression is
true . |
static void |
checkTrue(boolean expression,
java.lang.String messageTemplate,
java.lang.Object messageArg)
Checks that the specified expression is
true . |
static void |
checkTrue(boolean expression,
java.lang.String messageTemplate,
java.lang.Object arg1,
java.lang.Object arg2)
Checks that the specified expression is
true . |
static void |
checkTrue(boolean expression,
java.lang.String messageTemplate,
java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3)
Checks that the specified expression is
true . |
static InvalidRequestException |
invalidRequest(java.lang.String message)
Returns an
InvalidRequestException with the specified message. |
static InvalidRequestException |
invalidRequest(java.lang.String messageTemplate,
java.lang.Object... messageArgs)
Returns an
InvalidRequestException with the specified message. |
public static void checkTrue(boolean expression, java.lang.String message) throws InvalidRequestException
true
. If not an InvalidRequestException
will
be thrown.expression
- the expression to testmessage
- the error messageInvalidRequestException
- if the specified expression is false
.public static void checkTrue(boolean expression, java.lang.String messageTemplate, java.lang.Object messageArg) throws InvalidRequestException
true
. If not an InvalidRequestException
will
be thrown.expression
- the expression to testmessageTemplate
- the template used to build the error messagemessageArg
- the message argumentInvalidRequestException
- if the specified expression is false
.public static void checkTrue(boolean expression, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2) throws InvalidRequestException
true
. If not an InvalidRequestException
will
be thrown.expression
- the expression to testmessageTemplate
- the template used to build the error messagearg1
- the first message argumentarg2
- the second message argumentInvalidRequestException
- if the specified expression is false
.public static void checkTrue(boolean expression, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3) throws InvalidRequestException
true
. If not an InvalidRequestException
will
be thrown.expression
- the expression to testmessageTemplate
- the template used to build the error messagearg1
- the first message argumentarg2
- the second message argumentarg3
- the third message argumentInvalidRequestException
- if the specified expression is false
.public static <T extends java.util.Collection<E>,E> T checkNotEmpty(T collection, java.lang.String messageTemplate, java.lang.Object messageArg) throws InvalidRequestException
empty
.
If it is an InvalidRequestException
will be thrown.collection
- the collection to testmessageTemplate
- the template used to build the error messagemessageArg
- the message argumentInvalidRequestException
- if the specified collection is empty
.public static <T extends java.util.Collection<E>,E> T checkNotEmpty(T collection, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2) throws InvalidRequestException
empty
.
If it is an InvalidRequestException
will be thrown.collection
- the collection to testmessageTemplate
- the template used to build the error messagearg1
- the first message argumentarg2
- the second message argumentInvalidRequestException
- if the specified collection is empty
.public static void checkContainsNoDuplicates(java.util.List<?> list, java.lang.String message) throws InvalidRequestException
list
- the list to testmessage
- the error messageInvalidRequestException
- if the specified list contains duplicates.public static <E> void checkContainsOnly(java.util.List<E> list, java.util.List<E> expectedElements, java.lang.String message) throws InvalidRequestException
list
- the list to testexpectedElements
- the expected elementsmessage
- the error messageInvalidRequestException
- if the specified list contains duplicates.public static void checkFalse(boolean expression, java.lang.String messageTemplate, java.lang.Object messageArg) throws InvalidRequestException
false
. If not an InvalidRequestException
will
be thrown.expression
- the expression to testmessageTemplate
- the template used to build the error messagemessageArg
- the message argumentInvalidRequestException
- if the specified expression is true
.public static void checkFalse(boolean expression, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2) throws InvalidRequestException
false
. If not an InvalidRequestException
will
be thrown.expression
- the expression to testmessageTemplate
- the template used to build the error messagearg1
- the first message argumentarg2
- the second message argumentInvalidRequestException
- if the specified expression is true
.public static void checkFalse(boolean expression, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3) throws InvalidRequestException
false
. If not an InvalidRequestException
will
be thrown.expression
- the expression to testmessageTemplate
- the template used to build the error messagearg1
- the first message argumentarg2
- the second message argumentarg3
- the third message argumentInvalidRequestException
- if the specified expression is true
.public static void checkFalse(boolean expression, java.lang.String message) throws InvalidRequestException
false
. If not an InvalidRequestException
will
be thrown.expression
- the expression to testmessage
- the error messageInvalidRequestException
- if the specified expression is true
.public static <T> T checkNotNull(T object, java.lang.String message) throws InvalidRequestException
null
.
If it is an InvalidRequestException
will be thrown.object
- the object to testmessage
- the error messageInvalidRequestException
- if the specified object is null
.public static <T> T checkNotNull(T object, java.lang.String messageTemplate, java.lang.Object messageArg) throws InvalidRequestException
null
.
If it is an InvalidRequestException
will be thrown.object
- the object to testmessageTemplate
- the template used to build the error messagemessageArg
- the message argumentInvalidRequestException
- if the specified object is null
.public static <T> T checkNotNull(T object, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2) throws InvalidRequestException
null
.
If it is an InvalidRequestException
will be thrown.object
- the object to testmessageTemplate
- the template used to build the error messagearg1
- the first message argumentarg2
- the second message argumentInvalidRequestException
- if the specified object is null
.public static void checkBindValueSet(java.nio.ByteBuffer b, java.lang.String messageTemplate, java.lang.Object messageArg) throws InvalidRequestException
InvalidRequestException
will be thrown.b
- the ByteBuffer
to testmessageTemplate
- the template used to build the error messagemessageArg
- the message argumentInvalidRequestException
- if the specified bind marker value is not set to a meaningful value.public static void checkNull(java.lang.Object object, java.lang.String messageTemplate, java.lang.Object messageArg) throws InvalidRequestException
null
.
If it is not an InvalidRequestException
will be thrown.object
- the object to testmessageTemplate
- the template used to build the error messagemessageArg
- the message argumentInvalidRequestException
- if the specified object is not null
.public static void checkNull(java.lang.Object object, java.lang.String message) throws InvalidRequestException
null
.
If it is not an InvalidRequestException
will be thrown.object
- the object to testmessage
- the error messageInvalidRequestException
- if the specified object is not null
.public static InvalidRequestException invalidRequest(java.lang.String message)
InvalidRequestException
with the specified message.message
- the error messageInvalidRequestException
with the specified message.public static InvalidRequestException invalidRequest(java.lang.String messageTemplate, java.lang.Object... messageArgs)
InvalidRequestException
with the specified message.messageTemplate
- the template used to build the error messagemessageArgs
- the message argumentsInvalidRequestException
with the specified message.Copyright © 2009-2022 The Apache Software Foundation