Class Preconditions


  • public final class Preconditions
    extends Object
    Utility for parameter validation
    • Method Detail

      • checkArgument

        public static void checkArgument​(boolean isValid,
                                         String message,
                                         Object arg0)
                                  throws IllegalArgumentException
        Precondition-style validation that throws IllegalArgumentException.
        Parameters:
        isValid - true if valid, false if an exception should be thrown
        message - A String message for the exception.
        arg0 - First parameter of the message string template
        Throws:
        IllegalArgumentException - if isValid is false
      • checkArgument

        public static void checkArgument​(boolean isValid,
                                         String message,
                                         Object arg0,
                                         Object arg1)
                                  throws IllegalArgumentException
        Precondition-style validation that throws IllegalArgumentException.
        Parameters:
        isValid - true if valid, false if an exception should be thrown
        message - A String message for the exception.
        arg0 - First parameter of the message string template
        arg1 - Second parameter of the message string template
        Throws:
        IllegalArgumentException - if isValid is false
      • checkArgument

        public static void checkArgument​(boolean isValid,
                                         String message,
                                         Object arg0,
                                         Object arg1,
                                         Object arg2)
                                  throws IllegalArgumentException
        Precondition-style validation that throws IllegalArgumentException.
        Parameters:
        isValid - true if valid, false if an exception should be thrown
        message - A String message for the exception.
        arg0 - First parameter of the message string template
        arg1 - Second parameter of the message string template
        arg2 - Third parameter of the message string template
        Throws:
        IllegalArgumentException - if isValid is false
      • checkArgument

        public static void checkArgument​(boolean isValid,
                                         String message,
                                         Object... args)
                                  throws IllegalArgumentException
        Precondition-style validation that throws IllegalArgumentException.
        Parameters:
        isValid - true if valid, false if an exception should be thrown
        message - A String message for the exception.
        args - Objects used to fill in %s placeholders in the message
        Throws:
        IllegalArgumentException - if isValid is false
      • checkState

        public static void checkState​(boolean isValid,
                                      String message)
                               throws IllegalStateException
        Precondition-style validation that throws IllegalStateException.
        Parameters:
        isValid - true if valid, false if an exception should be thrown
        message - A String message for the exception.
        Throws:
        IllegalStateException - if isValid is false
      • checkState

        public static void checkState​(boolean isValid,
                                      String message,
                                      Object arg0)
                               throws IllegalStateException
        Precondition-style validation that throws IllegalStateException.
        Parameters:
        isValid - true if valid, false if an exception should be thrown
        message - A String message for the exception.
        arg0 - First parameter of the message string template
        Throws:
        IllegalStateException - if isValid is false
      • checkState

        public static void checkState​(boolean isValid,
                                      String message,
                                      Object arg0,
                                      Object arg1)
                               throws IllegalStateException
        Precondition-style validation that throws IllegalStateException.
        Parameters:
        isValid - true if valid, false if an exception should be thrown
        message - A String message for the exception.
        arg0 - First parameter of the message string template
        arg1 - Second parameter of the message string template
        Throws:
        IllegalStateException - if isValid is false
      • checkState

        public static void checkState​(boolean isValid,
                                      String message,
                                      Object arg0,
                                      Object arg1,
                                      Object arg2)
                               throws IllegalStateException
        Precondition-style validation that throws IllegalStateException.
        Parameters:
        isValid - true if valid, false if an exception should be thrown
        message - A String message for the exception.
        arg0 - First parameter of the message string template
        arg1 - Second parameter of the message string template
        arg2 - Third parameter of the message string template
        Throws:
        IllegalStateException - if isValid is false
      • checkState

        public static void checkState​(boolean isValid,
                                      String message,
                                      Object... args)
                               throws IllegalStateException
        Precondition-style validation that throws IllegalStateException.
        Parameters:
        isValid - true if valid, false if an exception should be thrown
        message - A String message for the exception.
        args - Objects used to fill in %s placeholders in the message
        Throws:
        IllegalStateException - if isValid is false