use of org.apache.sis.parameter.DefaultParameterValue in project sis by apache.
the class WKTUtilities method append.
/**
* Appends a {@linkplain ParameterValue parameter} in a {@code PARAMETER[…]} element.
* If the supplied parameter is actually a {@linkplain ParameterValueGroup parameter group},
* all contained parameters will be flattened in a single list.
*
* @param parameter the parameter to append to the WKT, or {@code null} if none.
* @param formatter the formatter where to append the parameter.
*/
public static void append(GeneralParameterValue parameter, final Formatter formatter) {
if (parameter instanceof ParameterValueGroup) {
boolean first = true;
for (final GeneralParameterValue param : ((ParameterValueGroup) parameter).values()) {
if (first) {
formatter.newLine();
first = false;
}
append(param, formatter);
}
}
if (parameter instanceof ParameterValue<?>) {
if (!(parameter instanceof FormattableObject)) {
parameter = new DefaultParameterValue<>((ParameterValue<?>) parameter);
}
formatter.append((FormattableObject) parameter);
formatter.newLine();
}
}
use of org.apache.sis.parameter.DefaultParameterValue in project sis by apache.
the class CC_OperationMethod method store.
/**
* Stores the given {@code parameters} into the given {@code addTo} collection.
* This method copies only the <em>references</em> if possible. However is some
* cases the values may need to be copied in new parameter instances.
*
* <div class="note"><b>Note:</b>
* this code is defined in this {@code CC_OperationMethod} class instead than in the
* {@link DefaultOperationMethod} class in the hope to reduce the amount of code processed
* by the JVM in the common case where JAXB (un)marshalling is not needed.</div>
*
* @param parameters the parameters to add to the {@code addTo} collection.
* @param addTo where to store the {@code parameters}.
* @param replacements the replacements to apply in the {@code GeneralParameterValue} instances.
*/
public static void store(final GeneralParameterValue[] parameters, final Collection<GeneralParameterValue> addTo, final Map<GeneralParameterDescriptor, GeneralParameterDescriptor> replacements) {
for (GeneralParameterValue p : parameters) {
final GeneralParameterDescriptor replacement = replacements.get(p.getDescriptor());
if (replacement != null) {
if (p instanceof ParameterValue<?>) {
final ParameterValue<?> source = (ParameterValue<?>) p;
final ParameterValue<?> target = new DefaultParameterValue<>((ParameterDescriptor<?>) replacement);
final Object value = source.getValue();
final Unit<?> unit = source.getUnit();
if (unit == null) {
target.setValue(value);
} else if (value instanceof double[]) {
target.setValue((double[]) value, unit);
} else {
target.setValue(((Number) value).doubleValue(), unit);
}
p = target;
} else if (p instanceof ParameterValueGroup) {
final ParameterValueGroup source = (ParameterValueGroup) p;
final ParameterValueGroup target = new DefaultParameterValueGroup((ParameterDescriptorGroup) replacement);
final Collection<GeneralParameterValue> values = source.values();
store(values.toArray(new GeneralParameterValue[values.size()]), target.values(), replacements);
p = target;
}
}
addTo.add(p);
}
}
Aggregations