Java Code Examples for org.opengis.parameter.GeneralParameterDescriptor#getAlias()

The following examples show how to use org.opengis.parameter.GeneralParameterDescriptor#getAlias() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapProjectionTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts that the primary name of the given parameter is the given name in the EPSG namespace.
 * Then asserts that the first alias (ignoring other EPSG alias) of the given parameter is the
 * given name in the OGC namespace.
 */
private static void assertParamEquals(final String epsgName, final String ogcName, final boolean isMandatory,
        final GeneralParameterDescriptor actual)
{
    if (epsgName != null) {
        assertEpsgIdentifierEquals(epsgName, actual.getName());
    } else {
        assertOgcIdentifierEquals(ogcName, actual.getName());
    }
    assertEquals("minimumOccurs", isMandatory ? 1 : 0, actual.getMinimumOccurs());
    if (epsgName != null) {
        for (final GenericName alias : actual.getAlias()) {
            if (alias instanceof ReferenceIdentifier && ((ReferenceIdentifier) alias).getAuthority() != Citations.EPSG) {
                assertOgcIdentifierEquals(ogcName, (ReferenceIdentifier) alias);
                return;
            }
        }
        fail("OGC alias not found.");
    }
}
 
Example 2
Source File: MapProjection.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the name of the given authority declared in the given parameter descriptor.
 * This method is used only as a way to avoid creating many instances of the same name.
 *
 * @param  authority   the authority for which to get the name.
 * @param  parameters  where to get name for the given authority.
 * @throws NoSuchElementException if the given authority has not been found.
 */
private static GenericName sameNameAs(final Citation authority, final GeneralParameterDescriptor parameters) {
    for (final GenericName candidate : parameters.getAlias()) {
        if (candidate instanceof Identifier && ((Identifier) candidate).getAuthority() == authority) {
            return candidate;
        }
    }
    throw new NoSuchElementException();
}
 
Example 3
Source File: ProvidersTest.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * 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.getConstructor((Class[]) null).newInstance((Object[]) null);
        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.");
                }
            }
        }
    }
}