Author: desruisseaux
Date: Wed Jan 15 15:56:01 2014
New Revision: 1558446

URL: http://svn.apache.org/r1558446
Log:
Initial support of AbstractCRS.forConvention(...).

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/DefaultEngineeringCRS.java
    
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
    
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
    
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
    
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultImageCRS.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
    
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.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=1558446&r1=1558445&r2=1558446&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] Wed Jan 15 15:56:01 2014
@@ -17,6 +17,7 @@
 package org.apache.sis.referencing.crs;
 
 import java.util.Map;
+import java.util.EnumMap;
 import javax.measure.unit.Unit;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlRootElement;
@@ -29,6 +30,8 @@ import org.opengis.referencing.crs.Singl
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.apache.sis.internal.referencing.ReferencingUtilities;
 import org.apache.sis.referencing.AbstractReferenceSystem;
+import org.apache.sis.referencing.IdentifiedObjects;
+import org.apache.sis.referencing.cs.AxesConvention;
 import org.apache.sis.referencing.cs.AbstractCS;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.io.wkt.Formatter;
@@ -91,13 +94,21 @@ public class AbstractCRS extends Abstrac
      * The coordinate system.
      *
      * <p><b>Consider this field as final!</b>
-     * This field is modified only at unmarshalling time by {@link 
#setCoordinateSystem(CoordinateSystem)}</p>
+     * This field is modified only at unmarshalling time by {@link 
#setCoordinateSystem(String, CoordinateSystem)}</p>
      *
      * @see #getCoordinateSystem()
      */
     private CoordinateSystem coordinateSystem;
 
     /**
+     * Other coordinate systems derived from this coordinate systems for other 
axes conventions.
+     * Created only when first needed.
+     *
+     * @see #forConvention(AxesConvention)
+     */
+    private transient Map<AxesConvention,AbstractCRS> derived;
+
+    /**
      * 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.
@@ -243,8 +254,50 @@ public class AbstractCRS extends Abstrac
     }
 
     /**
+     * Returns a coordinate reference system equivalent to this one but with 
axes rearranged according the given
+     * convention. If this CRS is already compatible with the given 
convention, then this method returns {@code this}.
+     *
+     * @param  convention The axes convention for which a coordinate reference 
system is desired.
+     * @return A coordinate reference system compatible with the given 
convention (may be {@code this}).
+     *
+     * @see AbstractCS#forConvention(AxesConvention)
+     */
+    public synchronized AbstractCRS forConvention(final AxesConvention 
convention) {
+        ensureNonNull("convention", convention);
+        if (derived == null) {
+            derived = new EnumMap<>(AxesConvention.class);
+        }
+        AbstractCRS crs = derived.get(convention);
+        if (crs == null) {
+            final AbstractCS cs = AbstractCS.castOrCopy(coordinateSystem);
+            final AbstractCS candidate = cs.forConvention(convention);
+            if (candidate == cs) {
+                crs = this;
+            } else {
+                crs = createSameType(IdentifiedObjects.getProperties(this, 
IDENTIFIERS_KEY), candidate);
+                for (final AbstractCRS existing : derived.values()) {
+                    if (crs.equals(existing)) {
+                        crs = existing;
+                        break;
+                    }
+                }
+            }
+            derived.put(convention, crs);
+        }
+        return crs;
+    }
+
+    /**
+     * Returns a coordinate reference system of the same type than this CRS 
but with different axes.
+     * This method shall be overridden by all {@code AbstractCRS} subclasses 
in this package.
+     */
+    AbstractCRS createSameType(final Map<String,?> properties, final 
CoordinateSystem cs) {
+        return new AbstractCRS(properties, cs);
+    }
+
+    /**
      * Returns the unit used for all axis, or {@code null} if not all axis 
uses the same unit.
-     * This method is often used for formatting according  Well Know Text 
(WKT) version 1.
+     * This method is often used for formatting according  Well Known Text 
(WKT) version 1.
      */
     final Unit<?> getUnit() {
         return ReferencingUtilities.getUnit(coordinateSystem);

Modified: 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java?rev=1558446&r1=1558445&r2=1558446&view=diff
==============================================================================
--- 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java
 [UTF-8] (original)
+++ 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java
 [UTF-8] Wed Jan 15 15:56:01 2014
@@ -233,6 +233,14 @@ public class DefaultEngineeringCRS exten
     private void setUserDefinedCS(final UserDefinedCS cs) 
{super.setCoordinateSystem("userDefinedCS", cs);}
 
     /**
+     * Returns a coordinate reference system of the same type than this CRS 
but with different axes.
+     */
+    @Override
+    final AbstractCRS createSameType(final Map<String,?> properties, final 
CoordinateSystem cs) {
+        return new DefaultEngineeringCRS(properties, datum, cs);
+    }
+
+    /**
      * Formats the inner part of a <cite>Well Known Text</cite> (WKT)</a> 
element.
      *
      * @param  formatter The formatter to use.

Modified: 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java?rev=1558446&r1=1558445&r2=1558446&view=diff
==============================================================================
--- 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
 [UTF-8] (original)
+++ 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
 [UTF-8] Wed Jan 15 15:56:01 2014
@@ -64,6 +64,17 @@ public class DefaultGeocentricCRS extend
     }
 
     /**
+     * For {@link #createSameType(Map, CoordinateSystem)} usage only.
+     * This constructor does not verify the coordinate system type.
+     */
+    private DefaultGeocentricCRS(final Map<String,?>    properties,
+                                 final GeodeticDatum    datum,
+                                 final CoordinateSystem cs)
+    {
+        super(properties, datum, cs);
+    }
+
+    /**
      * Creates a coordinate reference system from the given properties, datum 
and coordinate system.
      * The properties given in argument follow the same rules than for the
      * {@linkplain AbstractReferenceSystem#AbstractReferenceSystem(Map) 
super-class constructor}.
@@ -180,6 +191,14 @@ public class DefaultGeocentricCRS extend
     }
 
     /**
+     * Returns a coordinate reference system of the same type than this CRS 
but with different axes.
+     */
+    @Override
+    final AbstractCRS createSameType(final Map<String,?> properties, final 
CoordinateSystem cs) {
+        return new DefaultGeocentricCRS(properties, super.getDatum(), cs);
+    }
+
+    /**
      * Formats the inner part of a <cite>Well Known Text</cite> (WKT)</a> 
element.
      *
      * @param  formatter The formatter to use.

Modified: 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java?rev=1558446&r1=1558445&r2=1558446&view=diff
==============================================================================
--- 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
 [UTF-8] (original)
+++ 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
 [UTF-8] Wed Jan 15 15:56:01 2014
@@ -144,4 +144,13 @@ class DefaultGeodeticCRS extends Abstrac
     private void setCartesianCS  (final CartesianCS   cs) 
{super.setCoordinateSystem("cartesianCS",   cs);}
     private void setSphericalCS  (final SphericalCS   cs) 
{super.setCoordinateSystem("sphericalCS",   cs);}
     private void setEllipsoidalCS(final EllipsoidalCS cs) 
{super.setCoordinateSystem("ellipsoidalCS", cs);}
+
+    /**
+     * Returns a coordinate reference system of the same type than this CRS 
but with different axes.
+     * This method shall be overridden by all {@code DefaultGeodeticCRS} 
subclasses in this package.
+     */
+    @Override
+    AbstractCRS createSameType(final Map<String,?> properties, final 
CoordinateSystem cs) {
+        return new DefaultGeodeticCRS(properties, datum, cs);
+    }
 }

Modified: 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java?rev=1558446&r1=1558445&r2=1558446&view=diff
==============================================================================
--- 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
 [UTF-8] (original)
+++ 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
 [UTF-8] Wed Jan 15 15:56:01 2014
@@ -178,6 +178,14 @@ public class DefaultGeographicCRS extend
     }
 
     /**
+     * Returns a coordinate reference system of the same type than this CRS 
but with different axes.
+     */
+    @Override
+    final AbstractCRS createSameType(final Map<String,?> properties, final 
CoordinateSystem cs) {
+        return new DefaultGeographicCRS(properties, super.getDatum(), 
(EllipsoidalCS) cs);
+    }
+
+    /**
      * Returns the angular unit of the specified coordinate system.
      * The preference will be given to the longitude axis, if found.
      */

Modified: 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultImageCRS.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultImageCRS.java?rev=1558446&r1=1558445&r2=1558446&view=diff
==============================================================================
--- 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultImageCRS.java
 [UTF-8] (original)
+++ 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultImageCRS.java
 [UTF-8] Wed Jan 15 15:56:01 2014
@@ -20,6 +20,7 @@ import java.util.Map;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
+import org.opengis.referencing.cs.CoordinateSystem;
 import org.opengis.referencing.cs.AffineCS;
 import org.opengis.referencing.crs.ImageCRS;
 import org.opengis.referencing.cs.CartesianCS;
@@ -230,4 +231,12 @@ public class DefaultImageCRS extends Abs
     private void setCartesianCS(final CartesianCS cs) {
         super.setCoordinateSystem("cartesianCS", cs);
     }
+
+    /**
+     * Returns a coordinate reference system of the same type than this CRS 
but with different axes.
+     */
+    @Override
+    final AbstractCRS createSameType(final Map<String,?> properties, final 
CoordinateSystem cs) {
+        return new DefaultImageCRS(properties, datum, (AffineCS) cs);
+    }
 }

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=1558446&r1=1558445&r2=1558446&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] Wed Jan 15 15:56:01 2014
@@ -23,6 +23,7 @@ import javax.xml.bind.annotation.XmlElem
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.measure.quantity.Duration;
 import javax.measure.converter.UnitConverter;
+import org.opengis.referencing.cs.CoordinateSystem;
 import org.opengis.referencing.cs.TimeCS;
 import org.opengis.referencing.crs.TemporalCRS;
 import org.opengis.referencing.datum.TemporalDatum;
@@ -237,6 +238,14 @@ public class DefaultTemporalCRS extends 
     }
 
     /**
+     * Returns a coordinate reference system of the same type than this CRS 
but with different axes.
+     */
+    @Override
+    final AbstractCRS createSameType(final Map<String,?> properties, final 
CoordinateSystem cs) {
+        return new DefaultTemporalCRS(properties, datum, (TimeCS) cs);
+    }
+
+    /**
      * Convert the given value into a {@link Date} object.
      * If the given value is {@link Double#NaN NaN} or infinite, then this 
method returns {@code null}.
      *

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=1558446&r1=1558445&r2=1558446&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] Wed Jan 15 15:56:01 2014
@@ -20,6 +20,7 @@ import java.util.Map;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
+import org.opengis.referencing.cs.CoordinateSystem;
 import org.opengis.referencing.cs.VerticalCS;
 import org.opengis.referencing.crs.VerticalCRS;
 import org.opengis.referencing.datum.VerticalDatum;
@@ -209,6 +210,14 @@ public class DefaultVerticalCRS extends 
     }
 
     /**
+     * Returns a coordinate reference system of the same type than this CRS 
but with different axes.
+     */
+    @Override
+    final AbstractCRS createSameType(final Map<String,?> properties, final 
CoordinateSystem cs) {
+        return new DefaultVerticalCRS(properties, datum, (VerticalCS) cs);
+    }
+
+    /**
      * Formats the inner part of a <cite>Well Known Text</cite> (WKT)</a> 
element.
      *
      * @param  formatter The formatter to use.

Modified: 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java?rev=1558446&r1=1558445&r2=1558446&view=diff
==============================================================================
--- 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
 [UTF-8] (original)
+++ 
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
 [UTF-8] Wed Jan 15 15:56:01 2014
@@ -327,6 +327,8 @@ public class AbstractCS extends Abstract
      *
      * @param  convention The axes convention for which a coordinate system is 
desired.
      * @return A coordinate system compatible with the given convention (may 
be {@code this}).
+     *
+     * @see 
org.apache.sis.referencing.crs.AbstractCRS#forConvention(AxesConvention)
      */
     public synchronized AbstractCS forConvention(final AxesConvention 
convention) {
         ensureNonNull("convention", convention);
@@ -353,7 +355,7 @@ public class AbstractCS extends Abstract
     }
 
     /**
-     * Returns a coordinate system of the same this than this CS but with 
different axes.
+     * Returns a coordinate system of the same type than this CS but with 
different axes.
      * This method shall be overridden by all {@code AbstractCS} subclasses in 
this package.
      */
     AbstractCS createSameType(final Map<String,?> properties, final 
CoordinateSystemAxis[] axes) {


Reply via email to