final Class<? extends Object> target = param.getDescriptor().getValueClass(); if (key.equalsIgnoreCase("InputTransparentColor") || key.equalsIgnoreCase("OutputTransparentColor")) {
new DefaultParameterDescriptor(_key, descr.getValueClass(), null, value) .createValue());
private GeneralParameterValue[] buildFootprintBandParams( FootprintBehavior footprintBehavior, int[] bands) { final List<ParameterValue<?>> parameters = new ArrayList<ParameterValue<?>>(); parameters.add( new DefaultParameterDescriptor<>( AbstractGridFormat.FOOTPRINT_BEHAVIOR.getName().toString(), AbstractGridFormat.FOOTPRINT_BEHAVIOR.getValueClass(), null, footprintBehavior.name()) .createValue()); parameters.add( new DefaultParameterDescriptor<>( AbstractGridFormat.BANDS.getName().toString(), AbstractGridFormat.BANDS.getValueClass(), null, bands) .createValue()); return (GeneralParameterValue[]) parameters.toArray(new GeneralParameterValue[parameters.size()]); }
/** Format an error message for illegal method call for the current value type. */ private String getClassTypeError() { return Errors.format( ErrorKeys.ILLEGAL_OPERATION_FOR_VALUE_CLASS_$1, ((ParameterDescriptor) descriptor).getValueClass()); }
/** Returns the parameter type. */ private Class<T> getType() { return getDescriptor().getValueClass(); }
/** Returns the number of source coverages in the specified parameter group. */ private static int getNumSources(final ParameterDescriptorGroup descriptor) { int count = 0; for (final Iterator it = descriptor.descriptors().iterator(); it.hasNext(); ) { final GeneralParameterDescriptor candidate = (GeneralParameterDescriptor) it.next(); if (candidate instanceof ParameterDescriptorGroup) { count += getNumSources((ParameterDescriptorGroup) candidate); continue; } if (candidate instanceof ParameterDescriptor) { final Class type = ((ParameterDescriptor) candidate).getValueClass(); if (Coverage.class.isAssignableFrom(type)) { count++; } } } return count; }
/** * Constructs a parameter from the specified descriptor. The descriptor {@linkplain * ParameterDescriptor#getValueClass() value class} must be <code>{@linkplain Double}.class * </code>. * * @param descriptor The abstract definition of this parameter. * @throws IllegalArgumentException if the value class is not {@code Double.class}. */ public FloatParameter(final ParameterDescriptor<Double> descriptor) { super(descriptor); final Class type = descriptor.getValueClass(); final Class expected = Double.class; if (!expected.equals(type) && !Double.TYPE.equals(type)) { throw new IllegalArgumentException( Errors.format(ErrorKeys.ILLEGAL_CLASS_$2, type, expected)); } final Number value = (Number) descriptor.getDefaultValue(); this.value = (value != null) ? value.doubleValue() : Double.NaN; }
/** * Sets the parameter value as an integer. * * @param value The parameter value. * @throws InvalidParameterValueException if the integer type is inappropriate for this * parameter, or if the value is illegal for some other reason (for example a value out of * range). * @see #intValue */ public void setValue(final int value) throws InvalidParameterValueException { @SuppressWarnings("unchecked") // Checked by constructor. final ParameterDescriptor<T> descriptor = (ParameterDescriptor) this.descriptor; final Class<T> type = descriptor.getValueClass(); if (Double.class.equals(type) || Double.TYPE.equals(type)) { setValue((double) value); return; } final Integer check = value; this.value = ensureValidValue(descriptor, check); }
/** * Casts the given parameter descriptor to the given type. An exception is thrown immediately if * the parameter does not have the expected value class. This is a helper method for type safety * when using Java 5 parameterized types. * * @param <T> The expected value class. * @param descriptor The descriptor to cast. * @param type The expected value class. * @return The descriptor casted to the given type. * @throws ClassCastException if the given descriptor doesn't have the expected value class. * @since 2.5 */ @SuppressWarnings("unchecked") public static <T> ParameterDescriptor<T> cast(ParameterDescriptor<?> descriptor, Class<T> type) throws ClassCastException { if (descriptor != null) { final Class<?> actual = descriptor.getValueClass(); // We require a strict equality - not type.isAssignableFrom(actual) - because in // the later case we could have (to be strict) to return a <? extends T> type. if (!type.equals(actual)) { throw new ClassCastException( Errors.format( ErrorKeys.BAD_PARAMETER_TYPE_$2, descriptor.getName().getCode(), actual)); } } return (ParameterDescriptor) descriptor; }
/** * Casts the given parameter value to the given type. An exception is thrown immediately if the * parameter does not have the expected value class. This is a helper method for type safety * when using Java 5 parameterized types. * * @param <T> The expected value class. * @param value The value to cast. * @param type The expected value class. * @return The value casted to the given type. * @throws ClassCastException if the given value doesn't have the expected value class. * @since 2.5 */ @SuppressWarnings("unchecked") public static <T> ParameterValue<T> cast(final ParameterValue<?> value, final Class<T> type) throws ClassCastException { if (value != null) { final ParameterDescriptor descriptor = value.getDescriptor(); final Class<?> actual = descriptor.getValueClass(); if (!type.equals(actual)) { // Same comment than cast(ParameterDescriptor)... throw new ClassCastException( Errors.format( ErrorKeys.BAD_PARAMETER_TYPE_$2, descriptor.getName().getCode(), actual)); } } return (ParameterValue) value; }
final Class<?> expected = Classes.primitiveToWrapper(descriptor.getValueClass()); if (expected.isAssignableFrom(type)) { return false; // value not of the correct type
final ParameterValue<?> targetValue = (ParameterValue) targetPrm; if (Number.class.isAssignableFrom( targetValue.getDescriptor().getValueClass())) { final double sourceNum, targetNum; final Unit<?> unit = targetValue.getUnit();
/** * Constructs a descriptor with the same values than the specified one. This copy constructor * may be used in order to wraps an arbitrary implementation into a Geotools one. * * @param descriptor The descriptor to copy. * @since 2.2 */ public DefaultParameterDescriptor(final ParameterDescriptor<T> descriptor) { super(descriptor); valueClass = descriptor.getValueClass(); validValues = descriptor.getValidValues(); defaultValue = descriptor.getDefaultValue(); minimum = descriptor.getMinimumValue(); maximum = descriptor.getMaximumValue(); unit = descriptor.getUnit(); }
if (type == null || !type.isAssignableFrom(descriptor.getValueClass())) { return false;
final Class<T> type = descriptor.getValueClass(); if (!type.isInstance(value)) { error =
return Parameters.cast(group.parameter(name), param.getValueClass()); for (final GeneralParameterValue candidate : group.values()) { if (search.equals(candidate.getDescriptor())) { return Parameters.cast((ParameterValue) candidate, param.getValueClass());
this.value = descriptor.getValueClass().cast(value); this.unit = unit;
final String name = param.pullString("name"); final ParameterValue parameter = parameters.parameter(name); final Class type = parameter.getDescriptor().getValueClass(); if (Integer.class.equals(type)) { parameter.setValue(param.pullInteger("value"));
assertEquals("Type", double[].class, param.getValueClass()); assertEquals("Default", 1, ((double[]) param.getDefaultValue()).length); assertNull("Minimum", param.getMinimumValue());
assertEquals("name", "Test", dDescriptor.getName().getCode()); assertEquals("unit", SI.METRE, dDescriptor.getUnit()); assertEquals("class", Double.class, dDescriptor.getValueClass()); assertEquals("defaultValue", 12.0, dDescriptor.getDefaultValue().doubleValue(), 0.0); assertEquals("minimum", 4.0, dDescriptor.getMinimumValue());