sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1542796 - in /sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing: AbstractIdentifiedObject.java SubTypes.java datum/AbstractDatum.java datum/DefaultGeodeticDatum.java datum/SubTypes.java
Date Sun, 17 Nov 2013 18:55:59 GMT
Author: desruisseaux
Date: Sun Nov 17 18:55:58 2013
New Revision: 1542796

URL: http://svn.apache.org/r1542796
Log:
Provides 'castOrCopy' methods in parent class. This will be needed for the WKT formatter.

Added:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/SubTypes.java
  (with props)
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/SubTypes.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/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.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=1542796&r1=1542795&r2=1542796&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] Sun Nov 17 18:55:58 2013
@@ -290,6 +290,35 @@ public class AbstractIdentifiedObject ex
     }
 
     /**
+     * Returns a SIS identified object implementation with the values of the given arbitrary
implementation.
+     * This method performs the first applicable actions 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 is an instance of
+     *       {@link org.opengis.referencing.datum.Datum},
+     *       {@link org.opengis.referencing.datum.Ellipsoid} or
+     *       {@link org.opengis.referencing.datum.PrimeMeridian},
+     *       then this method delegates to the {@code castOrCopy(…)} method of the corresponding
SIS subclass.
+     *       Note that if the given object implements more than one of the above-cited interfaces,
+     *       then the {@code castOrCopy(…)} method to be used is unspecified.</li>
+     *   <li>Otherwise if the given object is already an instance of
+     *       {@code AbstractIdentifiedObject}, then it is returned unchanged.</li>
+     *   <li>Otherwise a new {@code AbstractIdentifiedObject} instance is created using
the
+     *       {@linkplain #AbstractIdentifiedObject(IdentifiedObject) copy constructor}
+     *       and returned. Note that this is a <cite>shallow</cite> copy operation,
since the other
+     *       properties contained in the given object are not recursively copied.</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 AbstractIdentifiedObject castOrCopy(final IdentifiedObject object) {
+        return SubTypes.castOrCopy(object);
+    }
+
+    /**
      * The {@code gml:id}, which is mandatory. The current implementation searches for the
first identifier,
      * regardless its authority. If no identifier is found, then the name is used.
      * If no name is found (which should not occur for valid objects), then this method returns
{@code null}.
@@ -525,7 +554,7 @@ public class AbstractIdentifiedObject ex
                 }
             }
         } else {
-            if (mode == ComparisonMode.STRICT) { // Same classes was required for this mode.
+            if (mode == ComparisonMode.STRICT) { // Same class was required for this mode.
                 return false;
             }
             if (!(object instanceof IdentifiedObject)) {

Added: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/SubTypes.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/SubTypes.java?rev=1542796&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/SubTypes.java
(added)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/SubTypes.java
[UTF-8] Sun Nov 17 18:55:58 2013
@@ -0,0 +1,67 @@
+/*
+ * 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.referencing.IdentifiedObject;
+import org.opengis.referencing.datum.Datum;
+import org.opengis.referencing.datum.Ellipsoid;
+import org.opengis.referencing.datum.PrimeMeridian;
+import org.apache.sis.referencing.datum.AbstractDatum;
+import org.apache.sis.referencing.datum.DefaultEllipsoid;
+import org.apache.sis.referencing.datum.DefaultPrimeMeridian;
+
+
+/**
+ * Implementation of {@link AbstractIdentifiedObject} methods that require knowledge about
subclasses.
+ * Those methods are defined in a separated static class for avoiding class loading of all
identified
+ * object implementations before necessary.
+ *
+ * <p>This class currently provides implementation for the following methods:</p>
+ * <ul>
+ *   <li>{@link AbstractIdentifiedObject#castOrCopy(IdentifiedObject)}</li>
+ * </ul>
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+final class SubTypes {
+    /**
+     * Do not allow instantiation of this class.
+     */
+    private SubTypes() {
+    }
+
+    /**
+     * Returns a SIS implementation for the given object.
+     *
+     * @see AbstractIdentifiedObject#castOrCopy(IdentifiedObject)
+     */
+    static AbstractIdentifiedObject castOrCopy(final IdentifiedObject object) {
+        if (object instanceof Datum) {
+            return AbstractDatum.castOrCopy((Datum) object);
+        }
+        if (object instanceof Ellipsoid) {
+            return DefaultEllipsoid.castOrCopy((Ellipsoid) object);
+        }
+        if (object instanceof PrimeMeridian) {
+            return DefaultPrimeMeridian.castOrCopy((PrimeMeridian) object);
+        }
+        return new AbstractIdentifiedObject(object);
+    }
+}

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

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

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java?rev=1542796&r1=1542795&r2=1542796&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
[UTF-8] Sun Nov 17 18:55:58 2013
@@ -183,6 +183,37 @@ public class AbstractDatum extends Abstr
     }
 
     /**
+     * Returns a SIS datum implementation with the values of the given arbitrary implementation.
+     * This method performs the first applicable actions 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 is an instance of
+     *       {@link org.opengis.referencing.datum.GeodeticDatum},
+     *       {@link org.opengis.referencing.datum.VerticalDatum},
+     *       {@link org.opengis.referencing.datum.TemporalDatum},
+     *       {@link org.opengis.referencing.datum.EngineeringDatum} or
+     *       {@link org.opengis.referencing.datum.ImageDatum},
+     *       then this method delegates to the {@code castOrCopy(…)} method of the corresponding
SIS subclass.
+     *       Note that if the given object implements more than one of the above-cited interfaces,
+     *       then the {@code castOrCopy(…)} method to be used is unspecified.</li>
+     *   <li>Otherwise if the given object is already an instance of
+     *       {@code AbstractDatum}, then it is returned unchanged.</li>
+     *   <li>Otherwise a new {@code AbstractDatum} instance is created using the
+     *       {@linkplain #AbstractDatum(Datum) copy constructor}
+     *       and returned. Note that this is a <cite>shallow</cite> copy operation,
since the other
+     *       properties contained in the given object are not recursively copied.</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 AbstractDatum castOrCopy(final Datum object) {
+        return SubTypes.castOrCopy(object);
+    }
+
+    /**
      * Returns a description of the point(s) used to anchor the datum to the Earth.
      * Also known as the "origin", especially for Engineering and Image Datums.
      *

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java?rev=1542796&r1=1542795&r2=1542796&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
[UTF-8] Sun Nov 17 18:55:58 2013
@@ -434,6 +434,7 @@ public class DefaultGeodeticDatum extend
                             Arrays.equals(this.bursaWolf,     that.bursaWolf);
                 }
                 default: {
+                    if (!(object instanceof GeodeticDatum)) break;
                     final GeodeticDatum that = (GeodeticDatum) object;
                     return deepEquals(getEllipsoid(),     that.getEllipsoid(),     mode)
&&
                            deepEquals(getPrimeMeridian(), that.getPrimeMeridian(), mode);

Added: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/SubTypes.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/SubTypes.java?rev=1542796&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/SubTypes.java
(added)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/SubTypes.java
[UTF-8] Sun Nov 17 18:55:58 2013
@@ -0,0 +1,76 @@
+/*
+ * 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.datum;
+
+import org.opengis.referencing.datum.Datum;
+import org.opengis.referencing.datum.GeodeticDatum;
+import org.opengis.referencing.datum.VerticalDatum;
+import org.opengis.referencing.datum.TemporalDatum;
+import org.opengis.referencing.datum.EngineeringDatum;
+import org.opengis.referencing.datum.ImageDatum;
+
+
+/**
+ * Implementation of {@link AbstractDatum} methods that require knowledge about subclasses.
+ * Those methods are defined in a separated static class for avoiding class loading of all
+ * datum implementations before necessary.
+ *
+ * <p>This class currently provides implementation for the following methods:</p>
+ * <ul>
+ *   <li>{@link AbstractDatum#castOrCopy(Datum)}</li>
+ * </ul>
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+final class SubTypes {
+    /**
+     * Do not allow instantiation of this class.
+     */
+    private SubTypes() {
+    }
+
+    /**
+     * Returns a SIS implementation for the given datum.
+     *
+     * @see AbstractDatum#castOrCopy(Datum)
+     */
+    static AbstractDatum castOrCopy(final Datum object) {
+        if (object instanceof GeodeticDatum) {
+            return DefaultGeodeticDatum.castOrCopy((GeodeticDatum) object);
+        }
+        if (object instanceof VerticalDatum) {
+            return DefaultVerticalDatum.castOrCopy((VerticalDatum) object);
+        }
+        if (object instanceof TemporalDatum) {
+            return DefaultTemporalDatum.castOrCopy((TemporalDatum) object);
+        }
+        if (object instanceof EngineeringDatum) {
+            return DefaultEngineeringDatum.castOrCopy((EngineeringDatum) object);
+        }
+        if (object instanceof ImageDatum) {
+            return DefaultImageDatum.castOrCopy((ImageDatum) object);
+        }
+        // Intentionally tested after the sub-interfaces.
+        if (object == null || object instanceof AbstractDatum) {
+            return (AbstractDatum) object;
+        }
+        return new AbstractDatum(object);
+    }
+}

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

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



Mime
View raw message