sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1555428 - in /sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs: AbstractCRS.java DefaultTemporalCRS.java DefaultVerticalCRS.java
Date Sat, 04 Jan 2014 22:44:40 GMT
Author: desruisseaux
Date: Sat Jan  4 22:44:40 2014
New Revision: 1555428

URL: http://svn.apache.org/r1555428
Log:
Minor refactoring: define the datum field in subclasses instead than in the AbstractCRS parent
class.

Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultTemporalCRS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java?rev=1555428&r1=1555427&r2=1555428&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
[UTF-8] Sat Jan  4 22:44:40 2014
@@ -93,21 +93,6 @@ public class AbstractCRS extends Abstrac
     private CoordinateSystem coordinateSystem;
 
     /**
-     * The datum, or {@code null} if none. This field shall be null for {@link DefaultCompoundCRS}
-     * and non-null for all other CRS types.
-     *
-     * {@note In OGC/ISO model, this property is defined in the <code>SingleCRS</code>
sub-type.
-     *        However Apache SIS does not define an <code>AbstractSingleCRS</code>
class in order
-     *        to simplify our class hierarchy, so we have to define this property here.}
-     *
-     * <p><b>Consider this field as final!</b>
-     * This field is modified only at unmarshalling time by {@link #setDatum(Datum)}</p>
-     *
-     * @see #getDatum()
-     */
-    private Datum datum;
-
-    /**
      * Constructs a new object in which every attributes are set to a null value.
      * <strong>This is not a valid object.</strong> This constructor is strictly
      * reserved to JAXB, which will assign values to the fields using reflexion.
@@ -170,22 +155,6 @@ public class AbstractCRS extends Abstrac
     }
 
     /**
-     * For subclasses that implement the {@link SingleCRS} interface. This constructor is
not public
-     * because this {@code AbstractCRS} class implements the {@code CoordinateReferenceSystem}
interface,
-     * not {@code SingleCRS}, and only the later has a datum attribute.
-     */
-    AbstractCRS(final Map<String,?> properties,
-                final Datum datum,
-                final CoordinateSystem cs)
-    {
-        super(properties);
-        ensureNonNull("datum", datum);
-        ensureNonNull("cs", cs);
-        this.datum = datum;
-        coordinateSystem = cs;
-    }
-
-    /**
      * Constructs a new coordinate 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.
@@ -215,13 +184,13 @@ public class AbstractCRS extends Abstrac
      * Returns the datum, or {@code null} if none.
      *
      * This property does not exist in {@code CoordinateReferenceSystem} interface — it
is defined in the
-     * {@link SingleCRS} sub-interface instead. But Apache SIS does not define an {@code
AbstractSingleCRS}
-     * class in order to simplify our class hierarchy, so we store the datum in this class
has a hidden property.
+     * {@link SingleCRS} sub-interface instead. But Apache SIS does not define an {@code
AbstractSingleCRS} class
+     * in order to simplify our class hierarchy, so we provide a datum getter in this class
has a hidden property.
      * Subclasses implementing {@code SingleCRS} (basically all SIS subclasses except {@link
DefaultCompoundCRS})
      * will override this method with public access and more specific return type.
      */
     Datum getDatum() {
-        return datum;
+        return null;
     }
 
     /**
@@ -235,22 +204,14 @@ public class AbstractCRS extends Abstrac
     }
 
     /**
-     * Sets the datum. This method is invoked only by JAXB at unmarshalling time
-     * and can be invoked only if the datum has never been set.
-     *
-     * @param  name The property name, used only in case of error message to format.
-     * @throws IllegalStateException If the datum has already been set.
-     */
-    final void setDatum(final String name, final Datum datum) {
-        if (datum != null && ReferencingUtilities.canSetProperty(name, this.datum
!= null)) {
-            this.datum = datum;
-        }
-    }
-
-    /**
      * Sets the coordinate system to the given value. This method is invoked only by JAXB
at
      * unmarshalling time and can be invoked only if the coordinate system has never been
set.
      *
+     * {@note It was easy to put JAXB annotations directly on datum fields in subclasses
because each CRS
+     *        type can be associated to only one datum type. But we do not have this convenience
for
+     *        coordinate systems, where the same CRS may accept more than one kind of CS.
+     *        In GML, the different kinds of CS are marshalled in different XML elements.}
+     *
      * @param  name The property name, used only in case of error message to format.
      * @throws IllegalStateException If the coordinate system has already been set.
      */
@@ -284,14 +245,15 @@ public class AbstractCRS extends Abstrac
     @Override
     public boolean equals(final Object object, final ComparisonMode mode) {
         if (super.equals(object, mode)) {
+            final Datum datum = getDatum();
             switch (mode) {
                 case STRICT: {
                     final AbstractCRS that = (AbstractCRS) object;
-                    return Objects.equals(datum, that.datum) &&
+                    return Objects.equals(datum, that.getDatum()) &&
                            Objects.equals(coordinateSystem, that.coordinateSystem);
                 }
                 default: {
-                    return deepEquals(getDatum(),
+                    return deepEquals(datum,
                                       (object instanceof SingleCRS) ? ((SingleCRS) object).getDatum()
: null, mode) &&
                            deepEquals(getCoordinateSystem(),
                                       ((CoordinateReferenceSystem) object).getCoordinateSystem(),
mode);
@@ -310,7 +272,7 @@ public class AbstractCRS extends Abstrac
      */
     @Override
     protected long computeHashCode() {
-        return super.computeHashCode() + Objects.hash(datum, coordinateSystem);
+        return super.computeHashCode() + Objects.hash(getDatum(), coordinateSystem);
     }
 
     /**
@@ -339,7 +301,7 @@ public class AbstractCRS extends Abstrac
      * For {@link DefaultEngineeringCRS} and {@link DefaultVerticalCRS} use only.
      */
     final void formatDefaultWKT(final Formatter formatter) {
-        formatter.append(datum);
+        formatter.append(getDatum());
         final Unit<?> unit = getUnit();
         formatter.append(unit);
         final int dimension = coordinateSystem.getDimension();

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultTemporalCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultTemporalCRS.java?rev=1555428&r1=1555427&r2=1555428&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultTemporalCRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultTemporalCRS.java
[UTF-8] Sat Jan  4 22:44:40 2014
@@ -29,6 +29,8 @@ import org.opengis.referencing.datum.Tem
 import org.apache.sis.referencing.AbstractReferenceSystem;
 import org.apache.sis.measure.Units;
 
+import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
+
 
 /**
  * A 1D coordinate reference system used for the recording of time.
@@ -36,7 +38,7 @@ import org.apache.sis.measure.Units;
  * <table class="sis">
  * <tr><th>Used with CS type(s)</th></tr>
  * <tr><td>
- *   {@link org.apache.sis.referencing.cs.DefaultTimeCS TimeCS}
+ *   {@linkplain org.apache.sis.referencing.cs.DefaultTimeCS Time CS}
  * </td></tr></table>
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
@@ -47,7 +49,10 @@ import org.apache.sis.measure.Units;
  * @see org.apache.sis.referencing.datum.DefaultTemporalDatum
  * @see org.apache.sis.referencing.cs.DefaultTimeCS
  */
-@XmlType(name = "TemporalCRSType")
+@XmlType(name = "TemporalCRSType", propOrder = {
+    "coordinateSystem",
+    "datum"
+})
 @XmlRootElement(name = "TemporalCRS")
 public class DefaultTemporalCRS extends AbstractCRS implements TemporalCRS {
     /**
@@ -56,6 +61,12 @@ public class DefaultTemporalCRS extends 
     private static final long serialVersionUID = 3000119849197222007L;
 
     /**
+     * The datum.
+     */
+    @XmlElement(name = "temporalDatum")
+    private final TemporalDatum datum;
+
+    /**
      * A converter from values in this CRS to values in milliseconds.
      * Will be constructed only when first needed.
      */
@@ -74,6 +85,7 @@ public class DefaultTemporalCRS extends 
      * reserved to JAXB, which will assign values to the fields using reflexion.
      */
     private DefaultTemporalCRS() {
+        datum = null;
     }
 
     /**
@@ -128,7 +140,9 @@ public class DefaultTemporalCRS extends 
                               final TemporalDatum datum,
                               final TimeCS        cs)
     {
-        super(properties, datum, cs);
+        super(properties, cs);
+        ensureNonNull("datum", datum);
+        this.datum = datum;
     }
 
     /**
@@ -144,6 +158,7 @@ public class DefaultTemporalCRS extends 
      */
     protected DefaultTemporalCRS(final TemporalCRS crs) {
         super(crs);
+        datum = crs.getDatum();
     }
 
     /**
@@ -180,44 +195,36 @@ public class DefaultTemporalCRS extends 
      * Initialize the fields required for {@link #toDate} and {@link #toValue} operations.
      */
     private void initializeConverter() {
-        origin   = getDatum().getOrigin().getTime();
+        origin   = datum.getOrigin().getTime();
         toMillis = getCoordinateSystem().getAxis(0).getUnit().asType(Duration.class).getConverterTo(Units.MILLISECOND);
     }
 
     /**
-     * Returns the coordinate system.
+     * Returns the datum.
      *
-     * @return The coordinate system.
+     * @return The datum.
      */
     @Override
-    @XmlElement(name = "timeCS")
-    public TimeCS getCoordinateSystem() {
-        return (TimeCS) super.getCoordinateSystem();
+    public final TemporalDatum getDatum() {
+        return datum;
     }
 
     /**
-     * Used by JAXB only (invoked by reflection).
-     */
-    final void setCoordinateSystem(final TimeCS cs) {
-        super.setCoordinateSystem("timeCS", cs);
-    }
-
-    /**
-     * Returns the datum.
+     * Returns the coordinate system.
      *
-     * @return The datum.
+     * @return The coordinate system.
      */
     @Override
-    @XmlElement(name = "temporalDatum")
-    public TemporalDatum getDatum() {
-        return (TemporalDatum) super.getDatum();
+    @XmlElement(name = "timeCS")
+    public TimeCS getCoordinateSystem() {
+        return (TimeCS) super.getCoordinateSystem();
     }
 
     /**
      * Used by JAXB only (invoked by reflection).
      */
-    final void setDatum(final TemporalDatum datum) {
-        super.setDatum("temporalDatum", datum);
+    private void setCoordinateSystem(final TimeCS cs) {
+        super.setCoordinateSystem("timeCS", cs);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java?rev=1555428&r1=1555427&r2=1555428&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java
[UTF-8] Sat Jan  4 22:44:40 2014
@@ -26,6 +26,8 @@ import org.opengis.referencing.datum.Ver
 import org.apache.sis.referencing.AbstractReferenceSystem;
 import org.apache.sis.io.wkt.Formatter;
 
+import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
+
 
 /**
  * A 1D coordinate reference system used for recording heights or depths.
@@ -35,7 +37,7 @@ import org.apache.sis.io.wkt.Formatter;
  * <table class="sis">
  * <tr><th>Used with CS type(s)</th></tr>
  * <tr><td>
- *   {@link org.apache.sis.referencing.cs.DefaultVerticalCS VerticalCS}
+ *   {@linkplain org.apache.sis.referencing.cs.DefaultVerticalCS Vertical CS}
  * </td></tr></table>
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
@@ -46,7 +48,10 @@ import org.apache.sis.io.wkt.Formatter;
  * @see org.apache.sis.referencing.datum.DefaultVerticalDatum
  * @see org.apache.sis.referencing.cs.DefaultVerticalCS
  */
-@XmlType(name = "VerticalCRSType")
+@XmlType(name = "VerticalCRSType", propOrder = {
+    "coordinateSystem",
+    "datum"
+})
 @XmlRootElement(name = "VerticalCRS")
 public class DefaultVerticalCRS extends AbstractCRS implements VerticalCRS {
     /**
@@ -55,11 +60,18 @@ public class DefaultVerticalCRS extends 
     private static final long serialVersionUID = 3565878468719941800L;
 
     /**
+     * The datum.
+     */
+    @XmlElement(name = "verticalDatum")
+    private final VerticalDatum datum;
+
+    /**
      * Constructs a new object in which every attributes are set to a null value.
      * <strong>This is not a valid object.</strong> This constructor is strictly
      * reserved to JAXB, which will assign values to the fields using reflexion.
      */
     private DefaultVerticalCRS() {
+        datum = null;
     }
 
     /**
@@ -114,7 +126,9 @@ public class DefaultVerticalCRS extends 
                               final VerticalDatum datum,
                               final VerticalCS    cs)
     {
-        super(properties, datum, cs);
+        super(properties, cs);
+        ensureNonNull("datum", datum);
+        this.datum = datum;
     }
 
     /**
@@ -130,6 +144,7 @@ public class DefaultVerticalCRS extends 
      */
     protected DefaultVerticalCRS(final VerticalCRS crs) {
         super(crs);
+        datum = crs.getDatum();
     }
 
     /**
@@ -163,6 +178,16 @@ public class DefaultVerticalCRS extends 
     }
 
     /**
+     * Returns the datum.
+     *
+     * @return The datum.
+     */
+    @Override
+    public final VerticalDatum getDatum() {
+        return datum;
+    }
+
+    /**
      * Returns the coordinate system.
      *
      * @return The coordinate system.
@@ -181,24 +206,6 @@ public class DefaultVerticalCRS extends 
     }
 
     /**
-     * Returns the datum.
-     *
-     * @return The datum.
-     */
-    @Override
-    @XmlElement(name = "verticalDatum")
-    public VerticalDatum getDatum() {
-        return (VerticalDatum) super.getDatum();
-    }
-
-    /**
-     * Used by JAXB only (invoked by reflection).
-     */
-    private void setDatum(final VerticalDatum datum) {
-        super.setDatum("verticalDatum", datum);
-    }
-
-    /**
      * Formats the inner part of a <cite>Well Known Text</cite> (WKT)</a>
element.
      *
      * @param  formatter The formatter to use.



Mime
View raw message