Class Preconditions
- java.lang.Object
-
- com.google.ar.sceneform.utilities.Preconditions
-
public class Preconditions extends java.lang.ObjectStatic convenience methods that help a method or constructor check whether it was invoked correctly.
-
-
Constructor Summary
Constructors Constructor Description Preconditions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckElementIndex(int index, int size)Ensures thatindexspecifies a valid element in an array, list or string of sizesize.static voidcheckElementIndex(int index, int size, java.lang.String desc)Ensures thatindexspecifies a valid element in an array, list or string of sizesize.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.Object errorMessage)Ensures that an object reference passed as a parameter to the calling method is not null.static voidcheckState(boolean expression)Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.static voidcheckState(boolean expression, java.lang.Object errorMessage)Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.
-
-
-
Method Detail
-
checkNotNull
public static <T> T checkNotNull(@Nullable T reference)Ensures that an object reference passed as a parameter to the calling method is not null.- Parameters:
reference- an object reference- Throws:
java.lang.NullPointerException- ifreferenceis null
-
checkNotNull
public static <T> T checkNotNull(@Nullable T reference, java.lang.Object 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; will be converted to a string usingString.valueOf(Object)- Throws:
java.lang.NullPointerException- ifreferenceis null
-
checkElementIndex
public static void checkElementIndex(int index, int size)Ensures thatindexspecifies a valid element in an array, list or string of sizesize. An element index may range from zero, inclusive, tosize, exclusive.- Parameters:
index- a user-supplied index identifying an element of an array, list or stringsize- the size of that array, list or string- Throws:
java.lang.IndexOutOfBoundsException- ifindexis negative or is not less thansizejava.lang.IllegalArgumentException- ifsizeis negative
-
checkElementIndex
public static void checkElementIndex(int index, int size, java.lang.String desc)Ensures thatindexspecifies a valid element in an array, list or string of sizesize. An element index may range from zero, inclusive, tosize, exclusive.- Parameters:
index- a user-supplied index identifying an element of an array, list or stringsize- the size of that array, list or stringdesc- the text to use to describe this index in an error message- Throws:
java.lang.IndexOutOfBoundsException- ifindexis negative or is not less thansizejava.lang.IllegalArgumentException- ifsizeis negative
-
checkState
public static void checkState(boolean expression)
Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.- Parameters:
expression- a boolean expression- Throws:
java.lang.IllegalStateException- ifexpressionis false
-
checkState
public static void checkState(boolean expression, @Nullable java.lang.Object errorMessage)Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.- Parameters:
expression- a boolean expressionerrorMessage- the exception message to use if the check fails; will be converted to a string usingString.valueOf(Object)- Throws:
java.lang.IllegalStateException- ifexpressionis false
-
-