|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectStatic
ArgumentChecks
public final class ArgumentChecks
Provides static methods for performing argument checks. The methods in this class throw one of the following exceptions (or a subclass of them) widely used in standard Java API:
| Exception | Thrown by|
|---|---|
NullPointerException |
ensureNonNull |
IndexOutOfBoundsException |
ensureValidIndex |
IllegalArgumentException |
ensurePositive,
ensureStrictlyPositive,
ensureBetween |
Method Arguments
By convention, the value to check is always the last parameter given to every methods
in this class. The other parameters may include the programmatic name of the argument
being checked. This programmatic name is used for building an error message localized
in the default locale if the check failed.
| utility/geotk-utility (download) | View source code for this class |
| Method Summary | ||
|---|---|---|
static void |
ensureBetween(String name,
double min,
double max,
double value)
Ensures that the given floating point value is between the given bounds, inclusive. |
|
static void |
ensureBetween(String name,
float min,
float max,
float value)
Ensures that the given floating point value is between the given bounds, inclusive. |
|
static void |
ensureBetween(String name,
int min,
int max,
int value)
Ensures that the given integer value is between the given bounds, inclusive. |
|
static void |
ensureBetween(String name,
long min,
long max,
long value)
Ensures that the given long value is between the given bounds, inclusive. |
|
static
|
ensureCanCast(String name,
Class<? extends T> expectedType,
T value)
Ensures that the specified value is null or an instance assignable to the given type. |
|
static void |
ensureDimensionMatches(String name,
DirectPosition position,
int expected)
Ensures that the given direct position has the expected number of dimensions. |
|
static void |
ensureNonNull(String name,
int index,
Object[] array)
Makes sure that an array element is non-null. |
|
static void |
ensureNonNull(String name,
Object object)
Makes sure that an argument is non-null. |
|
static void |
ensurePositive(String name,
double value)
Ensures that the given floating point value is greater than or equals to zero. |
|
static void |
ensurePositive(String name,
float value)
Ensures that the given floating point value is greater than or equals to zero. |
|
static void |
ensurePositive(String name,
int value)
Ensures that the given integer value is greater than or equals to zero. |
|
static void |
ensurePositive(String name,
long value)
Ensures that the given long value is greater than or equals to zero. |
|
static void |
ensureStrictlyPositive(String name,
double value)
Ensures that the given floating point value is greater than zero. |
|
static void |
ensureStrictlyPositive(String name,
float value)
Ensures that the given floating point value is greater than zero. |
|
static void |
ensureStrictlyPositive(String name,
int value)
Ensures that the given integer value is greater than zero. |
|
static void |
ensureStrictlyPositive(String name,
long value)
Ensures that the given long value is greater than zero. |
|
static void |
ensureValidIndex(int upper,
int index)
Ensures that the given index is equals or greater than zero and lower than the given upper value. |
|
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static void ensureNonNull(String name,
Object object)
throws NullArgumentException
object is null, then a
NullArgumentException is thrown with a localized message containing the given name.
name - The name of the argument to be checked. Used only in case an exception is thrown.object - The user argument to check against null value.
NullArgumentException - if object is null.
public static void ensureNonNull(String name,
int index,
Object[] array)
throws NullArgumentException
array[index] is null, then a
NullArgumentException is thrown with a localized message containing the given name.
name - The name of the argument to be checked. Used only in case an exception is thrown.index - Index of the element to check.array - The user argument to check against null element.
NullArgumentException - if array or array[index] is null.
public static <T> void ensureCanCast(String name,
Class<? extends T> expectedType,
T value)
throws IllegalArgumentException
expectedType without throwing a ClassCastException.
T - The compile-time type of the value.name - The name of the argument to be checked, used only if an exception is thrown.
Can be null if the name is unknown.expectedType - the expected type (class or interface).value - The value to check, or null.
IllegalArgumentException - if value is non-null and is not assignable
to the given type.
public static void ensureValidIndex(int upper,
int index)
throws IndexOutOfBoundsException
upper - The maximal index value, exclusive.index - The index to check.
IndexOutOfBoundsException - If the given index is negative or not lower than the
given upper value.
public static void ensurePositive(String name,
int value)
throws IllegalArgumentException
name - The name of the argument to be checked, used only if an exception is thrown.value - The user argument to check.
IllegalArgumentException - if the given value is negative.
public static void ensurePositive(String name,
long value)
throws IllegalArgumentException
name - The name of the argument to be checked, used only if an exception is thrown.value - The user argument to check.
IllegalArgumentException - if the given value is negative.
public static void ensurePositive(String name,
float value)
throws IllegalArgumentException
name - The name of the argument to be checked, used only if an exception is thrown.value - The user argument to check.
IllegalArgumentException - if the given value is NaN or negative.
public static void ensurePositive(String name,
double value)
throws IllegalArgumentException
name - The name of the argument to be checked, used only if an exception is thrown.value - The user argument to check.
IllegalArgumentException - if the given value is NaN or negative.
public static void ensureStrictlyPositive(String name,
int value)
throws IllegalArgumentException
name - The name of the argument to be checked, used only if an exception is thrown.value - The user argument to check.
IllegalArgumentException - if the given value is negative or equals to zero.
public static void ensureStrictlyPositive(String name,
long value)
throws IllegalArgumentException
name - The name of the argument to be checked, used only if an exception is thrown.value - The user argument to check.
IllegalArgumentException - if the given value is negative or equals to zero.
public static void ensureStrictlyPositive(String name,
float value)
throws IllegalArgumentException
name - The name of the argument to be checked, used only if an exception is thrown.value - The user argument to check.
IllegalArgumentException - if the given value is NaN,
zero or negative.
public static void ensureStrictlyPositive(String name,
double value)
throws IllegalArgumentException
name - The name of the argument to be checked, used only if an exception is thrown.value - The user argument to check.
IllegalArgumentException - if the given value is NaN,
zero or negative.
public static void ensureBetween(String name,
int min,
int max,
int value)
throws IllegalArgumentException
name - The name of the argument to be checked. Used only in case an exception is thrown.min - The minimal value, inclusive.max - The maximal value, inclusive.value - The value to be tested.
IllegalArgumentException - if the given value is not in the given range.ensureValidIndex(int, int)
public static void ensureBetween(String name,
long min,
long max,
long value)
throws IllegalArgumentException
name - The name of the argument to be checked. Used only in case an exception is thrown.min - The minimal value, inclusive.max - The maximal value, inclusive.value - The value to be tested.
IllegalArgumentException - if the given value is not in the given range.
public static void ensureBetween(String name,
float min,
float max,
float value)
throws IllegalArgumentException
name - The name of the argument to be checked. Used only in case an exception is thrown.min - The minimal value, inclusive.max - The maximal value, inclusive.value - The value to be tested.
IllegalArgumentException - if the given value is NaN
or not in the given range.
public static void ensureBetween(String name,
double min,
double max,
double value)
throws IllegalArgumentException
name - The name of the argument to be checked. Used only in case an exception is thrown.min - The minimal value, inclusive.max - The maximal value, inclusive.value - The value to be tested.
IllegalArgumentException - if the given value is NaN
or not in the given range.
public static void ensureDimensionMatches(String name,
DirectPosition position,
int expected)
throws MismatchedDimensionException
name - The name of the argument to be checked. Used only in case an exception is thrown.position - The direct position to check for its dimension.expected - The expected number of dimensions.
MismatchedDimensionException - If the given direct position is non-null and does
not have the expected number of dimensions.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||