Class Preconditions


  • public final class Preconditions
    extends java.lang.Object
    Precondition checking utility methods.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void checkArgument​(boolean expression, java.lang.String errorMessage)
      Ensures the truth of an expression involving parameters to the calling method.
      static void checkConfigured​(android.content.Context context, java.lang.String message, int... ids)  
      static <T> T checkNotNull​(T val, java.lang.String errorMessageTemplate, java.lang.Object... errorMessageArgs)
      Ensures that the provided value is not null, and throws a NullPointerException if it is null, with a message constructed from the provided error template and arguments.
      static void checkUnset​(android.os.Bundle b, java.lang.String message, java.lang.String... keys)  
      static int checkValidStyle​(android.content.Context context, int styleId, java.lang.String errorMessageTemplate, java.lang.Object... errorMessageArguments)
      Ensures that the provided identifier matches a known style resource, and throws an IllegalArgumentException if the resource cannot be found, or is not a style resource, with a message constructed from the provided error template and arguments.
      • Methods inherited from class java.lang.Object

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

      • checkNotNull

        @NonNull
        public static <T> T checkNotNull​(@Nullable
                                         T val,
                                         @NonNull
                                         java.lang.String errorMessageTemplate,
                                         @Nullable
                                         java.lang.Object... errorMessageArgs)
        Ensures that the provided value is not null, and throws a NullPointerException if it is null, with a message constructed from the provided error template and arguments.
      • checkValidStyle

        @StyleRes
        public static int checkValidStyle​(@NonNull
                                          android.content.Context context,
                                          int styleId,
                                          @NonNull
                                          java.lang.String errorMessageTemplate,
                                          @Nullable
                                          java.lang.Object... errorMessageArguments)
        Ensures that the provided identifier matches a known style resource, and throws an IllegalArgumentException if the resource cannot be found, or is not a style resource, with a message constructed from the provided error template and arguments.
      • checkUnset

        public static void checkUnset​(@NonNull
                                      android.os.Bundle b,
                                      @Nullable
                                      java.lang.String message,
                                      @NonNull
                                      java.lang.String... keys)
      • checkConfigured

        public static void checkConfigured​(@NonNull
                                           android.content.Context context,
                                           @Nullable
                                           java.lang.String message,
                                           @StringRes
                                           int... ids)
      • checkArgument

        public static void checkArgument​(boolean expression,
                                         java.lang.String errorMessage)
        Ensures the truth of an expression involving parameters to the calling method.
        Parameters:
        expression - a boolean expression
        errorMessage - the exception message to use if the check fails
        Throws:
        java.lang.IllegalArgumentException - if expression is false