Search in sources :

Example 41 with GenericName

use of org.opengis.util.GenericName 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 42 with GenericName

use of org.opengis.util.GenericName in project sis by apache.

the class IdentifiedObjectsTest method testIsHeuristicMatchForName.

/**
 * Tests {@link IdentifiedObjects#isHeuristicMatchForName(IdentifiedObject, String)}.
 */
@Test
public void testIsHeuristicMatchForName() {
    final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
    final GenericName name = factory.createGenericName(null, "myScope", "myName");
    // Intentional trailing space.
    IdentifiedObjectMock object = new IdentifiedObjectMock("myCode ", name);
    // Test the code.
    assertFalse(isHeuristicMatchForName(object, "other"));
    assertTrue(isHeuristicMatchForName(object, "myCode"));
    assertTrue(isHeuristicMatchForName(object, " my_code "));
    assertFalse(isHeuristicMatchForName(object, "testmyCode"));
    assertFalse(isHeuristicMatchForName(object, "other:myCode"));
    assertFalse(isHeuristicMatchForName(object, "test"));
    assertFalse(isHeuristicMatchForName(null, "myCode"));
    // Test the alias.
    assertTrue(isHeuristicMatchForName(object, "myName"));
    assertTrue(isHeuristicMatchForName(object, " My_name "));
    assertFalse(isHeuristicMatchForName(object, "myScope"));
    assertFalse(isHeuristicMatchForName(object, "other:myName"));
    assertFalse(isHeuristicMatchForName(object, "myScope:other"));
    assertFalse(isHeuristicMatchForName(object, "other:myScope:myName"));
    // Test non-letter and non-digits characters.
    object = new IdentifiedObjectMock("Mercator (1SP)", name);
    assertTrue(isHeuristicMatchForName(object, "Mercator (1SP)"));
    assertTrue(isHeuristicMatchForName(object, "Mercator_1SP"));
    assertFalse(isHeuristicMatchForName(object, "Mercator_2SP"));
    // Test diacritical signs
    object = new IdentifiedObjectMock("Réunion", name);
    assertTrue(isHeuristicMatchForName(object, "Réunion"));
    assertTrue(isHeuristicMatchForName(object, "Reunion"));
}
Also used : IdentifiedObjectMock(org.apache.sis.test.mock.IdentifiedObjectMock) GenericName(org.opengis.util.GenericName) NameFactory(org.opengis.util.NameFactory) Test(org.junit.Test)

Example 43 with GenericName

use of org.opengis.util.GenericName in project sis by apache.

the class ParameterBuilderTest method testMercatorProjection.

/**
 * Tests the <cite>"Mercator (variant A)"</cite> example given in Javadoc.
 */
@Test
@DependsOnMethod("testCreate")
@SuppressWarnings("UnnecessaryBoxing")
public void testMercatorProjection() {
    final ParameterBuilder builder = new ParameterBuilder();
    builder.setCodeSpace(Citations.EPSG, "EPSG").setRequired(true);
    final ParameterDescriptor<?>[] parameters = { builder.addName("Longitude of natural origin").addName(Citations.OGC, "central_meridian").addName(Citations.GEOTIFF, "NatOriginLong").setRemarks("Some remarks.").createBounded(-180, +180, 0, Units.DEGREE), builder.addName("Latitude of natural origin").createBounded(-80, +84, 0, Units.DEGREE), builder.addName("Scale factor at natural origin").createStrictlyPositive(1, Units.UNITY), builder.addName("False easting").create(0, Units.METRE), builder.addName("False northing").create(0, Units.METRE) };
    // Tests random properties.
    assertEquals("EPSG", parameters[1].getName().getCodeSpace());
    assertEquals("False easting", parameters[3].getName().getCode());
    assertEquals("Some remarks.", parameters[0].getRemarks().toString());
    assertEquals(Double.valueOf(84), parameters[1].getMaximumValue());
    assertEquals(Units.METRE, parameters[4].getUnit());
    assertTrue(parameters[1].getAlias().isEmpty());
    final GenericName alias = parameters[0].getAlias().iterator().next();
    assertEquals("central_meridian", alias.tip().toString());
    assertEquals("OGC", alias.head().toString());
    assertEquals("OGC:central_meridian", alias.toString());
}
Also used : GenericName(org.opengis.util.GenericName) ParameterDescriptor(org.opengis.parameter.ParameterDescriptor) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 44 with GenericName

use of org.opengis.util.GenericName in project sis by apache.

the class TypesTest method testResources.

/**
 * Verifies that all designations and definitions can be read from the resources.
 */
private static void testResources(final DefaultFeatureType type) {
    for (final AbstractIdentifiedType p : type.getProperties(false)) {
        final GenericName name = p.getName();
        if (!AttributeConvention.contains(name)) {
            final String label = name.toString();
            assertNonEmpty(label, p.getDesignation());
            assertNonEmpty(label, p.getDefinition());
        }
    }
}
Also used : GenericName(org.opengis.util.GenericName) AbstractIdentifiedType(org.apache.sis.feature.AbstractIdentifiedType) InternationalString(org.opengis.util.InternationalString)

Example 45 with GenericName

use of org.opengis.util.GenericName in project sis by apache.

the class AbstractName method toFullyQualifiedName.

/**
 * Returns a view of this name as a fully-qualified name. The {@linkplain #scope() scope}
 * of a fully qualified name is {@linkplain DefaultNameSpace#isGlobal() global}.
 * If the scope of this name is already global, then this method returns {@code this}.
 *
 * @return the fully-qualified name (never {@code null}).
 */
@Override
public synchronized GenericName toFullyQualifiedName() {
    if (fullyQualified == null) {
        final NameSpace scope = scope();
        if (scope.isGlobal()) {
            fullyQualified = this;
        } else {
            final GenericName prefix = scope.name();
            assert prefix.scope().isGlobal() : prefix;
            fullyQualified = new DefaultScopedName(prefix, this);
        }
    }
    return fullyQualified;
}
Also used : GenericName(org.opengis.util.GenericName) NameSpace(org.opengis.util.NameSpace)

Aggregations

GenericName (org.opengis.util.GenericName)46 Test (org.junit.Test)11 ReferenceIdentifier (org.opengis.referencing.ReferenceIdentifier)9 InternationalString (org.opengis.util.InternationalString)9 ArrayList (java.util.ArrayList)5 IdentifiedObject (org.opengis.referencing.IdentifiedObject)5 NameFactory (org.opengis.util.NameFactory)5 Identifier (org.opengis.metadata.Identifier)4 ScopedName (org.opengis.util.ScopedName)4 HashMap (java.util.HashMap)3 DependsOnMethod (org.apache.sis.test.DependsOnMethod)3 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 Collection (java.util.Collection)2 IdentityHashMap (java.util.IdentityHashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 AbstractIdentifiedType (org.apache.sis.feature.AbstractIdentifiedType)2 NameToIdentifier (org.apache.sis.internal.metadata.NameToIdentifier)2 TableAppender (org.apache.sis.io.TableAppender)2