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
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanValidate an axis index as a method argument.static booleanValidate a finite single-precision value as a method argument.static booleanValidate a finiteVector3fas a method argument.static booleanValidate a finiteVec3das 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 value as a method argument.static booleanValidate a non-null, non-empty float 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(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 value as a method argument.static booleannonNegative(Vector3f vector, String description) Validate a non-negativeVector3fas a method argument.static booleanValidate a non-null reference.static booleanValidate a non-zero long value as a method argument.static booleannonZero(Quaternion quaternion, String description) Validate a non-zeroQuaternionas a method argument.static booleanValidate a non-zeroVector3fas a method argument.static booleanValidate a non-zeroQuatdas 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-positiveVector3fas 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 throwNpeIftrue, throwNullPointerExceptionfor null arguments. Otherwise, throwIllegalArgumentException.
-
-
Method Details
-
axisIndex
Validate an axis index as a method argument.- Parameters:
iValue- the index to validatedescription- a description of the argument- Returns:
true(for use inassertstatements)- 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(for use inassertstatements)- Throws:
IllegalArgumentException- if the value is NaN or infinite
-
finite
Validate a finiteVec3das a method argument.- Parameters:
vector- the vector to validate (unaffected)description- a description of the argument- Returns:
true(for use inassertstatements)- Throws:
IllegalArgumentException- if the vector has a NaN or infinite componentNullPointerException- or IllegalArgumentException if the vector isnull
-
finite
Validate a finiteVector3fas a method argument.- Parameters:
vector- the vector to validate (unaffected)description- a description of the argument- Returns:
true(for use inassertstatements)- Throws:
IllegalArgumentException- if the vector has a NaN or infinite componentNullPointerException- or IllegalArgumentException if the vector isnull
-
fraction
Validate a non-negative proper fraction as a method argument.- Parameters:
dValue- the value to validatedescription- a description of the argument- Returns:
true(for use inassertstatements)- Throws:
IllegalArgumentException- if the value is outside the range [0, 1]
-
fraction
Validate a non-negative proper fraction as a method argument.- Parameters:
fValue- the value to validatedescription- a description of the argument- Returns:
true(for use inassertstatements)- Throws:
IllegalArgumentException- if the value is outside the range [0, 1]
-
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(for use inassertstatements)- Throws:
IllegalArgumentException- if the value is outside the range [min, max]
-
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(for use inassertstatements)- Throws:
IllegalArgumentException- if the value is outside the range [min, max]
-
inRange
Validate a limited integer value 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(for use inassertstatements)- Throws:
IllegalArgumentException- if the value is outside the range [min, max]Compare with
Objects.checkIndex()in Java 9.
-
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(for use inassertstatements)- 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(for use inassertstatements)- 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(for use inassertstatements)- 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(for use inassertstatements)- Throws:
NullPointerException- or IllegalArgumentException if the String is nullIllegalArgumentException- if the String has zero length
-
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(for use inassertstatements)- Throws:
IllegalArgumentException- if the value is negative or NaN
-
nonNegative
Validate a non-negative integer value as a method argument.- Parameters:
iValue- the value to validatedescription- a description of the argument- Returns:
true(for use inassertstatements)- Throws:
IllegalArgumentException- if the value is negative
-
nonNegative
Validate a non-negativeVector3fas a method argument.- Parameters:
vector- the vector to validate (unaffected)description- a description of the argument- Returns:
true(for use inassertstatements)- 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 situations, 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 validate (unaffected)description- a description of the argument- Returns:
true(for use inassertstatements)- Throws:
NullPointerException- or IllegalArgumentException if the reference isnull
-
nonZero
Validate a non-zero long value as a method argument.- Parameters:
lValue- the value to validatedescription- a description of the argument- Returns:
true(for use inassertstatements)- Throws:
IllegalArgumentException- if the value is zero
-
nonZero
Validate a non-zeroQuatdas a method argument.- Parameters:
quaternion- the value to validate (unaffected)description- a description of the argument- Returns:
true(for use inassertstatements)- Throws:
IllegalArgumentException- if the Quatd equals (0,0,0,0)NullPointerException- or IllegalArgumentException if the Quatd is null
-
nonZero
Validate a non-zeroQuaternionas a method argument.- Parameters:
quaternion- the value to validate (unaffected)description- a description of the argument- Returns:
true(for use inassertstatements)- Throws:
IllegalArgumentException- if the Quaternion equals (0,0,0,0)NullPointerException- or IllegalArgumentException if the Quaternion is null
-
nonZero
Validate a non-zeroVector3fas a method argument.- Parameters:
vector- the vector to validate (unaffected)description- a description of the argument- Returns:
true(for use inassertstatements)- Throws:
IllegalArgumentException- if the vector equals (0,0,0)NullPointerException- or IllegalArgumentException if the vector is null
-
positive
Validate a positive single-precision value as a method argument.- Parameters:
fValue- the value to validatedescription- a description of the argument- Returns:
true(for use inassertstatements)- Throws:
IllegalArgumentException- if the value is negative or zero or NaN
-
positive
Validate a positive integer value as a method argument.- Parameters:
iValue- the value to validatedescription- a description of the argument- Returns:
true(for use inassertstatements)- Throws:
IllegalArgumentException- if the value is negative or zero
-
positive
Validate an all-positiveVector3fas a method argument.- Parameters:
vector- the vector to validate (unaffected)description- a description of the argument- Returns:
true(for use inassertstatements)- 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 betrue)what- a description of the requirement- Returns:
true(for use inassertstatements)- Throws:
IllegalArgumentException- if the value isfalse
-
standardAngle
Validate a standardized angle as a method argument.- Parameters:
fValue- the angle to validatedescription- a description of the argument- Returns:
true(for use inassertstatements)- Throws:
IllegalArgumentException- if the value is outside the range [-PI, PI]
-