Search in sources :

Example 1 with DefaultParameterValue

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();
    }
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) ParameterValue(org.opengis.parameter.ParameterValue) DefaultParameterValue(org.apache.sis.parameter.DefaultParameterValue) GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) FormattableObject(org.apache.sis.io.wkt.FormattableObject)

Example 2 with DefaultParameterValue

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);
    }
}
Also used : DefaultParameterValue(org.apache.sis.parameter.DefaultParameterValue) GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) ParameterValue(org.opengis.parameter.ParameterValue) DefaultParameterValue(org.apache.sis.parameter.DefaultParameterValue) GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) DefaultParameterValueGroup(org.apache.sis.parameter.DefaultParameterValueGroup) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) DefaultParameterValueGroup(org.apache.sis.parameter.DefaultParameterValueGroup) Collection(java.util.Collection)

Aggregations

DefaultParameterValue (org.apache.sis.parameter.DefaultParameterValue)2 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)2 ParameterValue (org.opengis.parameter.ParameterValue)2 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)2 Collection (java.util.Collection)1 FormattableObject (org.apache.sis.io.wkt.FormattableObject)1 DefaultParameterDescriptorGroup (org.apache.sis.parameter.DefaultParameterDescriptorGroup)1 DefaultParameterValueGroup (org.apache.sis.parameter.DefaultParameterValueGroup)1 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)1 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)1