Class Preconditions


  • public final class Preconditions
    extends Object
    Utility class for guava style pre-condition checks.

    Not an official part of the AppAuth API; only intended for internal use and no guarantees are given on source or binary compatibility for this class between versions of AppAuth.

    • Method Detail

      • checkNotNull

        public static <T> T checkNotNull​(T reference)
        Ensures that an object reference passed as a parameter to the calling method is not null.
        Parameters:
        reference - an object reference
        Returns:
        the non-null reference that was validated
        Throws:
        NullPointerException - if reference is null
      • checkNotNull

        public static <T> T checkNotNull​(T reference,
                                         @Nullable
                                         Object 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)
        Returns:
        the non-null reference that was validated
        Throws:
        NullPointerException - if reference is null
      • checkArgument

        public static void checkArgument​(boolean expression)
        Ensures the truth of an expression involving one or more parameters to the calling method.
        Parameters:
        expression - a boolean expression
        Throws:
        IllegalArgumentException - if expression is false
      • checkArgument

        public static void checkArgument​(boolean expression,
                                         @Nullable
                                         Object errorMessage)
        Ensures the truth of an expression involving one or more parameters to the calling method.
        Parameters:
        expression - a boolean expression
        errorMessage - the exception message to use if the check fails; will be converted to a string using String.valueOf(Object)
        Throws:
        IllegalArgumentException - if expression is false
      • checkArgument

        public static void checkArgument​(boolean expression,
                                         @NonNull
                                         String errorTemplate,
                                         Object... params)
        Ensures the truth of an expression involving one or more parameters to the calling method.
        Parameters:
        expression - a boolean expression
        errorTemplate - the exception message to use if the check fails; this is used as the template for String.format.
        params - the parameters to the exception message.