Package org.conscrypt
Class Preconditions
- java.lang.Object
-
- org.conscrypt.Preconditions
-
final class Preconditions extends java.lang.Object
Static convenience methods that help a method or constructor check whether it was invoked correctly (that is, whether its preconditions were met).
-
-
Constructor Summary
Constructors Modifier Constructor Description private
Preconditions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.String
badPositionIndex(int index, int size, java.lang.String desc)
private static java.lang.String
badPositionIndexes(int start, int end, int size)
(package private) static void
checkArgument(boolean condition, java.lang.String errorMessage)
Ensures the truth of an expression involving one or more parameters to the calling method.(package private) static void
checkArgument(boolean condition, java.lang.String errorMessageTemplate, java.lang.Object arg)
Ensures the truth of an expression involving one or more parameters to the calling method.(package private) 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.(package private) static void
checkPositionIndexes(int start, int end, int size)
Ensures thatstart
andend
specify a valid positions in an array, list or string of sizesize
, and are in order.
-
-
-
Method Detail
-
checkNotNull
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
- ifreference
is null
-
checkArgument
static void checkArgument(boolean condition, java.lang.String errorMessage)
Ensures the truth of an expression involving one or more parameters to the calling method.- Parameters:
condition
- to condition to be testederrorMessage
- the exception message to use if the check fails.- Throws:
java.lang.IllegalArgumentException
- if the condition isfalse
-
checkArgument
static void checkArgument(boolean condition, java.lang.String errorMessageTemplate, java.lang.Object arg)
Ensures the truth of an expression involving one or more parameters to the calling method.- Parameters:
condition
- to condition to be testederrorMessageTemplate
- the format string to be passed toString.format(String, Object...)
arg
- the format argument to be passed toString.format(String, Object...)
- Throws:
java.lang.IllegalArgumentException
- if the condition isfalse
-
checkPositionIndexes
static void checkPositionIndexes(int start, int end, int size)
Ensures thatstart
andend
specify a valid positions in an array, list or string of sizesize
, and are in order. A position index may range from zero tosize
, inclusive.- Parameters:
start
- a user-supplied index identifying a starting position in an array, list or stringend
- a user-supplied index identifying a ending position in an array, list or stringsize
- the size of that array, list or string- Throws:
java.lang.IndexOutOfBoundsException
- if either index is negative or is greater thansize
, or ifend
is less thanstart
java.lang.IllegalArgumentException
- ifsize
is negative
-
badPositionIndexes
private static java.lang.String badPositionIndexes(int start, int end, int size)
-
badPositionIndex
private static java.lang.String badPositionIndex(int index, int size, java.lang.String desc)
-
-