Package org.apache.sis.parameter
Class Verifier
java.lang.Object
org.apache.sis.parameter.Verifier
Verifies the validity of a given value.
An instance of
Verifier
is created only if an error is detected.
In such case, the error message is given by message(Map, String, Object)
.- Since:
- 0.4
- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Object[]
The arguments to be used with the error message to format.private final short
TheErrors.Keys
orResources.Keys
value that describe the invalid value.private final boolean
private final boolean
true
if the last element inarguments
shall be set to the erroneous value. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
convertRange
(javax.measure.UnitConverter converter) Converts the information about an "value out of range" error.private static <T> Verifier
ensureValidValue
(Class<T> valueClass, Set<T> validValues, Comparable<T> minimum, Comparable<T> maximum, Object convertedValue) Same asensureValidValue(Class, Set, Range, Object)
, used as a fallback when the descriptor is not an instance ofDefaultParameterDescriptor
.(package private) static <T> Verifier
ensureValidValue
(Class<T> valueClass, Set<T> validValues, Range<?> valueDomain, Object convertedValue) Compares the given value against the given descriptor properties.(package private) static <T> T
ensureValidValue
(org.opengis.parameter.ParameterDescriptor<T> descriptor, Object value, javax.measure.Unit<?> unit) Ensures that the given value is valid according the specified parameter descriptor.private static javax.measure.Unit
<?> getCompatibleUnit
(Range<?> valueDomain, javax.measure.Unit<?> unit) If the given domain of values accepts units of incompatible dimensions, return the unit which is compatible with the given units.(package private) static String
getDisplayName
(org.opengis.parameter.GeneralParameterDescriptor descriptor) Convenience method returning the name of the specified descriptor.(package private) static short
getUnitMessageID
(javax.measure.Unit<?> unit) Returns the unit type as one of error message code.(package private) String
Returns an error message for the error detected byensureValidValue(Class, Set, Range, Object)
.
-
Field Details
-
errorKey
private final short errorKeyTheErrors.Keys
orResources.Keys
value that describe the invalid value. -
internal
private final boolean internal -
needsValue
private final boolean needsValuetrue
if the last element inarguments
shall be set to the erroneous value. -
arguments
The arguments to be used with the error message to format. The current implementation relies on the following invariants:- The first element in this array will be the parameter name. Before the name is known,
this element is either
null
or the index to append to the name. - The last element shall be set to the erroneous value if
needsValue
istrue
.
- The first element in this array will be the parameter name. Before the name is known,
this element is either
-
-
Constructor Details
-
Verifier
Stores information about an error.
-
-
Method Details
-
ensureValidValue
static <T> T ensureValidValue(org.opengis.parameter.ParameterDescriptor<T> descriptor, Object value, javax.measure.Unit<?> unit) throws org.opengis.parameter.InvalidParameterValueException Ensures that the given value is valid according the specified parameter descriptor. This method ensures thatvalue
is assignable to the expected class, is between the minimum and maximum values and is one of the set of valid values. If the value fails any of those tests, then an exception is thrown.This method does not attempt to convert the given value (for example from
Float
toDouble
) because such conversions should be done by the caller if desired. SeeDefaultParameterValue.setValue(Object, Unit)
.- Type Parameters:
T
- the type of parameter value. The givenvalue
should typically be an instance of this class. This is not required by this method signature but is checked by this method implementation.- Parameters:
descriptor
- the parameter descriptor to check against.value
- the value to check, ornull
.unit
- the unit of the value to check, ornull
.- Returns:
- the given value converted to the descriptor unit if any, then casted to the descriptor parameterized type.
- Throws:
org.opengis.parameter.InvalidParameterValueException
- if the parameter value is invalid.
-
ensureValidValue
static <T> Verifier ensureValidValue(Class<T> valueClass, Set<T> validValues, Range<?> valueDomain, Object convertedValue) Compares the given value against the given descriptor properties. If the value is valid, returnsnull
. Otherwise returns an object that can be used for formatting the error message.- Parameters:
convertedValue
- the value converted to the units specified by the descriptor. This is not necessarily the user-provided value.
-
ensureValidValue
private static <T> Verifier ensureValidValue(Class<T> valueClass, Set<T> validValues, Comparable<T> minimum, Comparable<T> maximum, Object convertedValue) Same asensureValidValue(Class, Set, Range, Object)
, used as a fallback when the descriptor is not an instance ofDefaultParameterDescriptor
.Implementation note: At the difference ofensureValidValue(…, Range, …)
, this method does not need to verify array elements because the type returned byParameterDescriptor.getMinimumValue()
andgetMaximumValue()
methods (namelyComparable<T>
) does not allow usage with arrays.- Parameters:
convertedValue
- the value converted to the units specified by the descriptor. This is not necessarily the user-provided value.
-
convertRange
private void convertRange(javax.measure.UnitConverter converter) Converts the information about an "value out of range" error. The range in the error message will be formatted in the unit given by the user, which is not necessarily the same than the unit of the parameter descriptor.- Parameters:
converter
- the conversion from user unit to descriptor unit, ornull
if none. This method uses the inverse of that conversion for converting the given minimum and maximum values.
-
getCompatibleUnit
private static javax.measure.Unit<?> getCompatibleUnit(Range<?> valueDomain, javax.measure.Unit<?> unit) If the given domain of values accepts units of incompatible dimensions, return the unit which is compatible with the given units. This is a non-public mechanism handling a few parameters in the EPSG database, like Coordinate 1 of evaluation point (EPSG:8617). -
message
Returns an error message for the error detected byensureValidValue(Class, Set, Range, Object)
.- Parameters:
name
- the parameter name.value
- the user supplied value (not necessarily equals to the converted value).
-
getDisplayName
Convenience method returning the name of the specified descriptor. This method is used mostly for output to be read by human, not for processing. Consequently, we may consider to returns a localized name in a future version.This method is null-safe even if none of the references checked here should be null. We make this method safe because it is indirectly invoked by methods like
toString()
which are not expected to fail even if the object is invalid.This method should NOT be invoked for programmatic usage (e.g. setting a parameter value) because the string returned in case of invalid descriptor is arbitrary.
-
getUnitMessageID
static short getUnitMessageID(javax.measure.Unit<?> unit) Returns the unit type as one of error message code. Used for checking unit with a better error message formatting if needed.
-