You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2015/01/26 18:14:47 UTC
svn commit: r1654848 - in /sis/branches/JDK8/core/sis-referencing/src:
main/java/org/apache/sis/internal/referencing/
main/java/org/apache/sis/referencing/
test/java/org/apache/sis/internal/referencing/
Author: desruisseaux
Date: Mon Jan 26 17:14:47 2015
New Revision: 1654848
URL: http://svn.apache.org/r1654848
Log:
After more though, removed IdentifierMatching from the public API.
Writing a test case with real-world data (the EPSG identifiers of the "Mercator (variant A)" projection)
shows that the previous enum did not worked as intended.
For now we keep a simpler implementation as internal API.
Removed:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifierMatching.java
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/OperationMethodsTest.java
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java?rev=1654848&r1=1654847&r2=1654848&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java [UTF-8] Mon Jan 26 17:14:47 2015
@@ -17,12 +17,18 @@
package org.apache.sis.internal.referencing;
import java.util.Map;
+import org.opengis.metadata.Identifier;
+import org.opengis.metadata.citation.Citation;
import org.opengis.referencing.operation.Matrix;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.OperationMethod;
+import org.apache.sis.referencing.AbstractIdentifiedObject;
import org.apache.sis.referencing.operation.transform.MathTransforms;
import org.apache.sis.referencing.operation.transform.PassThroughTransform;
+import org.apache.sis.internal.util.Citations;
import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.CharSequences;
+import org.apache.sis.util.Characters;
import org.apache.sis.util.Static;
@@ -43,6 +49,71 @@ public final class OperationMethods exte
}
/**
+ * Determines whether a match or mismatch is found between the two given collections of identifiers.
+ * If any of the given collections is {@code null} or empty, this method returns {@code null}.
+ *
+ * <p>According ISO 19162 (<cite>Well known text representation of coordinate reference systems</cite>),
+ * {@linkplain AbstractIdentifiedObject#getIdentifier() identifiers} should have precedence over
+ * {@linkplain AbstractIdentifiedObject#getName() name} for identifying {@code IdentifiedObject}s,
+ * at least in the case of {@linkplain org.apache.sis.referencing.operation.DefaultOperationMethod
+ * operation methods} and {@linkplain org.apache.sis.parameter.AbstractParameterDescriptor parameters}.</p>
+ *
+ * @param id1 The first collection of identifiers, or {@code null}.
+ * @param id2 The second collection of identifiers, or {@code null}.
+ * @return {@code TRUE} or {@code FALSE} on match or mismatch respectively, or {@code null} if this method
+ * can not determine if there is a match or mismatch.
+ */
+ public static Boolean hasCommonIdentifier(final Iterable<? extends Identifier> id1,
+ final Iterable<? extends Identifier> id2)
+ {
+ if (id1 != null && id2 != null) {
+ boolean hasFound = false;
+ for (final Identifier identifier : id1) {
+ final Citation authority = identifier.getAuthority();
+ final String codeSpace = identifier.getCodeSpace();
+ for (final Identifier other : id2) {
+ if (authorityMatches(identifier, authority, codeSpace)) {
+ if (CharSequences.equalsFiltered(identifier.getCode(), other.getCode(), Characters.Filter.UNICODE_IDENTIFIER, true)) {
+ return Boolean.TRUE;
+ }
+ hasFound = true;
+ }
+ }
+ }
+ if (hasFound) {
+ return Boolean.FALSE;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns {@code true} if the given identifier authority matches the given {@code authority}.
+ * If one of the authority is null, then the comparison fallback on the given {@code codeSpace}.
+ * If the code spaces are also null, then this method conservatively returns {@code false}.
+ *
+ * @param identifier The identifier to compare.
+ * @param authority The desired authority, or {@code null}.
+ * @param codeSpace The desired code space or {@code null}, used as a fallback if an authority is null.
+ * @return {@code true} if the authority or code space (as a fallback only) matches.
+ */
+ private static boolean authorityMatches(final Identifier identifier, final Citation authority, final String codeSpace) {
+ if (authority != null) {
+ final Citation other = identifier.getAuthority();
+ if (other != null) {
+ return Citations.identifierMatches(authority, other);
+ }
+ }
+ if (codeSpace != null) {
+ final String other = identifier.getCodeSpace();
+ if (other != null) {
+ return CharSequences.equalsFiltered(codeSpace, other, Characters.Filter.UNICODE_IDENTIFIER, true);
+ }
+ }
+ return false;
+ }
+
+ /**
* Checks if an operation method and a math transform have a compatible number of source and target dimensions.
* In the particular case of a {@linkplain PassThroughTransform pass through transform} with more dimensions
* than what we would expect from the given method, the check will rather be performed against the
Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/OperationMethodsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/OperationMethodsTest.java?rev=1654848&r1=1654847&r2=1654848&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/OperationMethodsTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/OperationMethodsTest.java [UTF-8] Mon Jan 26 17:14:47 2015
@@ -16,12 +16,16 @@
*/
package org.apache.sis.internal.referencing;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
+import org.opengis.metadata.Identifier;
import org.opengis.parameter.ParameterDescriptorGroup;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.OperationMethod;
+import org.apache.sis.metadata.iso.ImmutableIdentifier;
import org.apache.sis.parameter.DefaultParameterDescriptorGroup;
import org.apache.sis.referencing.operation.DefaultOperationMethod;
import org.apache.sis.referencing.operation.transform.MathTransformsTest;
@@ -46,6 +50,36 @@ import static org.opengis.test.Assert.*;
})
public final strictfp class OperationMethodsTest extends TestCase {
/**
+ * Tests {@link OperationMethods#hasCommonIdentifier(Iterable, Iterable)}.
+ */
+ @Test
+ public void testHasCommonIdentifier() {
+ final List<Identifier> id1 = new ArrayList<>(3);
+ final List<Identifier> id2 = new ArrayList<>(2);
+ assertNull(OperationMethods.hasCommonIdentifier(id1, id2));
+ /*
+ * Add codes for two Operation Methods which are implemented in Apache SIS by the same class:
+ *
+ * - EPSG:9804 — "Mercator (variant A)" (formerly known as "Mercator (1SP)").
+ * - EPSG:1026 — "Mercator (Spherical)"
+ * - GeoTIFF:7 — "CT_Mercator"
+ */
+ id1.add(new ImmutableIdentifier(null, "EPSG", "9804"));
+ id1.add(new ImmutableIdentifier(null, "EPSG", "1026"));
+ id1.add(new ImmutableIdentifier(null, "GeoTIFF", "7"));
+ assertNull(OperationMethods.hasCommonIdentifier(id1, id2));
+ /*
+ * EPSG:9841 is a legacy (now deprecated) code for "Mercator (1SP)".
+ * We could have declared it as a deprecated code in the above list,
+ * but for the sake of this test we do not.
+ */
+ id2.add(new ImmutableIdentifier(null, "EPSG", "9841"));
+ assertEquals(Boolean.FALSE, OperationMethods.hasCommonIdentifier(id1, id2));
+ id2.add(new ImmutableIdentifier(null, "EPSG", "9804"));
+ assertEquals(Boolean.TRUE, OperationMethods.hasCommonIdentifier(id1, id2));
+ }
+
+ /**
* Creates a dummy operation method of the given dimensions.
*/
private static OperationMethod createOperationMethod(final int sourceDimension, final int targetDimension) {