/** * Returns the unit of measure of the {@linkplain #doubleValue() parameter value}. The default * implementation always delegates to {@link ParameterDescriptor#getUnit}. * * @return The unit of measure, or {@code null} if none. */ public Unit<?> getUnit() { return ((ParameterDescriptor) descriptor).getUnit(); }
/** * Constructs a parameter value from the specified descriptor. The value will be initialized to * the default value, if any. * * @param descriptor The abstract definition of this parameter. */ public Parameter(final ParameterDescriptor<T> descriptor) { super(descriptor); value = descriptor.getDefaultValue(); unit = descriptor.getUnit(); }
/** * Constructs a parameter value from the specified descriptor and value. * * @param descriptor The abstract definition of this parameter. * @param value The parameter value. * @throws InvalidParameterValueException if the type of {@code value} is inappropriate for this * parameter, or if the value is illegal for some other reason (for example the value is * numeric and out of range). */ public Parameter(final ParameterDescriptor<T> descriptor, final T value) throws InvalidParameterValueException { super(descriptor); unit = descriptor.getUnit(); setValue(value); }
/** * Returns the parameter value for the specified operation parameter in standard units. * Values are automatically converted into the standard units specified by the supplied * {@code param} argument, except {@link NonSI#DEGREE_ANGLE degrees} which are converted to * {@link SI#RADIAN radians}. This conversion is performed because the radians units are * standard for all internal computations in the map projection package. For example they * are the standard units for {@link MapProjection#latitudeOfOrigin latitudeOfOrigin} and * {@link MapProjection#centralMeridian centralMeridian} fields in the {@link MapProjection} * class. * * @param param The parameter to look for. * @param group The parameter value group to search into. * @return The requested parameter value. * @throws ParameterNotFoundException if the parameter is not found. */ protected static double doubleValue( final ParameterDescriptor param, final ParameterValueGroup group) throws ParameterNotFoundException { double v = MathTransformProvider.doubleValue(param, group); if (NonSI.DEGREE_ANGLE.equals(param.getUnit())) { v = toRadians(v); } return v; } }
if (value instanceof Number) { v = ((Number) value).doubleValue(); if (NonSI.DEGREE_ANGLE.equals(param.getUnit())) { v = toRadians(v);
/** * Returns the parameter value for the specified operation parameter. Values are automatically * converted into the standard units specified by the supplied {@code param} argument. This * convenience method is used by subclasses for initializing {@linkplain MathTransform math * transform} from a set of parameters. * * @param param The parameter to look for. * @param group The parameter value group to search into. * @return The requested parameter value, or {@code NaN} if {@code param} is {@linkplain * #createOptionalDescriptor optional} and the user didn't provided any value. * @throws ParameterNotFoundException if the parameter is not found. * @todo Move to the {@link org.geotools.parameter.Parameters} class. */ protected static double doubleValue( final ParameterDescriptor<?> param, final ParameterValueGroup group) throws ParameterNotFoundException { final Unit<?> unit = param.getUnit(); final ParameterValue<?> value = getParameter(param, group); return (value == null) ? Double.NaN : (unit != null) ? value.doubleValue(unit) : value.doubleValue(); }
final ParameterValue<?> param = (ParameterValue) parameter; final ParameterDescriptor<?> descriptor = param.getDescriptor(); final Unit<?> valueUnit = descriptor.getUnit(); Unit<?> unit = valueUnit;
/** * 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(); }
/** * Set the parameter value as a floating point and its associated unit. * * @param value The parameter value. * @param unit The unit for the specified value. * @throws InvalidParameterValueException if the value is illegal for some reason (for example a * value out of range). */ public void setValue(double value, final Unit<?> unit) throws InvalidParameterValueException { ensureNonNull("unit", unit); @SuppressWarnings("unchecked") // Checked by constructor. final ParameterDescriptor<Double> descriptor = (ParameterDescriptor) this.descriptor; final Unit<?> thisUnit = descriptor.getUnit(); if (thisUnit == null) { throw unitlessParameter(descriptor); } final int expectedID = Parameter.getUnitMessageID(thisUnit); if (Parameter.getUnitMessageID(unit) != expectedID) { throw new IllegalArgumentException(Errors.format(expectedID, unit)); } value = Units.getConverterToAny(unit, thisUnit).convert(value); this.value = Parameter.ensureValidValue(descriptor, Double.valueOf(value)); }
double value) { if (isExpectedParameter(expected, param)) { if (NonSI.DEGREE_ANGLE.equals(param.getUnit())) {
/** * Set the parameter value as an array of floating point and their associated unit. * * @param values The parameter values. * @param unit The unit for the specified value. * @throws InvalidParameterValueException if the floating point type is inappropriate for this * parameter, or if the value is illegal for some other reason (for example a value out of * range). */ public void setValue(double[] values, final Unit<?> unit) throws InvalidParameterValueException { ensureNonNull("unit", unit); @SuppressWarnings("unchecked") // Checked by constructor. final ParameterDescriptor<T> descriptor = (ParameterDescriptor) this.descriptor; final Unit<?> targetUnit = descriptor.getUnit(); if (targetUnit == null) { throw unitlessParameter(descriptor); } final int expectedID = getUnitMessageID(targetUnit); if (getUnitMessageID(unit) != expectedID) { throw new IllegalArgumentException(Errors.format(expectedID, unit)); } final double[] converted = values.clone(); UnitConverter converter = Units.getConverterToAny(unit, targetUnit); for (int i = 0; i < converted.length; i++) { converted[i] = converter.convert(converted[i]); } this.value = ensureValidValue(descriptor, converted); this.unit = unit; }
@SuppressWarnings("unchecked") // Checked by constructor. final ParameterDescriptor<T> descriptor = (ParameterDescriptor) this.descriptor; final Unit<?> targetUnit = descriptor.getUnit(); if (targetUnit == null) { throw unitlessParameter(descriptor);
value = descriptor.getUnit(); if (value != null) { table.write(value.toString());
/** * Constructs a parameter value from the specified descriptor. * The value will be initialized to the default value, if any. * * @param descriptor The abstract definition of this parameter. */ public Parameter(final ParameterDescriptor<T> descriptor) { super(descriptor); value = descriptor.getDefaultValue(); unit = descriptor.getUnit(); }
@Override public Unit<?> getUnit() {return descriptor.getUnit();} @Override public ParameterValue<T> createValue() {return descriptor.createValue();}
/** * Creates a parameter value from the specified descriptor. * The value will be initialized to the default value, if any. * * @param descriptor the abstract definition of this parameter. */ public DefaultParameterValue(final ParameterDescriptor<T> descriptor) { ensureNonNull("descriptor", descriptor); this.descriptor = descriptor; this.value = descriptor.getDefaultValue(); this.unit = descriptor.getUnit(); }
/** * Creates a parameter value from the specified descriptor. * The value will be initialized to the default value, if any. * * @param descriptor the abstract definition of this parameter. */ public DefaultParameterValue(final ParameterDescriptor<T> descriptor) { ensureNonNull("descriptor", descriptor); this.descriptor = descriptor; this.value = descriptor.getDefaultValue(); this.unit = descriptor.getUnit(); }
final double paramValue = param.pullDouble("value"); final ParameterValue<?> parameter = parameters.parameter(paramName); final Unit<?> expected = parameter.getDescriptor().getUnit(); if (expected != null && !AbstractUnit.ONE.equals(expected)) { if (linearUnit != null && SI.METRE.isCompatible(expected)) {
assertNull("minimum", descriptor.getMinimumValue()); assertNull("maximum", descriptor.getMaximumValue()); assertNull("unit", descriptor.getUnit()); assertNull("validValues", descriptor.getValidValues()); try { assertEquals("doubleValue", 300, parameter.doubleValue(MetricPrefix.CENTI(SI.METRE)), 0); assertEquals("name", "Test", descriptor.getName().getCode()); assertEquals("unit", SI.METRE, descriptor.getUnit()); assertNull("defaultValue", descriptor.getDefaultValue()); assertNull("minimum", descriptor.getMinimumValue()); assertEquals("value", AxisDirection.NORTH, parameter.getValue()); assertEquals("name", "Test", descriptor.getName().getCode()); assertNull("unit", descriptor.getUnit()); assertNull("defaultValue", descriptor.getDefaultValue()); assertNull("minimum", descriptor.getMinimumValue());
parameter = dDescriptor.createValue(); 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);