sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1519058 - in /sis/branches/JDK7/core/sis-referencing/src: main/java/org/apache/sis/referencing/ test/java/org/apache/sis/referencing/ test/java/org/apache/sis/test/suite/
Date Fri, 30 Aug 2013 19:56:30 GMT
Author: desruisseaux
Date: Fri Aug 30 19:56:30 2013
New Revision: 1519058

URL: http://svn.apache.org/r1519058
Log:
Ported AbstractReferenceSystem.

Added:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java
  (with props)
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractReferenceSystemTest.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java?rev=1519058&r1=1519057&r2=1519058&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
[UTF-8] Fri Aug 30 19:56:30 2013
@@ -73,7 +73,8 @@ import java.util.Objects;
  * <ul>
  *   <li>a primary {@linkplain #getName() name}, considered by the object creator as
the preferred name,</li>
  *   <li>an arbitrary amount of {@linkplain #getAlias() aliases}, for example a list
of names used by other providers,</li>
- *   <li>an arbitrary amount of {@linkplain #getIdentifiers() identifiers}, typically
primary keys in the provider database.</li>
+ *   <li>an arbitrary amount of {@linkplain #getIdentifiers() identifiers}, typically
primary keys in the provider database,</li>
+ *   <li>optional {@linkplain #getRemarks() remarks}.</li>
  * </ul>
  *
  * {@section Instantiation}

Added: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java?rev=1519058&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java
(added)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java
[UTF-8] Fri Aug 30 19:56:30 2013
@@ -0,0 +1,177 @@
+/*
+ * 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 java.util.Map;
+import java.util.Objects;
+import javax.xml.bind.annotation.XmlElement;
+import org.opengis.util.InternationalString;
+import org.opengis.referencing.ReferenceSystem;
+import org.opengis.metadata.extent.Extent;
+import org.apache.sis.util.ComparisonMode;
+import org.apache.sis.util.Immutable;
+import org.apache.sis.util.iso.Types;
+
+import static org.apache.sis.util.Utilities.deepEquals;
+import static org.apache.sis.util.collection.Containers.property;
+
+
+/**
+ * Description of a spatial and temporal reference system used by a dataset.
+ * This class inherits the {@linkplain #getName() name}, {@linkplain #getAlias() aliases},
+ * {@linkplain #getIdentifiers() identifiers} and {@linkplain #getRemarks() remarks} from
+ * the parent class, and adds the following information:
+ *
+ * <ul>
+ *   <li>a {@linkplain #getDomainOfValidity() domain of validity}, the area for which
the reference system is valid,</li>
+ *   <li>a {@linkplain #getScope() scope}, which describes the domain of usage or limitation
of usage.
+ * </ul>
+ *
+ * {@section Instantiation}
+ * This class is conceptually <cite>abstract</cite>, even if it is technically
possible to instantiate it.
+ * Typical applications should create instances of the most specific subclass prefixed by
{@code Default} instead.
+ *
+ * @author  Martin Desruisseaux (IRD, Geomatys)
+ * @since   0.4 (derived from geotk-2.1)
+ * @version 0.4
+ * @module
+ */
+@Immutable
+public class AbstractReferenceSystem extends AbstractIdentifiedObject implements ReferenceSystem
{
+    /**
+     * Serial number for inter-operability with different versions.
+     */
+    private static final long serialVersionUID = 3337659819553899435L;
+
+    /**
+     * Area for which the (coordinate) reference system is valid.
+     */
+    private final Extent domainOfValidity;
+
+    /**
+     * Description of domain of usage, or limitations of usage,
+     * for which this (coordinate) reference system object is valid.
+     */
+    @XmlElement(required = true)
+    private final InternationalString scope;
+
+    /**
+     * Constructs a new reference system with the same values than the specified one.
+     * This copy constructor provides a way to convert an arbitrary implementation into a
SIS one
+     * or a user-defined one (as a subclass), usually in order to leverage some implementation-specific
API.
+     *
+     * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p>
+     *
+     * @param object The reference system to copy.
+     */
+    public AbstractReferenceSystem(final ReferenceSystem object) {
+        super(object);
+        domainOfValidity = object.getDomainOfValidity();
+        scope            = object.getScope();
+    }
+
+    /**
+     * Constructs a reference system from a set of properties.
+     * The properties given in argument follow the same rules than for the
+     * {@linkplain AbstractIdentifiedObject#AbstractIdentifiedObject(Map) super-class constructor}.
+     * Additionally, the following properties are understood by this constructor:
+     *
+     * <table class="sis">
+     *   <tr>
+     *     <th>Property name</th>
+     *     <th>Value type</th>
+     *     <th>Returned by</th>
+     *   </tr>
+     *   <tr>
+     *     <td>{@value org.opengis.referencing.ReferenceSystem#DOMAIN_OF_VALIDITY_KEY}</td>
+     *     <td>{@link Extent}</td>
+     *     <td>{@link #getDomainOfValidity()}</td>
+     *   </tr>
+     *   <tr>
+     *     <td>{@value org.opengis.referencing.ReferenceSystem#SCOPE_KEY}</td>
+     *     <td>{@link String} or {@link InternationalString}</td>
+     *     <td>{@link #getScope}</td>
+     *   </tr>
+     * </table>
+     *
+     * @param properties The properties to be given to this object.
+     */
+    public AbstractReferenceSystem(final Map<String,?> properties) {
+        super(properties);
+        domainOfValidity = property(properties, DOMAIN_OF_VALIDITY_KEY, Extent.class);
+        scope = Types.toInternationalString(properties, SCOPE_KEY);
+    }
+
+    /**
+     * Returns the region or timeframe in which this reference system is valid,
+     * or {@code null} if unspecified.
+     *
+     * @return Area or region or timeframe in which this (coordinate) reference system is
valid, or {@code null}.
+     */
+    @Override
+    public Extent getDomainOfValidity() {
+        return domainOfValidity;
+    }
+
+    /**
+     * Returns the domain or limitations of usage, or {@code null} if unspecified.
+     *
+     * @return Description of domain of usage, or limitations of usage, for which this
+     *         (coordinate) reference system object is valid, or {@code null}.
+     */
+    @Override
+    public InternationalString getScope() {
+        return scope;
+    }
+
+    /**
+     * Compares this reference system with the specified object for equality.
+     * If the {@code mode} argument value is {@link ComparisonMode#STRICT STRICT} or
+     * {@link ComparisonMode#BY_CONTRACT BY_CONTRACT}, then all available properties are
+     * compared including the {@linkplain #getDomainOfValidity() domain of validity} and
+     * the {@linkplain #getScope() scope}.
+     *
+     * @param  object The object to compare to {@code this}.
+     * @param  mode {@link ComparisonMode#STRICT STRICT} for performing a strict comparison,
or
+     *         {@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA} for comparing only
properties
+     *         relevant to transformations.
+     * @return {@code true} if both objects are equal.
+     */
+    @Override
+    public boolean equals(final Object object, final ComparisonMode mode) {
+        if (super.equals(object, mode)) {
+            switch (mode) {
+                case STRICT: {
+                    final AbstractReferenceSystem that = (AbstractReferenceSystem) object;
+                    return Objects.equals(domainOfValidity, that.domainOfValidity) &&
+                           Objects.equals(scope,            that.scope);
+                }
+                case BY_CONTRACT: {
+                    if (!(object instanceof ReferenceSystem)) break;
+                    final ReferenceSystem that = (ReferenceSystem) object;
+                    return deepEquals(getDomainOfValidity(), that.getDomainOfValidity(),
mode) &&
+                           deepEquals(getScope(),            that.getScope(), mode);
+                }
+                default: {
+                    // Domain of validity and scope are metadata, so they can be ignored.
+                    return (object instanceof ReferenceSystem);
+                }
+            }
+        }
+        return false;
+    }
+}

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

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

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java?rev=1519058&r1=1519057&r2=1519058&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
[UTF-8] Fri Aug 30 19:56:30 2013
@@ -50,16 +50,16 @@ public final strictfp class AbstractIden
         assertNull(properties.put("realizationEpoch", "Realization epoch"));
         assertNull(properties.put("validArea",        "Valid area"));
 
-        final AbstractIdentifiedObject reference = new AbstractIdentifiedObject(properties);
-        Validators.validate(reference);
+        final AbstractIdentifiedObject object = new AbstractIdentifiedObject(properties);
+        Validators.validate(object);
 
-        assertEquals("name",       "This is a name",      reference.getName().getCode());
-        assertNull  ("codeSpace",                         reference.getName().getCodeSpace());
-        assertNull  ("version",                           reference.getName().getVersion());
-        assertEquals("remarks",    "There is remarks",    reference.getRemarks().toString(Locale.ENGLISH));
-        assertEquals("remarks_fr", "Voici des remarques", reference.getRemarks().toString(Locale.FRENCH));
-        assertTrue  ("identifiers",                       reference.getIdentifiers().isEmpty());
-        assertNull  ("identifier",                        reference.getIdentifier());
-        assertTrue  ("aliases",                           reference.getAlias().isEmpty());
+        assertEquals("name",       "This is a name",      object.getName().getCode());
+        assertNull  ("codeSpace",                         object.getName().getCodeSpace());
+        assertNull  ("version",                           object.getName().getVersion());
+        assertEquals("remarks",    "There is remarks",    object.getRemarks().toString(Locale.ENGLISH));
+        assertEquals("remarks_fr", "Voici des remarques", object.getRemarks().toString(Locale.FRENCH));
+        assertTrue  ("identifiers",                       object.getIdentifiers().isEmpty());
+        assertNull  ("identifier",                        object.getIdentifier());
+        assertTrue  ("aliases",                           object.getAlias().isEmpty());
     }
 }

Added: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractReferenceSystemTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractReferenceSystemTest.java?rev=1519058&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractReferenceSystemTest.java
(added)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractReferenceSystemTest.java
[UTF-8] Fri Aug 30 19:56:30 2013
@@ -0,0 +1,61 @@
+/*
+ * 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 java.util.Map;
+import java.util.HashMap;
+import java.util.Locale;
+import org.opengis.test.Validators;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link AbstractReferenceSystem}.
+ *
+ * @author  Martin Desruisseaux (IRD)
+ * @since   0.4 (derived from geotk-2.2)
+ * @version 0.4
+ * @module
+ */
+@DependsOn(AbstractIdentifiedObjectTest.class)
+public final strictfp class AbstractReferenceSystemTest extends TestCase {
+    /**
+     * Tests {@link AbstractReferenceSystem}.
+     */
+    @Test
+    public void testReferenceSystem() {
+        final Map<String,Object> properties = new HashMap<>();
+        assertNull(properties.put("name",       "This is a name"));
+        assertNull(properties.put("scope",      "This is a scope"));
+        assertNull(properties.put("scope_fr",   "Valide dans ce domaine"));
+        assertNull(properties.put("remarks",    "There is remarks"));
+        assertNull(properties.put("remarks_fr", "Voici des remarques"));
+
+        final AbstractReferenceSystem reference = new AbstractReferenceSystem(properties);
+        Validators.validate(reference);
+
+        assertEquals("name",       "This is a name",         reference.getName()   .getCode());
+        assertEquals("scope",      "This is a scope",        reference.getScope()  .toString(Locale.ROOT));
+        assertEquals("scope_fr",   "Valide dans ce domaine", reference.getScope()  .toString(Locale.FRENCH));
+        assertEquals("remarks",    "There is remarks",       reference.getRemarks().toString(Locale.ENGLISH));
+        assertEquals("remarks_fr", "Voici des remarques",    reference.getRemarks().toString(Locale.FRENCH));
+    }
+}

Propchange: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractReferenceSystemTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractReferenceSystemTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1519058&r1=1519057&r2=1519058&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Fri Aug 30 19:56:30 2013
@@ -35,6 +35,7 @@ import org.junit.BeforeClass;
     org.apache.sis.io.wkt.FormatterTest.class,
     org.apache.sis.referencing.NamedIdentifierTest.class,
     org.apache.sis.referencing.AbstractIdentifiedObjectTest.class,
+    org.apache.sis.referencing.AbstractReferenceSystemTest.class,
     org.apache.sis.geometry.AbstractDirectPositionTest.class,
     org.apache.sis.geometry.GeneralDirectPositionTest.class,
     org.apache.sis.geometry.DirectPosition1DTest.class,



Mime
View raw message