/** * Always throws an exception, since this parameter is not an URI. * * @return Never return. * @throws InvalidParameterTypeException The value is not a reference to a file or an URI. */ public URI valueFile() throws InvalidParameterTypeException { throw new InvalidParameterTypeException(getClassTypeError(), Parameter.getName(descriptor)); }
/** Always throws an exception, since this parameter is not an array. */ public void setValue(double[] values, final Unit<?> unit) throws InvalidParameterValueException { throw new InvalidParameterTypeException(getClassTypeError(), Parameter.getName(descriptor)); }
/** * Returns the string value of an operation parameter. A string value does not have an * associated unit of measure. * * @return The string value represented by this parameter. * @throws InvalidParameterTypeException if the value is not a string. * @see #getValue * @see #setValue(Object) */ public String stringValue() throws InvalidParameterTypeException { if (value instanceof CharSequence) { return value.toString(); } final String name = getName(descriptor); if (value == null) { throw new IllegalStateException(Errors.format(ErrorKeys.MISSING_PARAMETER_$1, name)); } throw new InvalidParameterTypeException(getClassTypeError(), name); }
/** * Returns the boolean value of an operation parameter. A boolean value does not have an * associated unit of measure. * * @return The boolean value represented by this parameter. * @throws InvalidParameterTypeException if the value is not a boolean type. * @see #setValue(boolean) */ public boolean booleanValue() throws InvalidParameterTypeException { if (value instanceof Boolean) { return ((Boolean) value).booleanValue(); } final String name = getName(descriptor); if (value == null) { throw new IllegalStateException(Errors.format(ErrorKeys.MISSING_PARAMETER_$1, name)); } throw new InvalidParameterTypeException(getClassTypeError(), name); }
/** * Returns the positive integer value of an operation parameter, usually used for a count. An * integer value does not have an associated unit of measure. * * @return The numeric value represented by this parameter after conversion to type {@code int}. * @throws InvalidParameterTypeException if the value is not an integer type. * @see #setValue(int) * @see #intValueList */ public int intValue() throws InvalidParameterTypeException { if (value instanceof Number) { return ((Number) value).intValue(); } final String name = getName(descriptor); if (value == null) { throw new IllegalStateException(Errors.format(ErrorKeys.MISSING_PARAMETER_$1, name)); } throw new InvalidParameterTypeException(getClassTypeError(), name); }
/** * Returns the numeric value of the coordinate operation parameter with its associated * {@linkplain #getUnit unit of measure}. * * @return The numeric value represented by this parameter after conversion to type {@code * double}. * @throws InvalidParameterTypeException if the value is not a numeric type. * @see #getUnit * @see #setValue(double) * @see #doubleValueList() */ public double doubleValue() throws InvalidParameterTypeException { if (value instanceof Number) { return ((Number) value).doubleValue(); } final String name = getName(descriptor); if (value == null) { // This is the kind of exception expected by org.geotools.referencing.wkt.Formatter. throw new IllegalStateException(Errors.format(ErrorKeys.MISSING_PARAMETER_$1, name)); } // Reminder: the following is a specialization of IllegalStateException. throw new InvalidParameterTypeException(getClassTypeError(), name); }
/** * Returns an ordered sequence of two or more numeric values of an operation parameter list, * where each value has the same associated {@linkplain Unit unit of measure}. * * @return The sequence of values represented by this parameter. * @throws InvalidParameterTypeException if the value is not an array of {@code double}s. * @see #getUnit * @see #setValue(Object) * @see #doubleValue() */ public double[] doubleValueList() throws InvalidParameterTypeException { if (value instanceof double[]) { return (double[]) value; } final String name = getName(descriptor); if (value == null) { throw new IllegalStateException(Errors.format(ErrorKeys.MISSING_PARAMETER_$1, name)); } throw new InvalidParameterTypeException(getClassTypeError(), name); }
/** * Returns an ordered sequence of two or more integer values of an operation parameter list, * usually used for counts. These integer values do not have an associated unit of measure. * * @return The sequence of values represented by this parameter. * @throws InvalidParameterTypeException if the value is not an array of {@code int}s. * @see #setValue(Object) * @see #intValue */ public int[] intValueList() throws InvalidParameterTypeException { if (value instanceof int[]) { return (int[]) value; } final String name = getName(descriptor); if (value == null) { throw new IllegalStateException(Errors.format(ErrorKeys.MISSING_PARAMETER_$1, name)); } throw new InvalidParameterTypeException(getClassTypeError(), name); }
/** Returns the exception to be throws for an operation on a wrong parameter type. */ private InvalidParameterTypeException invalidType(final ClassCastException cause) { final InvalidParameterTypeException exception = new InvalidParameterTypeException( Errors.format(ErrorKeys.ILLEGAL_OPERATION_FOR_VALUE_CLASS_$1, getType()), getName(descriptor)); exception.initCause(cause); return exception; }
new InvalidParameterTypeException(getClassTypeError(), name); if (cause != null) { exception.initCause(cause);
if (count == null) { final String name = getName(descriptor); throw new InvalidParameterTypeException( Errors.format(ErrorKeys.ILLEGAL_DESCRIPTOR_FOR_PARAMETER_$1, name), name);
/** * Thrown unconditionally the exception, since this parameter implementation can not * represent URI. * * @return never returned. * @throws InvalidParameterTypeException Always thrown. */ @Override public URI valueFile() throws InvalidParameterTypeException { throw new InvalidParameterTypeException("This parameter is not for files.", code); }
/** * Invoked when any getter method other than {@link #getValue()} has been invoked. */ private IllegalStateException invalidType() { return new InvalidParameterTypeException(null, getParameterName()); }
/** * Creates an exception for an invalid type. */ private InvalidParameterTypeException invalidType(final String type) { return new InvalidParameterTypeException("Value " + value + " is not " + type + '.', name.getCode()); }
/** * Returns the exception to throw for a getter method invoked with a parameter of the wrong type. * * @param parameter the netCDF parameter. * @param requested the requested type. * @return the exception to throw. */ private static InvalidParameterTypeException invalidType( final Parameter parameter, final Class<?> requested) { final String name = parameter.getName(); return new InvalidParameterTypeException("Can not convert '" + name + "' from type " + getValueClass(parameter).getSimpleName() + " to type " + requested.getSimpleName() + '.', name); }
/** * Always throws an exception, since this parameter is not an URI. * * @return Never return. * @throws InvalidParameterTypeException The value is not a reference to a file or an URI. */ @Override public URI valueFile() throws InvalidParameterTypeException { throw new InvalidParameterTypeException(getClassTypeError(), getName(descriptor)); }
/** * Unconditionally throw an exception. */ @Override public double[] doubleValueList() throws InvalidParameterTypeException { throw new InvalidParameterTypeException("This parameter is not an array.", delegate().getName()); }
/** * Returns the exception to throw when an incompatible method is invoked for the value type. */ private IllegalStateException missingOrIncompatibleValue(final Object newValue) { final String name = Verifier.getDisplayName(descriptor); if (newValue != null) { return new InvalidParameterTypeException(getClassTypeError(), name); } return new IllegalStateException(Resources.format(Resources.Keys.MissingValueForParameter_1, name)); }
/** * Returns the exception to throw when an incompatible method is invoked for the value type. */ private IllegalStateException missingOrIncompatibleValue(final Object newValue) { final String name = Verifier.getDisplayName(descriptor); if (newValue != null) { return new InvalidParameterTypeException(getClassTypeError(), name); } return new IllegalStateException(Resources.format(Resources.Keys.MissingValueForParameter_1, name)); }
/** * Sets this parameter to the given {@link String}, {@code double[]} or {@link Number}. * If the given value is a number, then this method delegates to {@link #setValue(double)}. * * @throws InvalidParameterValueException if this parameter can not accept the given value. * * @see Parameter#Parameter(String, String) */ @Override public void setValue(final Object value) throws InvalidParameterValueException { if (value instanceof Number) { setValue(((Number) value).doubleValue()); } else { throw new InvalidParameterTypeException("The value must be a number.", delegate().getName()); } }