/** * Set the parameter value as a {@link Double} object. * * @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 void setValue(final Object value) throws InvalidParameterValueException { @SuppressWarnings("unchecked") // Checked by constructor. final ParameterDescriptor<Double> descriptor = (ParameterDescriptor) this.descriptor; this.value = Parameter.ensureValidValue(descriptor, value); }
/** * Set the parameter value as an object. The object type is typically a {@link Double}, {@link * Integer}, {@link Boolean}, {@link String}, {@link URI}, {@code double[]} or {@code int[]}. * * @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). * @see #getValue */ public void setValue(final Object value) throws InvalidParameterValueException { @SuppressWarnings("unchecked") // Checked by constructor. final ParameterDescriptor<T> descriptor = (ParameterDescriptor) this.descriptor; this.value = ensureValidValue(descriptor, value); }
/** * Sets the parameter value as a floating point. The unit, if any, stay unchanged. * * @param value The parameter 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). * @see #setValue(double,Unit) * @see #doubleValue() */ public void setValue(final double value) throws InvalidParameterValueException { final Double check = value; @SuppressWarnings("unchecked") // Checked by constructor. final ParameterDescriptor<T> descriptor = (ParameterDescriptor) this.descriptor; this.value = ensureValidValue(descriptor, check); }
/** * Set the parameter value as a floating point. * * @param value The parameter value. * @throws InvalidParameterValueException if the value is illegal for some reason (for example a * value out of range). */ public void setValue(final double value) throws InvalidParameterValueException { @SuppressWarnings("unchecked") // Checked by constructor. final ParameterDescriptor<Double> descriptor = (ParameterDescriptor) this.descriptor; this.value = Parameter.ensureValidValue(descriptor, Double.valueOf(value)); }
/** * Sets the parameter value as a boolean. * * @param value The parameter value. * @throws InvalidParameterValueException if the boolean type is inappropriate for this * parameter. * @see #booleanValue */ public void setValue(final boolean value) throws InvalidParameterValueException { @SuppressWarnings("unchecked") // Checked by constructor. final ParameterDescriptor<T> descriptor = (ParameterDescriptor) this.descriptor; final Boolean check = Boolean.valueOf(value); this.value = ensureValidValue(descriptor, check); }
/** * 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); }
/** * 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)); }
Parameter.ensureValidValue(this, defaultValue);
/** * 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; }
ensureValidValue(descriptor, converted);