public final class JobPreconditions extends Object
Modifier and Type | Method and Description |
---|---|
static float |
checkArgumentFinite(float value,
String valueName)
Ensures that the argument floating point value is a finite number.
|
static float |
checkArgumentInRange(float value,
float lower,
float upper,
String valueName)
Ensures that the argument floating point value is within the inclusive range.
|
static int |
checkArgumentInRange(int value,
int lower,
int upper,
String valueName)
Ensures that the argument int value is within the inclusive range.
|
static long |
checkArgumentInRange(long value,
long lower,
long upper,
String valueName)
Ensures that the argument int value is within the inclusive range.
|
static int |
checkArgumentNonnegative(int value,
String errorMessage)
Ensures that that the argument numeric value is non-negative.
|
static long |
checkArgumentNonnegative(long value,
String errorMessage)
Ensures that that the argument numeric value is non-negative.
|
static int |
checkArgumentPositive(int value,
String errorMessage)
Ensures that that the argument numeric value is positive.
|
static long |
checkArgumentPositive(long value,
String errorMessage)
Ensures that that the argument numeric value is positive.
|
static float[] |
checkArrayElementsInRange(float[] value,
float lower,
float upper,
String valueName)
Ensures that all elements in the argument floating point array are within the inclusive range
|
static <T> T[] |
checkArrayElementsNotNull(T[] value,
String valueName)
Ensures that the array is not
null , and none of its elements are null . |
static <T> Collection<T> |
checkCollectionElementsNotNull(Collection<T> value,
String valueName)
|
static <T> Collection<T> |
checkCollectionNotEmpty(Collection<T> value,
String valueName)
Ensures that the
Collection is not null , and contains at least one element. |
static void |
checkFlagsArgument(int requestedFlags,
int allowedFlags)
Check the requested flags, throwing if any requested flags are outside
the allowed set.
|
static <T extends CharSequence> |
checkNotEmpty(T reference)
Ensures that a CharSequence passed as a parameter to the calling method is
not null and not empty.
|
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,
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.
|
public static <T> T checkNotNull(T reference)
reference
- an object referenceNullPointerException
- if reference
is nullpublic static <T> T checkNotNull(T reference, Object errorMessage)
reference
- an object referenceerrorMessage
- the exception message to use if the check fails; will
be converted to a string using String.valueOf(Object)
NullPointerException
- if reference
is nullpublic static <T extends CharSequence> T checkNotEmpty(T reference)
reference
- an CharSequence referenceIllegalArgumentException
- if reference
was null or emptypublic static void checkState(boolean expression)
expression
- a boolean expressionIllegalStateException
- if expression
is falsepublic static void checkFlagsArgument(int requestedFlags, int allowedFlags)
public static int checkArgumentNonnegative(int value, String errorMessage)
value
- a numeric int valueerrorMessage
- the exception message to use if the check failsIllegalArgumentException
- if value
was negativepublic static long checkArgumentNonnegative(long value, String errorMessage)
value
- a numeric long valueerrorMessage
- the exception message to use if the check failsIllegalArgumentException
- if value
was negativepublic static int checkArgumentPositive(int value, String errorMessage)
value
- a numeric int valueerrorMessage
- the exception message to use if the check failsIllegalArgumentException
- if value
was not positivepublic static long checkArgumentPositive(long value, String errorMessage)
value
- a numeric long valueerrorMessage
- the exception message to use if the check failsIllegalArgumentException
- if value
was not positivepublic static float checkArgumentFinite(float value, String valueName)
A finite number is defined to be both representable (that is, not NaN) and not infinite (that is neither positive or negative infinity).
value
- a floating point valuevalueName
- the name of the argument to use if the check failsIllegalArgumentException
- if value
was not finitepublic static float checkArgumentInRange(float value, float lower, float upper, String valueName)
While this can be used to range check against +/- infinity, note that all NaN numbers will always be out of range.
value
- a floating point valuelower
- the lower endpoint of the inclusive rangeupper
- the upper endpoint of the inclusive rangevalueName
- the name of the argument to use if the check failsIllegalArgumentException
- if value
was not within the rangepublic static int checkArgumentInRange(int value, int lower, int upper, String valueName)
value
- a int valuelower
- the lower endpoint of the inclusive rangeupper
- the upper endpoint of the inclusive rangevalueName
- the name of the argument to use if the check failsIllegalArgumentException
- if value
was not within the rangepublic static long checkArgumentInRange(long value, long lower, long upper, String valueName)
value
- a long valuelower
- the lower endpoint of the inclusive rangeupper
- the upper endpoint of the inclusive rangevalueName
- the name of the argument to use if the check failsIllegalArgumentException
- if value
was not within the rangepublic static <T> T[] checkArrayElementsNotNull(T[] value, String valueName)
null
, and none of its elements are null
.value
- an array of boxed objectsvalueName
- the name of the argument to use if the check failsNullPointerException
- if the value
or any of its elements were null
public static <T> Collection<T> checkCollectionElementsNotNull(Collection<T> value, String valueName)
value
- a Collection
of boxed objectsvalueName
- the name of the argument to use if the check failsCollection
NullPointerException
- if the value
or any of its elements were null
public static <T> Collection<T> checkCollectionNotEmpty(Collection<T> value, String valueName)
Collection
is not null
, and contains at least one element.value
- a Collection
of boxed elements.valueName
- the name of the argument to use if the check fails.Collection
NullPointerException
- if the value
was null
IllegalArgumentException
- if the value
was emptypublic static float[] checkArrayElementsInRange(float[] value, float lower, float upper, String valueName)
While this can be used to range check against +/- infinity, note that all NaN numbers will always be out of range.
value
- a floating point array of valueslower
- the lower endpoint of the inclusive rangeupper
- the upper endpoint of the inclusive rangevalueName
- the name of the argument to use if the check failsIllegalArgumentException
- if any of the elements in value
were out of rangeNullPointerException
- if the value
was null