Package google.registry.util
Class PreconditionsUtils
java.lang.Object
google.registry.util.PreconditionsUtils
Utility methods related to preconditions checking.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
checkArgumentNotNull
(T reference) Checks whether the provided reference is null, throws IAE if it is, and returns it if not.static <T> T
checkArgumentNotNull
(T reference, Object errorMessage) Checks whether the provided reference is null, throws IAE if it is, and returns it if not.static <T> T
checkArgumentNotNull
(T reference, String errorMessageTemplate, Object... errorMessageArgs) Checks whether the provided reference is null, throws IAE if it is, and returns it if not.static <T> T
checkArgumentPresent
(Optional<T> reference) Checks if the provided Optional is present, returns its value if so, and throws IAE if not.static <T> T
checkArgumentPresent
(Optional<T> reference, Object errorMessage) Checks if the provided Optional is present, returns its value if so, and throws IAE if not.static <T> T
checkArgumentPresent
(Optional<T> reference, String errorMessageTemplate, Object... errorMessageArgs) Checks if the provided Optional is present, returns its value if so, and throws IAE if not.
-
Constructor Details
-
PreconditionsUtils
public PreconditionsUtils()
-
-
Method Details
-
checkArgumentNotNull
public static <T> T checkArgumentNotNull(@Nullable T reference) Checks whether the provided reference is null, throws IAE if it is, and returns it if not.This method and its overloads are to substitute for checkNotNull() in cases where it's preferable to throw an IAE instead of an NPE, such as where we want an IAE to indicate that it's just a bad argument/parameter and reserve NPEs for bugs and unexpected null values.
-
checkArgumentNotNull
Checks whether the provided reference is null, throws IAE if it is, and returns it if not. -
checkArgumentNotNull
public static <T> T checkArgumentNotNull(@Nullable T reference, @Nullable String errorMessageTemplate, @Nullable Object... errorMessageArgs) Checks whether the provided reference is null, throws IAE if it is, and returns it if not. -
checkArgumentPresent
Checks if the provided Optional is present, returns its value if so, and throws IAE if not. -
checkArgumentPresent
public static <T> T checkArgumentPresent(@Nullable Optional<T> reference, @Nullable Object errorMessage) Checks if the provided Optional is present, returns its value if so, and throws IAE if not. -
checkArgumentPresent
public static <T> T checkArgumentPresent(@Nullable Optional<T> reference, @Nullable String errorMessageTemplate, @Nullable Object... errorMessageArgs) Checks if the provided Optional is present, returns its value if so, and throws IAE if not.
-