public final class ArgumentChecks extends Static
ensureXXX(…)
methods are provided in the following classes:
Defined in the sis-utility module
Modifier and Type | Method and Description |
---|---|
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 void |
ensureCanCast(String name,
Class<?> expectedType,
Object value)
Ensures that the specified value is null or an instance assignable to the given type.
|
static void |
ensureDimensionMatches(String name,
int expected,
CoordinateReferenceSystem crs)
Ensures that the given CRS, if non-null, has the expected number of dimensions.
|
static void |
ensureDimensionMatches(String name,
int expected,
DirectPosition position)
Ensures that the given direct position, if non-null, has the expected number of dimensions.
|
static void |
ensureDimensionMatches(String name,
int expected,
double[] vector)
Ensures that the given vector, if non-null, has the expected number of dimensions
(taken as its length).
|
static void |
ensureDimensionMatches(String name,
int expected,
Envelope envelope)
Ensures that the given envelope, if non-null, has the expected number of dimensions.
|
static void |
ensureFinite(String name,
double value)
Ensures that the given floating point value is not
NaN neither Double.isInfinite(double).
|
static void |
ensureFinite(String name,
float value)
Ensures that the given floating point value is not
NaN neither Float.isInfinite(float).
|
static void |
ensureNonEmpty(String name,
CharSequence text)
Makes sure that a character sequence is non-null and non-empty.
|
static void |
ensureNonNull(String name,
Object object)
Makes sure that an argument is non-null.
|
static void |
ensureNonNullElement(String name,
int index,
Object element)
Makes sure that an array element is non-null.
|
static void |
ensurePositive(String name,
double value)
Ensures that the given floating point value is not
NaN and is greater than or equals to zero.
|
static void |
ensurePositive(String name,
float value)
Ensures that the given floating point value is not
NaN and 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 |
ensureSizeBetween(String name,
int min,
int max,
int size)
Ensures that the given collection size of array length is between the given bounds, inclusive.
|
static void |
ensureStrictlyPositive(String name,
double value)
Ensures that the given floating point value is not
NaN and is greater than zero.
|
static void |
ensureStrictlyPositive(String name,
float value)
Ensures that the given floating point value is not
NaN and 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.
|
static void |
ensureValidIndexRange(int length,
int lower,
int upper)
Ensures that the given index range is valid for a sequence of the given length.
|
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 if an exception is thrown.object
- The user argument to check against null value.NullArgumentException
- if object
is null.public static void ensureNonNullElement(String name, int index, Object element) throws NullArgumentException
element
is null, then a
NullArgumentException
is thrown with a localized message containing the
given name and index.name
- The name of the argument to be checked. Used only if an exception is thrown.index
- The Index of the element to check in an array or a list. Used only if an exception is thrown.element
- The array or list element to check against null null.NullArgumentException
- if element
is null.public static void ensureNonEmpty(String name, CharSequence text) throws NullArgumentException, IllegalArgumentException
text
is
null, then a NullArgumentException
is thrown. Otherwise if the given text
has
a length equals to 0, then an IllegalArgumentException
is thrown.name
- The name of the argument to be checked. Used only if an exception is thrown.text
- The user argument to check against null value and empty sequences.NullArgumentException
- if text
is null.IllegalArgumentException
- if text
is empty.public static void ensureCanCast(String name, Class<?> expectedType, Object value) throws IllegalArgumentException
expectedType
without throwing a ClassCastException
.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.ensurePositive(String, int)
public static void ensureValidIndexRange(int length, int lower, int upper) throws IndexOutOfBoundsException
This method verifies only the lower
and upper
argument values.
It does not not verify the validity of the length
argument,
because this information is assumed to be provided by the implementation rather than
the user.
length
- The length of the sequence (array, CharSequence
, etc.).lower
- The user-specified lower index, inclusive.upper
- The user-specified upper index, exclusive.IndexOutOfBoundsException
- If the given [lower
… upper
]
range is out of the sequence index range.ensureSizeBetween(String, int, int, int)
public static void ensurePositive(String name, int value) throws IllegalArgumentException
ensureValidIndex(int, int)
instead.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.ensureValidIndex(int, int)
,
ensureStrictlyPositive(String, int)
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.ensureStrictlyPositive(String, long)
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.ensureStrictlyPositive(String, float)
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.ensureStrictlyPositive(String, double)
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.ensurePositive(String, int)
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.ensurePositive(String, long)
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.ensurePositive(String, float)
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.ensurePositive(String, double)
public static void ensureFinite(String name, float value)
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 infinite.public static void ensureFinite(String name, double value)
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 infinite.public static void ensureBetween(String name, int min, int max, int value) throws IllegalArgumentException
ensureSizeBetween(…)
if the value
argument is a collection size or an array length.ensureValidIndex(…)
if the value
argument is an index in a list or an array.name
- The name of the argument to be checked. Used only if an exception is thrown.min
- The minimal value, inclusive.max
- The maximal value, inclusive.value
- The user argument to check.IllegalArgumentException
- if the given value is not in the given range.ensureSizeBetween(String, int, int, int)
,
ensureValidIndex(int, int)
,
ensureValidIndexRange(int, 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 if an exception is thrown.min
- The minimal value, inclusive.max
- The maximal value, inclusive.value
- The user argument to check.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 if an exception is thrown.min
- The minimal value, inclusive.max
- The maximal value, inclusive.value
- The user argument to check.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 if an exception is thrown.min
- The minimal value, inclusive.max
- The maximal value, inclusive.value
- The user argument to check.IllegalArgumentException
- if the given value is NaN or not in the given range.public static void ensureSizeBetween(String name, int min, int max, int size) throws IllegalArgumentException
ensureBetween(…)
, but the error message is different in case of failure.name
- The name of the argument to be checked. Used only if an exception is thrown.min
- The minimal size (inclusive), or 0 if none.max
- The maximal size (inclusive), or Integer.MAX_VALUE
if none.size
- The user collection size or array length to be checked.IllegalArgumentException
- if the given value is not in the given range.ensureBetween(String, int, int, int)
,
ensureValidIndexRange(int, int, int)
public static void ensureDimensionMatches(String name, int expected, CoordinateReferenceSystem crs) throws MismatchedDimensionException
name
- The name of the argument to be checked. Used only if an exception is thrown.expected
- The expected number of dimensions.crs
- The coordinate reference system to check for its dimension, or null
.MismatchedDimensionException
- If the given coordinate reference system is non-null
and does not have the expected number of dimensions.public static void ensureDimensionMatches(String name, int expected, double[] vector) throws MismatchedDimensionException
name
- The name of the argument to be checked. Used only if an exception is thrown.expected
- The expected number of dimensions.vector
- The vector to check for its number of dimensions, or null
.MismatchedDimensionException
- If the given vector is non-null and does not have the
expected number of dimensions (taken as its length).public static void ensureDimensionMatches(String name, int expected, DirectPosition position) throws MismatchedDimensionException
name
- The name of the argument to be checked. Used only if an exception is thrown.expected
- The expected number of dimensions.position
- The direct position to check for its dimension, or null
.MismatchedDimensionException
- If the given direct position is non-null and does
not have the expected number of dimensions.public static void ensureDimensionMatches(String name, int expected, Envelope envelope) throws MismatchedDimensionException
name
- The name of the argument to be checked. Used only if an exception is thrown.expected
- The expected number of dimensions.envelope
- The envelope to check for its dimension, or null
.MismatchedDimensionException
- If the given envelope is non-null and does
not have the expected number of dimensions.Copyright © 2010–2013 The Apache Software Foundation. All rights reserved.