Class Preconditions

java.lang.Object
io.jmix.core.common.util.Preconditions

public final class Preconditions extends Object
Simple static methods to be called at the start of your own methods to verify correct arguments and state.
  • Method Details

    • checkNotEmptyString

      public static void checkNotEmptyString(@Nullable String value)
      Ensures that a string passed as a parameter to the calling method is not empty.
      Parameters:
      value - string value
      Throws:
      IllegalArgumentException - if value is empty
    • checkNotEmptyString

      public static void checkNotEmptyString(@Nullable String value, @Nullable String errorMessage)
      Ensures that a string passed as a parameter to the calling method is not empty.
      Parameters:
      value - string value
      errorMessage - the exception message to use if the check fails; will be converted to a string using String.valueOf(Object)
      Throws:
      IllegalArgumentException - if value is empty
    • checkNotEmptyString

      public static void checkNotEmptyString(@Nullable String value, @Nullable String errorMessageTemplate, @Nullable Object... errorMessageArgs)
      Ensures that a string passed as a parameter to the calling method is not empty.
      Parameters:
      value - string value
      errorMessageTemplate - a template for the exception message should the check fail. The message is formed by replacing each %s placeholder in the template with an argument. These are matched by position - the first %s gets errorMessageArgs[0], etc.

      Unmatched arguments will be appended to the formatted message in square braces. Unmatched placeholders will be left as-is.

      errorMessageArgs - the arguments to be substituted into the message template. Arguments are converted to strings using String.valueOf(Object).
      Throws:
      IllegalArgumentException - if value is empty
    • checkNotNullArgument

      public static void checkNotNullArgument(@Nullable Object reference)
      Ensures that an object reference passed as a parameter to the calling method is not null.
      Parameters:
      reference - an object reference
      Throws:
      IllegalArgumentException - if reference is null
    • checkNotNullArgument

      public static void checkNotNullArgument(@Nullable Object reference, @Nullable String errorMessage)
      Ensures that an object reference passed as a parameter to the calling method is not null.
      Parameters:
      reference - an object reference
      errorMessage - the exception message to use if the check fails; will be converted to a string using String.valueOf(Object)
      Throws:
      IllegalArgumentException - if reference is null
    • checkNotNullArgument

      public static void checkNotNullArgument(@Nullable Object reference, @Nullable String errorMessageTemplate, @Nullable Object... errorMessageArgs)
      Ensures that an object reference passed as a parameter to the calling method is not null.
      Parameters:
      reference - an object reference
      errorMessageTemplate - a template for the exception message should the check fail. The message is formed by replacing each %s placeholder in the template with an argument. These are matched by position - the first %s gets errorMessageArgs[0], etc. Unmatched arguments will be appended to the formatted message in square braces. Unmatched placeholders will be left as-is.
      errorMessageArgs - the arguments to be substituted into the message template. Arguments are converted to strings using String.valueOf(Object).
      Throws:
      IllegalArgumentException - if reference is null
    • formatExceptionArgs

      public static String formatExceptionArgs(String template, @Nullable Object... args)