- java.lang.Object
-
- dagger.internal.Preconditions
-
public final class Preconditions extends java.lang.ObjectAn 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> voidcheckBuilderRequirement(T requirement, java.lang.Class<T> clazz)Checks that the component builder fieldrequirementhas been initialized.static <T> TcheckNotNull(T reference)Ensures that an object reference passed as a parameter to the calling method is not null.static <T> TcheckNotNull(T reference, java.lang.String errorMessage)Ensures that an object reference passed as a parameter to the calling method is not null.static <T> TcheckNotNull(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> TcheckNotNullFromComponent(T reference)Ensures that an object reference returned from a component method is not null.static <T> TcheckNotNullFromProvides(T reference)Ensures that an object reference returned from a provides method is not null.
-
-
-
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- ifreferenceis 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 referenceerrorMessage- the exception message to use if the check fails- Returns:
- the non-null reference that was validated
- Throws:
java.lang.NullPointerException- ifreferenceis 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- ifreferenceis 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- ifreferenceis 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 referenceerrorMessageTemplate- a template for the exception message should the check fail. The message is formed by replacing the single%splaceholder in the template witherrorMessageArg.errorMessageArg- the argument to be substituted into the message template. Converted to a string usingString.valueOf(Object), except forClassobjects, which useClass.getCanonicalName().- Returns:
- the non-null reference that was validated
- Throws:
java.lang.NullPointerException- ifreferenceis nulljava.lang.IllegalArgumentException- iferrorMessageTemplatedoesn't contain exactly one "%s"
-
checkBuilderRequirement
public static <T> void checkBuilderRequirement(T requirement, java.lang.Class<T> clazz)Checks that the component builder fieldrequirementhas been initialized.- Throws:
java.lang.IllegalStateException- ifrequirement is null
-
-