Class RequestValidations
- java.lang.Object
-
- org.apache.cassandra.cql3.statements.RequestValidations
-
public final class RequestValidations extends java.lang.ObjectUtility methods use to perform request validation.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));
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckBindValueSet(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 voidcheckContainsNoDuplicates(java.util.List<?> list, java.lang.String message)Checks that the specified list does not contains duplicates.static <E> voidcheckContainsOnly(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 voidcheckFalse(boolean expression, java.lang.String message)Checks that the specified expression isfalse.static voidcheckFalse(boolean expression, java.lang.String messageTemplate, java.lang.Object messageArg)Checks that the specified expression isfalse.static voidcheckFalse(boolean expression, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2)Checks that the specified expression isfalse.static voidcheckFalse(boolean expression, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)Checks that the specified expression isfalse.static <T extends java.util.Collection<E>,E>
TcheckNotEmpty(T collection, java.lang.String messageTemplate, java.lang.Object messageArg)Checks that the specified collections is NOTempty.static <T extends java.util.Collection<E>,E>
TcheckNotEmpty(T collection, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2)Checks that the specified collections is NOTempty.static <T> TcheckNotNull(T object, java.lang.String message)Checks that the specified object is NOTnull.static <T> TcheckNotNull(T object, java.lang.String messageTemplate, java.lang.Object messageArg)Checks that the specified object is NOTnull.static <T> TcheckNotNull(T object, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2)Checks that the specified object is NOTnull.static voidcheckNull(java.lang.Object object, java.lang.String message)Checks that the specified object isnull.static voidcheckNull(java.lang.Object object, java.lang.String messageTemplate, java.lang.Object messageArg)Checks that the specified object isnull.static voidcheckTrue(boolean expression, java.lang.String message)Checks that the specified expression istrue.static voidcheckTrue(boolean expression, java.lang.String messageTemplate, java.lang.Object messageArg)Checks that the specified expression istrue.static voidcheckTrue(boolean expression, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2)Checks that the specified expression istrue.static voidcheckTrue(boolean expression, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)Checks that the specified expression istrue.static InvalidRequestExceptioninvalidRequest(java.lang.String message)Returns anInvalidRequestExceptionwith the specified message.static InvalidRequestExceptioninvalidRequest(java.lang.String messageTemplate, java.lang.Object... messageArgs)Returns anInvalidRequestExceptionwith the specified message.
-
-
-
Method Detail
-
checkTrue
public static void checkTrue(boolean expression, java.lang.String message) throws InvalidRequestExceptionChecks that the specified expression istrue. If not anInvalidRequestExceptionwill be thrown.- Parameters:
expression- the expression to testmessage- the error message- Throws:
InvalidRequestException- if the specified expression isfalse.
-
checkTrue
public static void checkTrue(boolean expression, java.lang.String messageTemplate, java.lang.Object messageArg) throws InvalidRequestExceptionChecks that the specified expression istrue. If not anInvalidRequestExceptionwill be thrown.- Parameters:
expression- the expression to testmessageTemplate- the template used to build the error messagemessageArg- the message argument- Throws:
InvalidRequestException- if the specified expression isfalse.
-
checkTrue
public static void checkTrue(boolean expression, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2) throws InvalidRequestExceptionChecks that the specified expression istrue. If not anInvalidRequestExceptionwill be thrown.- Parameters:
expression- the expression to testmessageTemplate- the template used to build the error messagearg1- the first message argumentarg2- the second message argument- Throws:
InvalidRequestException- if the specified expression isfalse.
-
checkTrue
public static void checkTrue(boolean expression, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3) throws InvalidRequestExceptionChecks that the specified expression istrue. If not anInvalidRequestExceptionwill be thrown.- Parameters:
expression- the expression to testmessageTemplate- the template used to build the error messagearg1- the first message argumentarg2- the second message argumentarg3- the third message argument- Throws:
InvalidRequestException- if the specified expression isfalse.
-
checkNotEmpty
public static <T extends java.util.Collection<E>,E> T checkNotEmpty(T collection, java.lang.String messageTemplate, java.lang.Object messageArg) throws InvalidRequestExceptionChecks that the specified collections is NOTempty. If it is anInvalidRequestExceptionwill be thrown.- Parameters:
collection- the collection to testmessageTemplate- the template used to build the error messagemessageArg- the message argument- Returns:
- the collection
- Throws:
InvalidRequestException- if the specified collection isempty.
-
checkNotEmpty
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 InvalidRequestExceptionChecks that the specified collections is NOTempty. If it is anInvalidRequestExceptionwill be thrown.- Parameters:
collection- the collection to testmessageTemplate- the template used to build the error messagearg1- the first message argumentarg2- the second message argument- Returns:
- the collection
- Throws:
InvalidRequestException- if the specified collection isempty.
-
checkContainsNoDuplicates
public static void checkContainsNoDuplicates(java.util.List<?> list, java.lang.String message) throws InvalidRequestExceptionChecks that the specified list does not contains duplicates.- Parameters:
list- the list to testmessage- the error message- Throws:
InvalidRequestException- if the specified list contains duplicates.
-
checkContainsOnly
public static <E> void checkContainsOnly(java.util.List<E> list, java.util.List<E> expectedElements, java.lang.String message) throws InvalidRequestExceptionChecks that the specified list contains only the specified elements.- Parameters:
list- the list to testexpectedElements- the expected elementsmessage- the error message- Throws:
InvalidRequestException- if the specified list contains duplicates.
-
checkFalse
public static void checkFalse(boolean expression, java.lang.String messageTemplate, java.lang.Object messageArg) throws InvalidRequestExceptionChecks that the specified expression isfalse. If not anInvalidRequestExceptionwill be thrown.- Parameters:
expression- the expression to testmessageTemplate- the template used to build the error messagemessageArg- the message argument- Throws:
InvalidRequestException- if the specified expression istrue.
-
checkFalse
public static void checkFalse(boolean expression, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2) throws InvalidRequestExceptionChecks that the specified expression isfalse. If not anInvalidRequestExceptionwill be thrown.- Parameters:
expression- the expression to testmessageTemplate- the template used to build the error messagearg1- the first message argumentarg2- the second message argument- Throws:
InvalidRequestException- if the specified expression istrue.
-
checkFalse
public static void checkFalse(boolean expression, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3) throws InvalidRequestExceptionChecks that the specified expression isfalse. If not anInvalidRequestExceptionwill be thrown.- Parameters:
expression- the expression to testmessageTemplate- the template used to build the error messagearg1- the first message argumentarg2- the second message argumentarg3- the third message argument- Throws:
InvalidRequestException- if the specified expression istrue.
-
checkFalse
public static void checkFalse(boolean expression, java.lang.String message) throws InvalidRequestExceptionChecks that the specified expression isfalse. If not anInvalidRequestExceptionwill be thrown.- Parameters:
expression- the expression to testmessage- the error message- Throws:
InvalidRequestException- if the specified expression istrue.
-
checkNotNull
public static <T> T checkNotNull(T object, java.lang.String message) throws InvalidRequestExceptionChecks that the specified object is NOTnull. If it is anInvalidRequestExceptionwill be thrown.- Parameters:
object- the object to testmessage- the error message- Returns:
- the object
- Throws:
InvalidRequestException- if the specified object isnull.
-
checkNotNull
public static <T> T checkNotNull(T object, java.lang.String messageTemplate, java.lang.Object messageArg) throws InvalidRequestExceptionChecks that the specified object is NOTnull. If it is anInvalidRequestExceptionwill be thrown.- Parameters:
object- the object to testmessageTemplate- the template used to build the error messagemessageArg- the message argument- Returns:
- the object
- Throws:
InvalidRequestException- if the specified object isnull.
-
checkNotNull
public static <T> T checkNotNull(T object, java.lang.String messageTemplate, java.lang.Object arg1, java.lang.Object arg2) throws InvalidRequestExceptionChecks that the specified object is NOTnull. If it is anInvalidRequestExceptionwill be thrown.- Parameters:
object- the object to testmessageTemplate- the template used to build the error messagearg1- the first message argumentarg2- the second message argument- Returns:
- the object
- Throws:
InvalidRequestException- if the specified object isnull.
-
checkBindValueSet
public static void checkBindValueSet(java.nio.ByteBuffer b, java.lang.String messageTemplate, java.lang.Object messageArg) throws InvalidRequestExceptionChecks that the specified bind marker value is set to a meaningful value. If it is not aInvalidRequestExceptionwill be thrown.- Parameters:
b- theByteBufferto testmessageTemplate- the template used to build the error messagemessageArg- the message argument- Throws:
InvalidRequestException- if the specified bind marker value is not set to a meaningful value.
-
checkNull
public static void checkNull(java.lang.Object object, java.lang.String messageTemplate, java.lang.Object messageArg) throws InvalidRequestExceptionChecks that the specified object isnull. If it is not anInvalidRequestExceptionwill be thrown.- Parameters:
object- the object to testmessageTemplate- the template used to build the error messagemessageArg- the message argument- Throws:
InvalidRequestException- if the specified object is notnull.
-
checkNull
public static void checkNull(java.lang.Object object, java.lang.String message) throws InvalidRequestExceptionChecks that the specified object isnull. If it is not anInvalidRequestExceptionwill be thrown.- Parameters:
object- the object to testmessage- the error message- Throws:
InvalidRequestException- if the specified object is notnull.
-
invalidRequest
public static InvalidRequestException invalidRequest(java.lang.String message)
Returns anInvalidRequestExceptionwith the specified message.- Parameters:
message- the error message- Returns:
- an
InvalidRequestExceptionwith the specified message.
-
invalidRequest
public static InvalidRequestException invalidRequest(java.lang.String messageTemplate, java.lang.Object... messageArgs)
Returns anInvalidRequestExceptionwith the specified message.- Parameters:
messageTemplate- the template used to build the error messagemessageArgs- the message arguments- Returns:
- an
InvalidRequestExceptionwith the specified message.
-
-