Module dagger

Class Preconditions


  • public final class Preconditions
    extends java.lang.Object
    An adaptation of Guava's Preconditions that is specially tailored to support checks applied in Dagger's generated code.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> void checkBuilderRequirement​(T requirement, java.lang.Class<T> clazz)
      Checks that the component builder field requirement has been initialized.
      static <T> T checkNotNull​(T reference)
      Ensures that an object reference passed as a parameter to the calling method is not null.
      static <T> T checkNotNull​(T reference, java.lang.String errorMessage)
      Ensures that an object reference passed as a parameter to the calling method is not null.
      static <T> T checkNotNull​(T reference, java.lang.String errorMessageTemplate, java.lang.Object errorMessageArg)
      Ensures that an object reference passed as a parameter to the calling method is not null.
      static <T> T checkNotNullFromComponent​(T reference)
      Ensures that an object reference returned from a component method is not null.
      static <T> T checkNotNullFromProvides​(T reference)
      Ensures that an object reference returned from a provides method is not null.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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:
        java.lang.NullPointerException - if reference is null
      • checkNotNull

        public static <T> T checkNotNull​(T reference,
                                         java.lang.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
        Returns:
        the non-null reference that was validated
        Throws:
        java.lang.NullPointerException - if reference is null
      • checkNotNullFromProvides

        public static <T> T checkNotNullFromProvides​(T reference)
        Ensures that an object reference returned from a provides method is not null.
        Parameters:
        reference - an object reference
        Returns:
        the non-null reference that was validated
        Throws:
        java.lang.NullPointerException - if reference is null
      • checkNotNullFromComponent

        public static <T> T checkNotNullFromComponent​(T reference)
        Ensures that an object reference returned from a component method is not null.
        Parameters:
        reference - an object reference
        Returns:
        the non-null reference that was validated
        Throws:
        java.lang.NullPointerException - if reference is null
      • checkNotNull

        public static <T> T checkNotNull​(T reference,
                                         java.lang.String errorMessageTemplate,
                                         java.lang.Object errorMessageArg)
        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 the single %s placeholder in the template with errorMessageArg.
        errorMessageArg - the argument to be substituted into the message template. Converted to a string using String.valueOf(Object), except for Class objects, which use Class.getCanonicalName().
        Returns:
        the non-null reference that was validated
        Throws:
        java.lang.NullPointerException - if reference is null
        java.lang.IllegalArgumentException - if errorMessageTemplate doesn't contain exactly one "%s"
      • checkBuilderRequirement

        public static <T> void checkBuilderRequirement​(T requirement,
                                                       java.lang.Class<T> clazz)
        Checks that the component builder field requirement has been initialized.
        Throws:
        java.lang.IllegalStateException - if requirement is null