Class Verifier

java.lang.Object
org.apache.sis.parameter.Verifier

final class Verifier extends Object
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 Details

    • errorKey

      private final short errorKey
      The Errors.Keys or Resources.Keys value that describe the invalid value.
    • internal

      private final boolean internal
      false if errorKey is a Errors.Keys constants, or true if it is a Resources.Keys constant.
    • needsValue

      private final boolean needsValue
      true if the last element in arguments shall be set to the erroneous value.
    • arguments

      private final Object[] 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 is true.
  • Constructor Details

    • Verifier

      private Verifier(boolean internal, short errorKey, boolean needsValue, Object... arguments)
      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 that value 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 to Double) because such conversions should be done by the caller if desired. See DefaultParameterValue.setValue(Object, Unit).

      Type Parameters:
      T - the type of parameter value. The given value 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, or null.
      unit - the unit of the value to check, or null.
      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, returns null. 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 as ensureValidValue(Class, Set, Range, Object), used as a fallback when the descriptor is not an instance of DefaultParameterDescriptor.
      Implementation note: At the difference of ensureValidValue(…, Range, …), this method does not need to verify array elements because the type returned by ParameterDescriptor.getMinimumValue() and getMaximumValue() methods (namely Comparable<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, or null 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

      String message(Map<?,?> properties, String name, Object value)
      Returns an error message for the error detected by ensureValidValue(Class, Set, Range, Object).
      Parameters:
      name - the parameter name.
      value - the user supplied value (not necessarily equals to the converted value).
    • getDisplayName

      static String getDisplayName(org.opengis.parameter.GeneralParameterDescriptor descriptor)
      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.