Search in sources :

Example 16 with NameFactory

use of org.opengis.util.NameFactory 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 17 with NameFactory

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

the class NamedIdentifierTest method testCreateFromName.

/**
 * Tests the {@link NamedIdentifier#NamedIdentifier(GenericName)} constructor.
 */
@Test
public void testCreateFromName() {
    final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
    final NameSpace scope = factory.createNameSpace(factory.createLocalName(null, "IOGP"), null);
    final NamedIdentifier identifier = new NamedIdentifier(factory.createGenericName(scope, "EPSG", "4326"));
    Validators.validate((ReferenceIdentifier) identifier);
    Validators.validate((GenericName) identifier);
    // ImmutableIdentifier properties
    assertEquals("code", "4326", identifier.getCode());
    assertEquals("codeSpace", "EPSG", identifier.getCodeSpace());
    assertEquals("authority", "IOGP", Citations.getIdentifier(identifier.getAuthority()));
    assertNull("version", identifier.getVersion());
    assertNull("description", identifier.getDescription());
    // NamedIdentifier properties
    assertEquals("depth", 2, identifier.depth());
    assertEquals("tip", "4326", identifier.tip().toString());
    assertEquals("head", "EPSG", identifier.head().toString());
    assertEquals("name", "EPSG:4326", identifier.toString());
    assertSame("scope", scope, identifier.scope());
    assertFalse("scope.isGlobal", scope.isGlobal());
    assertEquals("scope", "IOGP", scope.name().toString());
}
Also used : NameSpace(org.opengis.util.NameSpace) NameFactory(org.opengis.util.NameFactory) Test(org.junit.Test)

Example 18 with NameFactory

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

the class AbstractName method castOrCopy.

/**
 * Returns a SIS name implementation with the values of the given arbitrary implementation.
 * This method performs the first applicable action in the following choices:
 *
 * <ul>
 *   <li>If the given object is {@code null}, then this method returns {@code null}.</li>
 *   <li>Otherwise if the given object is an instance of {@link LocalName}, then this
 *       method delegates to {@link DefaultLocalName#castOrCopy(LocalName)}.</li>
 *   <li>Otherwise if the given object is already an instance of {@code AbstractName},
 *       then it is returned unchanged.</li>
 *   <li>Otherwise a new instance of an {@code AbstractName} subclass is created using the
 *       {@link DefaultNameFactory#createGenericName(NameSpace, CharSequence[])} method.</li>
 * </ul>
 *
 * @param  object  the object to get as a SIS implementation, or {@code null} if none.
 * @return a SIS implementation containing the values of the given object (may be the
 *         given object itself), or {@code null} if the argument was null.
 */
public static AbstractName castOrCopy(final GenericName object) {
    if (object instanceof LocalName) {
        return DefaultLocalName.castOrCopy((LocalName) object);
    }
    if (object == null || object instanceof AbstractName) {
        return (AbstractName) object;
    }
    /*
         * Recreates a new name for the given name in order to get
         * a SIS implementation from an arbitrary implementation.
         */
    final List<? extends LocalName> parsedNames = object.getParsedNames();
    final CharSequence[] names = new CharSequence[parsedNames.size()];
    int i = 0;
    for (final LocalName component : parsedNames) {
        names[i++] = component.toInternationalString();
    }
    if (i != names.length) {
        throw new ConcurrentModificationException(Errors.format(Errors.Keys.UnexpectedChange_1, "parsedNames"));
    }
    /*
         * Following cast should be safe because DefaultFactories.forBuildin(Class) filters the factories in
         * order to return the Apache SIS implementation, which is known to create AbstractName instances.
         */
    final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
    return (AbstractName) factory.createGenericName(object.scope(), names);
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) LocalName(org.opengis.util.LocalName) NameFactory(org.opengis.util.NameFactory)

Example 19 with NameFactory

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

the class Names method parseGenericName.

/**
 * Creates a local or scoped name in the given namespace.
 * The character sequences can be either {@link String} or {@link InternationalString} instances.
 * The {@code namespace} character sequences is taken verbatim, while {@code scopedName} is splitted
 * around the {@linkplain DefaultNameSpace#DEFAULT_SEPARATOR default separator}, which is {@code ":"}.
 *
 * @param  namespace   the namespace, or {@code null} for the global namespace.
 * @param  separator   the separator between the namespace and the scoped name, or {@code null}
 *                     for the {@linkplain DefaultNameSpace#DEFAULT_SEPARATOR default separator}.
 * @param  scopedName  the name to parse using {@code ':'} as the separator between components.
 * @return a local or scoped name in the given namespace.
 *
 * @see DefaultNameFactory#parseGenericName(NameSpace, CharSequence)
 */
public static GenericName parseGenericName(final CharSequence namespace, final String separator, final CharSequence scopedName) {
    ensureNonNull("localPart", scopedName);
    final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
    return factory.parseGenericName(createNameSpace(factory, namespace, separator), scopedName);
}
Also used : NameFactory(org.opengis.util.NameFactory)

Example 20 with NameFactory

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

the class Names method createTypeName.

/**
 * Creates a type name which is local in the given namespace.
 * The character sequences can be either {@link String} or {@link InternationalString} instances.
 * Those character sequences are taken verbatim; they are <em>not</em> parsed into their components.
 *
 * <div class="note"><b>Example:</b> {@code createTypeName("gco", ":", "Integer")} returns a name
 * which can be used for representing the type of {@code <gco:Integer>} elements in XML files.</div>
 *
 * <div class="note"><b>Performance note:</b> this method is okay for <em>casual</em> use. If many names need
 * to be created in the same namespace, then {@link DefaultNameFactory#createTypeName(NameSpace, CharSequence)}
 * is more efficient since it allows to create the {@code NameSpace} object only once.</div>
 *
 * @param  namespace  the namespace, or {@code null} for the global namespace.
 * @param  separator  the separator between the namespace and the local part, or {@code null}
 *                    for the {@linkplain DefaultNameSpace#DEFAULT_SEPARATOR default separator}.
 * @param  localPart  the name which is locale in the given namespace.
 * @return a type name in the given namespace.
 *
 * @see DefaultNameFactory#createTypeName(NameSpace, CharSequence)
 */
public static TypeName createTypeName(final CharSequence namespace, final String separator, final CharSequence localPart) {
    ensureNonNull("localPart", localPart);
    final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
    return factory.createTypeName(createNameSpace(factory, namespace, separator), localPart);
}
Also used : NameFactory(org.opengis.util.NameFactory)

Aggregations

NameFactory (org.opengis.util.NameFactory)20 Test (org.junit.Test)13 DependsOnMethod (org.apache.sis.test.DependsOnMethod)6 GenericName (org.opengis.util.GenericName)5 LocalName (org.opengis.util.LocalName)5 InternationalString (org.opengis.util.InternationalString)4 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)2 NameSpace (org.opengis.util.NameSpace)2 ConcurrentModificationException (java.util.ConcurrentModificationException)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)1 IdentifiedObjectMock (org.apache.sis.test.mock.IdentifiedObjectMock)1 DefaultNameFactory (org.apache.sis.util.iso.DefaultNameFactory)1 Citation (org.opengis.metadata.citation.Citation)1 ResponsibleParty (org.opengis.metadata.citation.ResponsibleParty)1 Constraints (org.opengis.metadata.constraint.Constraints)1 Format (org.opengis.metadata.distribution.Format)1 Extent (org.opengis.metadata.extent.Extent)1 MaintenanceInformation (org.opengis.metadata.maintenance.MaintenanceInformation)1