Class Validate
These methods are intended for checking the arguments of public/protected methods in library classes. To check return values, or the arguments of private/package methods, use assertions.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanValidate an axis index as a method argument.static booleanValidate a finite double-precision value as a method argument.static booleanValidate a finite single-precision value as a method argument.static booleanValidate a finite Vector3f as a method argument.static booleanValidate a non-negative proper fraction as a method argument.static booleanValidate a non-negative proper fraction as a method argument.static booleanValidate a limited double-precision value as a method argument.static booleanValidate a limited single-precision value as a method argument.static booleanValidate a limited integer as a method argument.static booleanValidate a non-null, non-empty float array as a method argument.static booleanValidate a non-null, non-empty int array as a method argument.static booleanValidate a non-null, non-empty object array as a method argument.static booleanValidate a non-null, non-empty string as a method argument.static booleannonEmpty(Collection collection, String description) Validate a non-null, non-empty collection as a method argument.static booleannonNegative(double dValue, String description) Validate a non-negative double-precision value as a method argument.static booleannonNegative(float fValue, String description) Validate a non-negative single-precision value as a method argument.static booleannonNegative(int iValue, String description) Validate a non-negative integer as a method argument.static booleannonNegative(com.jme3.math.Vector2f vector, String description) Validate a non-negative Vector2f as a method argument.static booleannonNegative(com.jme3.math.Vector3f vector, String description) Validate a non-negative Vector3f as a method argument.static booleanValidate a non-null reference.static booleannonNullArray(Object[] array, String description) Validate an array of non-null objects.static booleanValidate a non-zero single-precision value as a method argument.static booleanValidate a non-zero integer value as a method argument.static booleanValidate a non-zero long value as a method argument.static booleanValidate a non-zero Quaternion as a method argument.static booleanValidate a non-zero Vector2f as a method argument.static booleanValidate a non-zero Vector3f as a method argument.static booleanValidate a double-precision number as a method argument.static booleanValidate a single-precision number as a method argument.static booleanValidate a positive double-precision value as a method argument.static booleanValidate a positive single-precision value as a method argument.static booleanValidate a positive integer value as a method argument.static booleanValidate an all-positive Vector3f as a method argument.static booleanValidate an arbitrary boolean-valued expression involving method arguments.static booleanstandardAngle(float fValue, String description) Validate a standardized angle as a method argument.
-
Field Details
-
logger
message logger for this class -
throwNpe
public static boolean throwNpeIf true, throw NullPointerException for null arguments. Otherwise, throw IllegalArgumentException.
-
-
Method Details
-
axisIndex
Validate an axis index as a method argument.- Parameters:
iValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is outside the range [0, 2]
-
finite
Validate a finite single-precision value as a method argument.- Parameters:
fValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is NaN or infinite
-
finite
Validate a finite double-precision value as a method argument.- Parameters:
dValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is NaN or infinite
-
finite
Validate a finite Vector3f as a method argument.- Parameters:
vector- the vector to validate (unaffected)description- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the vector has a NaN or infinite componentNullPointerException- or IllegalArgumentException if the vector is null
-
fraction
Validate a non-negative proper fraction as a method argument.- Parameters:
fValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is outside the range [0, 1]
-
fraction
Validate a non-negative proper fraction as a method argument.- Parameters:
dValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is outside the range [0, 1]
-
inRange
Validate a limited integer as a method argument.- Parameters:
iValue- the value to validatedescription- a description of the argumentmin- the smallest valid value (≤max)max- the largest valid value (≥max)- Returns:
- true
- Throws:
IllegalArgumentException- if the value is outside the range [min, max]Compare with
Objects.checkIndex()in Java 9.
-
inRange
Validate a limited single-precision value as a method argument.- Parameters:
fValue- the value to validatedescription- a description of the argumentmin- the smallest valid value (≤max)max- the largest valid value (≥max)- Returns:
- true
- Throws:
IllegalArgumentException- if the value is outside the range
-
inRange
Validate a limited double-precision value as a method argument.- Parameters:
dValue- the value to validatedescription- a description of the argumentmin- the smallest valid value (≤max)max- the largest valid value (≥max)- Returns:
- true
- Throws:
IllegalArgumentException- if the value is outside the range
-
nonEmpty
Validate a non-null, non-empty collection as a method argument.- Parameters:
collection- the collection to validate (unaffected)description- a description of the argument- Returns:
- true
- Throws:
NullPointerException- or IllegalArgumentException if the collection is nullIllegalArgumentException- if the collection is empty
-
nonEmpty
Validate a non-null, non-empty float array as a method argument.- Parameters:
array- the array to validate (unaffected)description- a description of the argument- Returns:
- true
- Throws:
NullPointerException- or IllegalArgumentException if the array is nullIllegalArgumentException- if the array has zero length
-
nonEmpty
Validate a non-null, non-empty int array as a method argument.- Parameters:
array- the array to validate (unaffected)description- a description of the argument- Returns:
- true
- Throws:
NullPointerException- or IllegalArgumentException if the array is nullIllegalArgumentException- if the array has zero length
-
nonEmpty
Validate a non-null, non-empty object array as a method argument.- Parameters:
array- the array to validate (unaffected)description- a description of the argument- Returns:
- true
- Throws:
NullPointerException- or IllegalArgumentException if the array is nullIllegalArgumentException- if the array has zero length
-
nonEmpty
Validate a non-null, non-empty string as a method argument.- Parameters:
string- the String to validatedescription- a description of the argument- Returns:
- true
- Throws:
NullPointerException- or IllegalArgumentException if the String is nullIllegalArgumentException- if the String has zero length
-
nonNegative
Validate a non-negative integer as a method argument.- Parameters:
iValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is negative
-
nonNegative
Validate a non-negative single-precision value as a method argument.- Parameters:
fValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is negative or NaN
-
nonNegative
Validate a non-negative double-precision value as a method argument.- Parameters:
dValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is negative or NaN
-
nonNegative
Validate a non-negative Vector2f as a method argument.- Parameters:
vector- the vector to validate (unaffected)description- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the vector has a negative or NaN componentNullPointerException- or IllegalArgumentException if the vector is null
-
nonNegative
Validate a non-negative Vector3f as a method argument.- Parameters:
vector- the vector to validate (unaffected)description- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the vector has a negative or NaN componentNullPointerException- or IllegalArgumentException if the vector is null
-
nonNull
Validate a non-null reference. In many methods, validation can be omitted because the object in question is about to be dereferenced.While it might seem more logical to throw an IllegalArgumentException in the case of a method argument, the javadoc for NullPointerException says, "Applications should throw instances of this class to indicate other illegal uses of the null object." To throw an IllegalArgumentException instead, set
throwNpeto false.Compare with
java.util.Objects.requireNonNull().- Parameters:
object- the reference to validatedescription- a description of the argument- Returns:
- true
- Throws:
NullPointerException- or IllegalArgumentException if the reference is null
-
nonNullArray
Validate an array of non-null objects.While it might seem more logical to throw an IllegalArgumentException in the case of a method argument, the javadoc for NullPointerException says, "Applications should throw instances of this class to indicate other illegal uses of the null object." To throw an IllegalArgumentException instead, set
throwNpeto false.- Parameters:
array- the array to validate (unaffected)description- a description of the argument- Returns:
- true
- Throws:
NullPointerException- or IllegalArgumentException if the array is null or contains a null element
-
nonZero
Validate a non-zero integer value as a method argument.- Parameters:
iValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is zero
-
nonZero
Validate a non-zero long value as a method argument.- Parameters:
lValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is zero
-
nonZero
Validate a non-zero single-precision value as a method argument.- Parameters:
fValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is zero
-
nonZero
Validate a non-zero Quaternion as a method argument.- Parameters:
quaternion- the Quaternion to validate (unaffected)description- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the Quaternion equals (0,0,0,0)NullPointerException- or IllegalArgumentException if the Quaternion is null
-
nonZero
Validate a non-zero Vector2f as a method argument.- Parameters:
vector- the vector to validate (unaffected)description- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the vector equals (0,0)NullPointerException- or IllegalArgumentException if the vector is null
-
nonZero
Validate a non-zero Vector3f as a method argument.- Parameters:
vector- the vector to validate (unaffected)description- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the vector equals (0,0,0)NullPointerException- or IllegalArgumentException if the vector is null
-
number
Validate a single-precision number as a method argument.- Parameters:
fValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is NaN
-
number
Validate a double-precision number as a method argument.- Parameters:
dValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is NaN
-
positive
Validate a positive integer value as a method argument.- Parameters:
iValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is negative or zero
-
positive
Validate a positive single-precision value as a method argument.- Parameters:
fValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is not positive
-
positive
Validate a positive double-precision value as a method argument.- Parameters:
dValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is not positive
-
positive
Validate an all-positive Vector3f as a method argument.- Parameters:
vector- the vector to validate (unaffected)description- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if any component is not positiveNullPointerException- or IllegalArgumentException if the vector is null
-
require
Validate an arbitrary boolean-valued expression involving method arguments.- Parameters:
value- the value of the expression (required to be true)what- a description of the requirement- Returns:
- true
- Throws:
IllegalArgumentException- if the value is false
-
standardAngle
Validate a standardized angle as a method argument.- Parameters:
fValue- the value to validatedescription- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException- if the value is outside the range [-PI, PI]
-