Class PreconditionsUtils

java.lang.Object
google.registry.util.PreconditionsUtils

public class PreconditionsUtils extends Object
Utility methods related to preconditions checking.
  • 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

      public static <T> T checkArgumentNotNull(@Nullable T reference, @Nullable Object errorMessage)
      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

      public static <T> T checkArgumentPresent(@Nullable Optional<T> reference)
      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.