Class Preconditions
- java.lang.Object
-
- com.google.ar.sceneform.utilities.Preconditions
-
public class Preconditions extends java.lang.Object
Static 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 void
checkElementIndex(int index, int size)
Ensures thatindex
specifies a valid element in an array, list or string of sizesize
.static void
checkElementIndex(int index, int size, java.lang.String desc)
Ensures thatindex
specifies a valid element in an array, list or string of sizesize
.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.Object errorMessage)
Ensures that an object reference passed as a parameter to the calling method is not null.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.static void
checkState(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
- ifreference
is 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
- ifreference
is null
-
checkElementIndex
public static void checkElementIndex(int index, int size)
Ensures thatindex
specifies 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
- ifindex
is negative or is not less thansize
java.lang.IllegalArgumentException
- ifsize
is negative
-
checkElementIndex
public static void checkElementIndex(int index, int size, java.lang.String desc)
Ensures thatindex
specifies 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
- ifindex
is negative or is not less thansize
java.lang.IllegalArgumentException
- ifsize
is 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
- ifexpression
is 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
- ifexpression
is false
-
-