Class RequestValidations


  • public final class RequestValidations
    extends java.lang.Object
    Utility methods use to perform request validation.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void checkBindValueSet​(java.nio.ByteBuffer b, java.lang.String messageTemplate, java.lang.Object... messageArgs)
      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... messageArgs)
      Checks that the specified expression is false.
      static <T extends java.util.Collection<E>,​E>
      T
      checkNotEmpty​(T collection, java.lang.String messageTemplate, java.lang.Object... messageArgs)
      Checks that the specified collections is NOT empty.
      static <T> T checkNotNull​(T object, java.lang.String messageTemplate, java.lang.Object... messageArgs)
      Checks that the specified object is NOT null.
      static <T> T checkNull​(T object, java.lang.String message)
      Checks that the specified object is null.
      static <T> T checkNull​(T object, java.lang.String messageTemplate, java.lang.Object... messageArgs)
      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... messageArgs)
      Checks that the specified expression is true.
      static InvalidRequestException invalidRequest​(java.lang.String messageTemplate, java.lang.Object... messageArgs)
      Returns an InvalidRequestException with the specified message.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • checkTrue

        public static void checkTrue​(boolean expression,
                                     java.lang.String message)
                              throws InvalidRequestException
        Checks that the specified expression is true. If not an InvalidRequestException will be thrown.
        Parameters:
        expression - the expression to test
        message - the error message
        Throws:
        InvalidRequestException - if the specified expression is false.
      • checkTrue

        public static void checkTrue​(boolean expression,
                                     java.lang.String messageTemplate,
                                     java.lang.Object... messageArgs)
                              throws InvalidRequestException
        Checks that the specified expression is true. If not an InvalidRequestException will be thrown.
        Parameters:
        expression - the expression to test
        messageTemplate - the template used to build the error message
        messageArgs - the message arguments
        Throws:
        InvalidRequestException - if the specified expression is false.
      • checkContainsNoDuplicates

        public static void checkContainsNoDuplicates​(java.util.List<?> list,
                                                     java.lang.String message)
                                              throws InvalidRequestException
        Checks that the specified list does not contains duplicates.
        Parameters:
        list - the list to test
        message - 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 InvalidRequestException
        Checks that the specified list contains only the specified elements.
        Parameters:
        list - the list to test
        expectedElements - the expected elements
        message - 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... messageArgs)
                               throws InvalidRequestException
        Checks that the specified expression is false. If not an InvalidRequestException will be thrown.
        Parameters:
        expression - the expression to test
        messageTemplate - the template used to build the error message
        messageArgs - the message arguments
        Throws:
        InvalidRequestException - if the specified expression is true.
      • checkFalse

        public static void checkFalse​(boolean expression,
                                      java.lang.String message)
                               throws InvalidRequestException
        Checks that the specified expression is false. If not an InvalidRequestException will be thrown.
        Parameters:
        expression - the expression to test
        message - the error message
        Throws:
        InvalidRequestException - if the specified expression is true.
      • checkNotNull

        public static <T> T checkNotNull​(T object,
                                         java.lang.String messageTemplate,
                                         java.lang.Object... messageArgs)
                                  throws InvalidRequestException
        Checks that the specified object is NOT null. If it is an InvalidRequestException will be throws.
        Parameters:
        object - the object to test
        messageTemplate - the template used to build the error message
        messageArgs - the message arguments
        Returns:
        the object
        Throws:
        InvalidRequestException - if the specified object is null.
      • checkNotEmpty

        public static <T extends java.util.Collection<E>,​E> T checkNotEmpty​(T collection,
                                                                                  java.lang.String messageTemplate,
                                                                                  java.lang.Object... messageArgs)
                                                                           throws InvalidRequestException
        Checks that the specified collections is NOT empty. If it is an InvalidRequestException will be throws.
        Parameters:
        collection - the collection to test
        messageTemplate - the template used to build the error message
        messageArgs - the message arguments
        Returns:
        the collection
        Throws:
        InvalidRequestException - if the specified collection is empty.
      • checkBindValueSet

        public static void checkBindValueSet​(java.nio.ByteBuffer b,
                                             java.lang.String messageTemplate,
                                             java.lang.Object... messageArgs)
                                      throws InvalidRequestException
        Checks that the specified bind marker value is set to a meaningful value. If it is not a InvalidRequestException will be thrown.
        Parameters:
        b - the ByteBuffer to test
        messageTemplate - the template used to build the error message
        messageArgs - the message arguments
        Throws:
        InvalidRequestException - if the specified bind marker value is not set to a meaningful value.
      • checkNull

        public static <T> T checkNull​(T object,
                                      java.lang.String messageTemplate,
                                      java.lang.Object... messageArgs)
                               throws InvalidRequestException
        Checks that the specified object is null. If it is not an InvalidRequestException will be throws.
        Parameters:
        object - the object to test
        messageTemplate - the template used to build the error message
        messageArgs - the message arguments
        Returns:
        the object
        Throws:
        InvalidRequestException - if the specified object is not null.
      • checkNull

        public static <T> T checkNull​(T object,
                                      java.lang.String message)
                               throws InvalidRequestException
        Checks that the specified object is null. If it is not an InvalidRequestException will be throws.
        Parameters:
        object - the object to test
        message - the error message
        Returns:
        the object
        Throws:
        InvalidRequestException - if the specified object is not null.
      • invalidRequest

        public static InvalidRequestException invalidRequest​(java.lang.String messageTemplate,
                                                             java.lang.Object... messageArgs)
        Returns an InvalidRequestException with the specified message.
        Parameters:
        messageTemplate - the template used to build the error message
        messageArgs - the message arguments
        Returns:
        an InvalidRequestException with the specified message.