sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1653617 - in /sis/branches/JDK8/core: sis-referencing/src/main/java/org/apache/sis/referencing/ sis-utility/src/main/java/org/apache/sis/internal/util/ sis-utility/src/main/java/org/apache/sis/util/
Date Wed, 21 Jan 2015 17:51:50 GMT
Author: desruisseaux
Date: Wed Jan 21 17:51:49 2015
New Revision: 1653617

URL: http://svn.apache.org/r1653617
Log:
Initial draft of an enumeration representing the result of checking if two IdentifiedObjects
are the same by looking at their identifiers.
According ISO 19162, identifiers shall have precedence over names at least for OperationMethod
and ParameterValue instances.

Added:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifierMatching.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Citations.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Characters.java

Added: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifierMatching.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifierMatching.java?rev=1653617&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifierMatching.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifierMatching.java
[UTF-8] Wed Jan 21 17:51:49 2015
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.referencing;
+
+import org.opengis.metadata.Identifier;
+import org.opengis.metadata.citation.Citation;
+import org.apache.sis.internal.util.Citations;
+import org.apache.sis.util.CharSequences;
+import org.apache.sis.util.Characters;
+
+
+/**
+ * Whether two {@code IdentifiedObject} instances contain matching, mismatching or contradictory
identifiers.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5
+ * @version 0.5
+ * @module
+ */
+public enum IdentifierMatching {
+    /**
+     * The two identified objects share at least one common identifier and no contradiction
was found.
+     * In such case, we can consider that the two {@code IdentifiedObject} instances are
for the same object.
+     *//**
+     * The two identified objects share at least one common identifier and no contradiction
was found.
+     * In such case, we can consider that the two {@code IdentifiedObject} instances are
for the same object.
+     */
+    MATCH,
+
+    /**
+     * The two identified objects have at least one identifier with different codes in the
same code space.
+     * In such case, we can consider that the two {@code IdentifiedObject} instances are
for different objects.
+     */
+    MISMATCH,
+
+    /**
+     * The two identified objects have some identifiers meeting the {@code MATCH} condition,
+     * and other identifiers meeting the {@code MISMATCH} condition.
+     */
+    CONTRADICTION,
+
+    /**
+     * The two identified objects do not have any identifier meeting the {@code MATCH} or
{@code MISMATCH} condition.
+     */
+    UNKNOWN;
+
+    /**
+     * Determines whether a match or mismatch is found between the two given collection of
identifiers.
+     * If any of the given collection is {@code null} or empty, this method returns {@link
#UNKNOWN}.
+     *
+     * @param  id1 The first collection of identifiers, or {@code null}.
+     * @param  id2 The second collection of identifiers, or {@code null}.
+     * @return {@link #MATCH} or {@link #MISMATCH} if (mis)matching can be determined without
contradiction,
+     *         or {@link #CONTRADICTION} or {@link #UNKNOWN} otherwise.
+     */
+    public static IdentifierMatching determine(final Iterable<? extends Identifier>
id1,
+                                               final Iterable<? extends Identifier>
id2)
+    {
+        if (id1 != null && id2 != null) {
+            Boolean match = null;
+            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)) {
+                        final boolean m = CharSequences.equalsFiltered(identifier.getCode(),
+                                other.getCode(), Characters.Filter.UNICODE_IDENTIFIER, true);
+                        if (match == null) {
+                            match = m;
+                        } else if (match != m) {
+                            return CONTRADICTION;
+                        }
+                    }
+                }
+            }
+            if (match != null) {
+                return match ? MATCH : MISMATCH;
+            }
+        }
+        return UNKNOWN;
+    }
+
+    /**
+     * 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;
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifierMatching.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifierMatching.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Citations.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Citations.java?rev=1653617&r1=1653616&r2=1653617&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Citations.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Citations.java
[UTF-8] Wed Jan 21 17:51:49 2015
@@ -216,8 +216,8 @@ public final class Citations extends Sta
      * one. The comparison is case-insensitive and ignores every character which is not a
      * {@linkplain Character#isLetterOrDigit(int) letter or a digit}.
      *
-     * <p>If a match is found, if the given {@code identifier} is non-null and if the
codespace
-     * of both objects is non-null, then the codespace is also compared.</p>
+     * <p>If a match is found, if the given {@code identifier} is non-null and if the
code space
+     * of both objects is non-null, then the code space is also compared.</p>
      *
      * <p>If (and <em>only</em> if) the citation does not contain any identifier,
then this method
      * fallback on titles comparison using the {@link #titleMatches(Citation, CharSequence)
titleMatches}
@@ -240,11 +240,11 @@ public final class Citations extends Sta
                 final Identifier id = identifiers.next();
                 if (id != null && equalsFiltered(code, id.getCode(), LETTERS_AND_DIGITS,
true)) {
                     if (identifier != null) {
-                        final String codespace = identifier.getCodeSpace();
-                        if (codespace != null) {
+                        final String codeSpace = identifier.getCodeSpace();
+                        if (codeSpace != null) {
                             final String cs = id.getCodeSpace();
                             if (cs != null) {
-                                return equalsFiltered(codespace, cs, LETTERS_AND_DIGITS,
true);
+                                return equalsFiltered(codeSpace, cs, LETTERS_AND_DIGITS,
true);
                             }
                         }
                     }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Characters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Characters.java?rev=1653617&r1=1653616&r2=1653617&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Characters.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Characters.java [UTF-8]
Wed Jan 21 17:51:49 2015
@@ -292,9 +292,9 @@ public final class Characters extends St
 
         /**
          * The subset of all characters for which {@link Character#isUnicodeIdentifierPart(int)}
-         * returns {@code true}, excluding {@linkplain Character#isIdentifierIgnorable(int)
-         * ignorable} characters. This subset includes all the {@link #LETTERS_AND_DIGITS}
-         * categories with the addition of the following ones:
+         * returns {@code true}, excluding {@linkplain Character#isIdentifierIgnorable(int)
ignorable} characters.
+         * This subset includes all the {@link #LETTERS_AND_DIGITS} categories with the addition
of the following
+         * ones:
          * {@link Character#LETTER_NUMBER},
          * {@link Character#CONNECTOR_PUNCTUATION CONNECTOR_PUNCTUATION},
          * {@link Character#NON_SPACING_MARK NON_SPACING_MARK} and



Mime
View raw message