Search in sources :

Example 26 with GeneralParameterDescriptor

use of org.opengis.parameter.GeneralParameterDescriptor 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)

Example 27 with GeneralParameterDescriptor

use of org.opengis.parameter.GeneralParameterDescriptor in project sis by apache.

the class TensorValuesTest method testAlphaNumericDescriptors.

/**
 * Tests {@link TensorValues#descriptors()} using alphanumeric (EPSG) contentions.
 */
@Test
@DependsOnMethod("testDescriptors")
public void testAlphaNumericDescriptors() {
    final Double N0 = 0.0;
    final Double N1 = 1.0;
    final Integer N3 = 3;
    final ParameterValueGroup group = createAlphaNumeric();
    final List<GeneralParameterDescriptor> descriptors = group.getDescriptor().descriptors();
    assertDescriptorEquals(NUM_ROW, N3, descriptors.get(0));
    assertDescriptorEquals(NUM_COL, N3, descriptors.get(1));
    assertDescriptorEquals("A0", N1, descriptors.get(2));
    assertDescriptorEquals("A1", N0, descriptors.get(3));
    assertDescriptorEquals("A2", N0, descriptors.get(4));
    assertDescriptorEquals("B0", N0, descriptors.get(5));
    assertDescriptorEquals("B1", N1, descriptors.get(6));
    assertDescriptorEquals("B2", N0, descriptors.get(7));
    assertDescriptorEquals("C0", N0, descriptors.get(8));
    assertDescriptorEquals("C1", N0, descriptors.get(9));
    assertDescriptorEquals("C2", N1, descriptors.get(10));
    assertEquals("size", 11, descriptors.size());
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 28 with GeneralParameterDescriptor

use of org.opengis.parameter.GeneralParameterDescriptor in project sis by apache.

the class TensorValuesTest method testDescriptors.

/**
 * Tests {@link TensorValues#descriptors()} using WKT1 contentions.
 */
@Test
public void testDescriptors() {
    final Double N0 = 0.0;
    final Double N1 = 1.0;
    final Integer N3 = 3;
    final ParameterValueGroup group = createWKT1();
    group.parameter(NUM_ROW).setValue(1);
    group.parameter(NUM_COL).setValue(1);
    List<GeneralParameterDescriptor> descriptors = group.getDescriptor().descriptors();
    assertDescriptorEquals(NUM_ROW, N3, descriptors.get(0));
    assertDescriptorEquals(NUM_COL, N3, descriptors.get(1));
    assertDescriptorEquals("elt_0_0", N1, descriptors.get(2));
    assertEquals("size", 3, descriptors.size());
    group.parameter(NUM_ROW).setValue(2);
    group.parameter(NUM_COL).setValue(3);
    descriptors = group.getDescriptor().descriptors();
    assertDescriptorEquals(NUM_ROW, N3, descriptors.get(0));
    assertDescriptorEquals(NUM_COL, N3, descriptors.get(1));
    assertDescriptorEquals("elt_0_0", N1, descriptors.get(2));
    assertDescriptorEquals("elt_0_1", N0, descriptors.get(3));
    assertDescriptorEquals("elt_0_2", N0, descriptors.get(4));
    assertDescriptorEquals("elt_1_0", N0, descriptors.get(5));
    assertDescriptorEquals("elt_1_1", N1, descriptors.get(6));
    assertDescriptorEquals("elt_1_2", N0, descriptors.get(7));
    assertEquals("size", 8, descriptors.size());
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) Test(org.junit.Test)

Example 29 with GeneralParameterDescriptor

use of org.opengis.parameter.GeneralParameterDescriptor in project sis by apache.

the class ProvidersTest method ensureParameterUniqueness.

/**
 * Ensures that every parameter instance is unique. Actually this test is not strong requirement.
 * This is only for sharing existing resources by avoiding unnecessary objects duplication.
 *
 * @throws ReflectiveOperationException if the instantiation of a service provider failed.
 */
@Test
public void ensureParameterUniqueness() throws ReflectiveOperationException {
    final Map<GeneralParameterDescriptor, String> groupNames = new IdentityHashMap<>();
    final Map<GeneralParameterDescriptor, GeneralParameterDescriptor> parameters = new HashMap<>();
    final Map<Object, Object> namesAndIdentifiers = new HashMap<>();
    for (final Class<?> c : methods()) {
        final OperationMethod method = (OperationMethod) c.newInstance();
        final ParameterDescriptorGroup group = method.getParameters();
        final String operationName = group.getName().getCode();
        for (final GeneralParameterDescriptor param : group.descriptors()) {
            assertFalse("Parameter declared twice in the same group.", operationName.equals(groupNames.put(param, operationName)));
            /*
                 * Ensure uniqueness of the parameter descriptor as a whole.
                 */
            final Identifier name = param.getName();
            Object existing = parameters.put(param, param);
            if (existing != null && existing != param) {
                fail("Parameter “" + name.getCode() + "” defined in “" + operationName + '”' + " was already defined in “" + groupNames.get(existing) + "”." + " The same instance could be shared.");
            }
            /*
                 * Ensure uniqueness of each name and identifier.
                 */
            existing = namesAndIdentifiers.put(name, name);
            if (existing != null && existing != name) {
                fail("The name of parameter “" + name.getCode() + "” defined in “" + operationName + '”' + " was already defined elsewhere. The same instance could be shared.");
            }
            for (final GenericName alias : param.getAlias()) {
                existing = namesAndIdentifiers.put(alias, alias);
                if (existing != null && existing != alias) {
                    fail("Alias “" + alias + "” of parameter “" + name.getCode() + "” defined in “" + operationName + '”' + " was already defined elsewhere. The same instance could be shared.");
                }
            }
            for (final Identifier id : param.getIdentifiers()) {
                existing = namesAndIdentifiers.put(id, id);
                if (existing != null && existing != id) {
                    fail("Identifier “" + id + "” of parameter “" + name.getCode() + "” defined in “" + operationName + '”' + " was already defined elsewhere. The same instance could be shared.");
                }
            }
        }
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) DefaultOperationMethod(org.apache.sis.referencing.operation.DefaultOperationMethod) OperationMethod(org.opengis.referencing.operation.OperationMethod) GenericName(org.opengis.util.GenericName) Identifier(org.opengis.metadata.Identifier) Test(org.junit.Test)

Example 30 with GeneralParameterDescriptor

use of org.opengis.parameter.GeneralParameterDescriptor in project sis by apache.

the class AffineTest method verifyParameters.

/**
 * Verifies that the given providers contain parameters of the given names.
 */
private static void verifyParameters(final Affine provider, final String... expectedNames) {
    int index = 0;
    for (final GeneralParameterDescriptor p : provider.getParameters().descriptors()) {
        final String expectedName = expectedNames[index++];
        assertEquals(expectedName, p.getName().getCode());
    }
    assertEquals("Number of parameters", expectedNames.length, index);
}
Also used : GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor)

Aggregations

GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)30 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)12 Test (org.junit.Test)10 DefaultParameterDescriptorGroup (org.apache.sis.parameter.DefaultParameterDescriptorGroup)8 DependsOnMethod (org.apache.sis.test.DependsOnMethod)8 ParameterNotFoundException (org.opengis.parameter.ParameterNotFoundException)6 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)6 HashMap (java.util.HashMap)5 Identifier (org.opengis.metadata.Identifier)5 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)5 ParameterDescriptor (org.opengis.parameter.ParameterDescriptor)4 IdentityHashMap (java.util.IdentityHashMap)3 OperationMethod (org.opengis.referencing.operation.OperationMethod)3 ArrayList (java.util.ArrayList)2 DefaultParameterValueGroup (org.apache.sis.parameter.DefaultParameterValueGroup)2 CorruptedObjectException (org.apache.sis.util.CorruptedObjectException)2 InvalidParameterNameException (org.opengis.parameter.InvalidParameterNameException)2 ParameterValue (org.opengis.parameter.ParameterValue)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1