Package jme3utilities
Class Validate
java.lang.Object
jme3utilities.Validate
Utility methods to throw exceptions for invalid method arguments.
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Validate an axis index as a method argument.static boolean
Validate a finite single-precision value as a method argument.static boolean
Validate a finite Vector3f as a method argument.static boolean
Validate a finite Vec3d as a method argument.static boolean
Validate a non-negative proper fraction as a method argument.static boolean
Validate a non-negative proper fraction as a method argument.static boolean
Validate a limited double-precision value as a method argument.static boolean
Validate a limited single-precision value as a method argument.static boolean
Validate a limited integer as a method argument.static boolean
Validate a non-null, non-empty float array as a method argument.static boolean
Validate a non-null, non-empty object array as a method argument.static boolean
Validate a non-null, non-empty string as a method argument.static boolean
nonEmpty
(Collection collection, String description) Validate a non-null, non-empty collection as a method argument.static boolean
nonNegative
(float fValue, String description) Validate a non-negative single-precision value as a method argument.static boolean
nonNegative
(int iValue, String description) Validate a non-negative integer as a method argument.static boolean
nonNegative
(Vector3f vector, String description) Validate a non-negative Vector3f as a method argument.static boolean
Validate a non-null reference.static boolean
Validate a non-zero long value as a method argument.static boolean
nonZero
(Quaternion quaternion, String description) Validate a non-zero Quaternion as a method argument.static boolean
Validate a non-zero Vector3f as a method argument.static boolean
Validate a non-zero Quatd as a method argument.static boolean
Validate a positive single-precision value as a method argument.static boolean
Validate a positive integer value as a method argument.static boolean
Validate an all-positive Vector3f as a method argument.static boolean
Validate an arbitrary boolean-valued expression involving method arguments.static boolean
standardAngle
(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 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
-
finite
Validate a finite Vec3d 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 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 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
throwNpe
to 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
-
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 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 Quatd as a method argument.- Parameters:
quaternion
- the Quatd to validate (unaffected)description
- a description of the argument- Returns:
- true
- Throws:
IllegalArgumentException
- if the Quatd equals (0,0,0,0)NullPointerException
- or IllegalArgumentException if the Quatd 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
-
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 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]
-