/** * 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; }
final Unit<?> targetUnit = descriptor.getUnit(); if (targetUnit == null) { throw unitlessParameter(descriptor);