UnitConverter converter = Units.getConverterToAny(candidate, unit); if (!converter.isLinear()) {
value = Units.getConverterToAny(unit, target).convert(value);
value = Units.getConverterToAny(unit, target).convert(value);
/** * 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)); }
/** * Returns the numeric value of the coordinate operation parameter in the specified unit of * measure. This convenience method apply unit conversion on the fly as needed. * * @param unit The unit of measure for the value to be returned. * @return The numeric value represented by this parameter after conversion to type {@code * double} and conversion to {@code unit}. * @throws IllegalArgumentException if the specified unit is invalid for this parameter. */ public double doubleValue(final Unit<?> unit) throws IllegalArgumentException { ensureNonNull("unit", unit); final Unit<?> thisUnit = 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)); } return Units.getConverterToAny(thisUnit, unit).convert(value); }
/** * Returns the envelope span along the specified dimension, in terms of the given units. * * @param dimension The dimension to query. * @param unit The unit for the return value. * @return The span in terms of the given unit. * @throws IndexOutOfBoundsException If the given index is out of bounds. * @throws ConversionException if the length can't be converted to the specified units. * @throws IllegalArgumentException if the target units are not compatible with the units of the * provided {@code dimension} * @since 2.5 */ public double getSpan(final int dimension, final Unit<?> unit) throws IndexOutOfBoundsException { double value = getSpan(dimension); if (crs != null) { final Unit<?> source = crs.getCoordinateSystem().getAxis(dimension).getUnit(); if (source != null) { value = Units.getConverterToAny(source, unit).convert(value); } } return value; }
/** * Returns the numeric value of the coordinate operation parameter in the specified unit of * measure. This convenience method apply unit conversion on the fly as needed. * * @param unit The unit of measure for the value to be returned. * @return The numeric value represented by this parameter after conversion to type {@code * double} and conversion to {@code unit}. * @throws InvalidParameterTypeException if the value is not a numeric type. * @throws IllegalArgumentException if the specified unit is invalid for this parameter. * @see #getUnit * @see #setValue(double,Unit) * @see #doubleValueList(Unit) */ public double doubleValue(final Unit<?> unit) throws InvalidParameterTypeException { if (this.unit == null) { throw unitlessParameter(descriptor); } ensureNonNull("unit", unit); final int expectedID = getUnitMessageID(this.unit); if (getUnitMessageID(unit) != expectedID) { throw new IllegalArgumentException(Errors.format(expectedID, unit)); } return Units.getConverterToAny(this.unit, unit).convert(doubleValue()); }
/** * Returns an ordered sequence of numeric values in the specified unit of measure. This * convenience method apply unit conversion on the fly as needed. * * @param unit The unit of measure for the value to be returned. * @return The sequence of values represented by this parameter after conversion to type {@code * double} and conversion to {@code unit}. * @throws InvalidParameterTypeException if the value is not an array of {@code double}s. * @throws IllegalArgumentException if the specified unit is invalid for this parameter. * @see #getUnit * @see #setValue(double[],Unit) * @see #doubleValue(Unit) */ public double[] doubleValueList(final Unit<?> unit) throws InvalidParameterTypeException { if (this.unit == null) { throw unitlessParameter(descriptor); } ensureNonNull("unit", unit); final int expectedID = getUnitMessageID(this.unit); if (getUnitMessageID(unit) != expectedID) { throw new IllegalArgumentException(Errors.format(expectedID, unit)); } UnitConverter converter = Units.getConverterToAny(this.unit, unit); final double[] values = doubleValueList().clone(); for (int i = 0; i < values.length; i++) { values[i] = converter.convert(values[i]); } return values; }
/** * 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; }
Errors.format(expectedID, unit), descriptor.getName().getCode(), value); Double converted = Units.getConverterToAny(unit, targetUnit).convert(value); ensureValidValue(descriptor, converted);
UnitConverter converter = Units.getConverterToAny(sourceUnit, targetUnit); if (!converter.isLinear()) { throw new IllegalArgumentException(