Class Utils


  • @Immutable
    public final class Utils
    extends Object
    General internal utility methods.
    • Method Detail

      • checkArgument

        public static void checkArgument​(boolean isValid,
                                         String errorMessage)
        Throws an IllegalArgumentException if the argument is false. This method is similar to Preconditions.checkArgument(boolean, Object) from Guava.
        Parameters:
        isValid - whether the argument check passed.
        errorMessage - the message to use for the exception.
      • checkArgument

        public static void checkArgument​(boolean expression,
                                         String errorMessageTemplate,
                                         Object... errorMessageArgs)
        Throws an IllegalArgumentException if the argument is false. This method is similar to Preconditions.checkArgument(boolean, Object) from Guava.
        Parameters:
        expression - a boolean expression
        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 expression is false
        NullPointerException - if the check fails and either errorMessageTemplate or errorMessageArgs is null (don't let this happen)
      • checkState

        public static void checkState​(boolean isValid,
                                      String errorMessage)
        Throws an IllegalStateException if the argument is false. This method is similar to Preconditions.checkState(boolean, Object) from Guava.
        Parameters:
        isValid - whether the state check passed.
        errorMessage - the message to use for the exception.
      • validateLabelPairs

        public static void validateLabelPairs​(String[] keyValuePairs)
        Validates that the array of Strings is 1) even in length, and 2) they can be formed into valid pairs where the first item in the pair is not null.

        TODO: write unit tests for this method.

        Parameters:
        keyValuePairs - The String[] to validate for correctness.
        Throws:
        IllegalArgumentException - if any of the preconditions are violated.