Author: desruisseaux
Date: Wed Jan 15 21:52:55 2014
New Revision: 1558577
URL: http://svn.apache.org/r1558577
Log:
Implemented DefaultCompoundCRS.forConvention(...).
Added:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/SubTypes.java
- copied, changed from r1558164, sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/SubTypes.java
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/DefaultCompoundCRS.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.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=1558577&r1=1558576&r2=1558577&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 21:52:55 2014
@@ -178,6 +178,8 @@ public class AbstractCRS extends Abstrac
*
This constructor performs a shallow copy, i.e. the properties are not cloned.
*
* @param crs The coordinate reference system to copy.
+ *
+ * @see #castOrCopy(CoordinateReferenceSystem)
*/
protected AbstractCRS(final CoordinateReferenceSystem crs) {
super(crs);
@@ -185,6 +187,40 @@ public class AbstractCRS extends Abstrac
}
/**
+ * Returns a SIS coordinate reference system implementation with the values of the given arbitrary implementation.
+ * This method performs the first applicable actions in the following choices:
+ *
+ *
+ *
If the given object is {@code null}, then this method returns {@code null}.
+ *
Otherwise if the given object is is an instance of
+ * {@link org.opengis.referencing.crs.GeodeticCRS} (including the
+ * {@link org.opengis.referencing.crs.GeographicCRS} and
+ * {@link org.opengis.referencing.crs.GeocentricCRS} subtypes),
+ * {@link org.opengis.referencing.crs.VerticalCRS},
+ * {@link org.opengis.referencing.crs.TemporalCRS},
+ * {@link org.opengis.referencing.crs.EngineeringCRS},
+ * {@link org.opengis.referencing.crs.ImageCRS} or
+ * {@link org.opengis.referencing.cs.CompoundCRS},
+ * 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.
+ *
Otherwise if the given object is already an instance of
+ * {@code AbstractCRS}, then it is returned unchanged.
+ *
Otherwise a new {@code AbstractCRS} instance is created using the
+ * {@linkplain #AbstractCRS(CoordinateReferenceSystem) copy constructor}
+ * and returned. Note that this is a shallow copy operation, since the other
+ * properties contained in the given object are not recursively copied.
+ *
+ *
+ * @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 AbstractCRS castOrCopy(final CoordinateReferenceSystem object) {
+ return SubTypes.castOrCopy(object);
+ }
+
+ /**
* Returns the GeoAPI interface implemented by this class.
* The default implementation returns {@code CoordinateReferenceSystem.class}.
* Subclasses implementing a more specific GeoAPI interface shall override this method.
@@ -254,6 +290,18 @@ public class AbstractCRS extends Abstrac
}
/**
+ * Returns the map of cached CRS for axes conventions.
+ * This method shall be invoked in a synchronized block.
+ */
+ final Map derived() {
+ assert Thread.holdsLock(this);
+ if (derived == null) {
+ derived = new EnumMap<>(AxesConvention.class);
+ }
+ return derived;
+ }
+
+ /**
* 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}.
*
@@ -264,9 +312,7 @@ public class AbstractCRS extends Abstrac
*/
public synchronized AbstractCRS forConvention(final AxesConvention convention) {
ensureNonNull("convention", convention);
- if (derived == null) {
- derived = new EnumMap<>(AxesConvention.class);
- }
+ final Map derived = derived();
AbstractCRS crs = derived.get(convention);
if (crs == null) {
final AbstractCS cs = AbstractCS.castOrCopy(coordinateSystem);
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java?rev=1558577&r1=1558576&r2=1558577&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java [UTF-8] Wed Jan 15 21:52:55 2014
@@ -28,8 +28,10 @@ import org.opengis.referencing.crs.Singl
import org.opengis.referencing.crs.CompoundCRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.cs.CoordinateSystem;
+import org.apache.sis.referencing.cs.AxesConvention;
import org.apache.sis.referencing.cs.DefaultCompoundCS;
import org.apache.sis.referencing.AbstractReferenceSystem;
+import org.apache.sis.referencing.IdentifiedObjects;
import org.apache.sis.internal.referencing.ReferencingUtilities;
import org.apache.sis.internal.util.UnmodifiableArrayList;
import org.apache.sis.util.collection.CheckedContainer;
@@ -306,6 +308,38 @@ public class DefaultCompoundCRS extends
}
/**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public synchronized DefaultCompoundCRS forConvention(final AxesConvention convention) {
+ ensureNonNull("convention", convention);
+ final Map derived = derived();
+ DefaultCompoundCRS crs = (DefaultCompoundCRS) derived.get(convention);
+ if (crs == null) {
+ crs = this;
+ boolean changed = false;
+ final CoordinateReferenceSystem[] components = new CoordinateReferenceSystem[singles.size()];
+ for (int i=0; iThis class currently provides implementation for the following methods:
*