Class Preconditions


  • public final class Preconditions
    extends Object
    Precondition checking utility methods.
    • Method Detail

      • checkNotNull

        @NonNull
        public static <T> T checkNotNull​(@Nullable
                                         T val,
                                         @NonNull
                                         String errorMessageTemplate,
                                         @Nullable
                                         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
                                          Context context,
                                          int styleId,
                                          @NonNull
                                          String errorMessageTemplate,
                                          @Nullable
                                          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
                                      Bundle b,
                                      @Nullable
                                      String message,
                                      @NonNull
                                      String... keys)
      • checkConfigured

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

        public static void checkArgument​(boolean expression,
                                         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:
        IllegalArgumentException - if expression is false