/** * 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)); }
/** 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; }
fail("doubleValue shall not be allowed on AxisDirection"); } catch (InvalidParameterTypeException exception) { final String message = exception.getMessage(); assertTrue(message, message.contains("AxisDirection")); assertEquals("Direction", exception.getParameterName());
/** * Returns the {@linkplain Parameter#getStringValue() parameter string value} as a URI. * This method invokes {@link #stringValue()}, then parse the string as a URI. * * @return the parameter URI value. * @throws InvalidParameterTypeException if the parameter value is not convertible * to the {@link URI} type. * * @see Parameter#getStringValue() */ @Override public URI valueFile() throws InvalidParameterTypeException { try { return new URI(stringValue()); } catch (URISyntaxException cause) { final InvalidParameterTypeException e = invalidType(parameter, URI.class); e.initCause(cause); throw e; } }
} catch (InvalidParameterTypeException exception) { assertEquals("Test", exception.getParameterName()); } catch (InvalidParameterTypeException exception) { assertEquals("Test", exception.getParameterName()); } catch (InvalidParameterTypeException exception) { assertEquals("Test", exception.getParameterName());
fail("stringValue()"); } catch (InvalidParameterTypeException exception) { final String message = exception.getMessage(); assertTrue(message, message.contains("Integer")); assertEquals("Integer param", exception.getParameterName());
/** 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)); }
new InvalidParameterTypeException(getClassTypeError(), name); if (cause != null) { exception.initCause(cause);
fail("stringValue()"); } catch (InvalidParameterTypeException exception) { final String message = exception.getMessage(); assertTrue(message, message.contains("Double")); assertEquals("Numerical param", exception.getParameterName());
/** * 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); }
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); }
/** * Returns the integer value of an operation parameter, usually used for a count. * If {@linkplain #LENIENT lenient}, this method returns the {@linkplain #value} * casted to the {@code int} type only if this cast can be done without lost of * information. In all other cases an exception is thrown. * * @return the numeric value represented by this parameter after conversion to type {@code int}. * @throws InvalidParameterTypeException if the value can not be casted to an integer type. */ @Override public int intValue() throws InvalidParameterTypeException { if (LENIENT) { final int candidate = (int) value; if (candidate == value) { return candidate; } } throw new InvalidParameterTypeException("Value " + value + " is not an integer.", code); }
/** * Returns the boolean value of an operation parameter. * If {@linkplain #LENIENT lenient}, this method makes the following choice: * * <ul> * <li>Returns {@code false} if the {@linkplain #value} is 0</li> * <li>Returns {@code true} if the {@linkplain #value} is 1</li> * <li>Throws an exception in all other cases</li> * </ul> * * @return the boolean value represented by this parameter. * @throws InvalidParameterTypeException if the value can not be converted to a boolean. */ @Override public boolean booleanValue() throws InvalidParameterTypeException { if (LENIENT) { if (value == 0) return false; if (value == 1) return true; } throw new InvalidParameterTypeException("Value " + value + " is not a boolean.", code); }
/** * Invoked when any getter method other than {@link #getValue()} has been invoked. */ private IllegalStateException invalidType() { return new InvalidParameterTypeException(null, getParameterName()); }