sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1683594 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/internal/metadata/ sis-referencing/src/main/java/org/apache/sis/internal/referencing/ sis-referencing/src/main/java/org/apache/sis/io/wkt/ sis-referencing/src/...
Date Thu, 04 Jun 2015 16:58:33 GMT
Author: desruisseaux
Date: Thu Jun  4 16:58:33 2015
New Revision: 1683594

URL: http://svn.apache.org/r1683594
Log:
Referencing: avoid direct dependencies to BursaWolfParameters and CoordinateSystems (from
sis-referencing module) in GeodeticObjectParser.
This is part of the effort to make SIS compliant with OSGi.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java?rev=1683594&r1=1683593&r2=1683594&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] Thu Jun  4 16:58:33 2015
@@ -17,12 +17,15 @@
 package org.apache.sis.internal.metadata;
 
 import java.util.Map;
+import javax.measure.unit.Unit;
+import javax.measure.quantity.Length;
 import org.opengis.geometry.Envelope;
 import org.opengis.metadata.Identifier;
 import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.crs.SingleCRS;
 import org.opengis.referencing.crs.DerivedCRS;
+import org.opengis.referencing.cs.CartesianCS;
 import org.opengis.referencing.cs.CoordinateSystem;
 import org.opengis.referencing.cs.CoordinateSystemAxis;
 import org.opengis.referencing.operation.MathTransform;
@@ -71,6 +74,11 @@ public class ReferencingServices extends
     public static final double AUTHALIC_RADIUS = 6371007;
 
     /**
+     * The {@link org.apache.sis.referencing.datum.DefaultGeodeticDatum#BURSA_WOLF_KEY} value.
+     */
+    public static final String BURSA_WOLF_KEY = "bursaWolf";
+
+    /**
      * The key for specifying explicitely the value to be returned by
      * {@link org.apache.sis.referencing.operation.DefaultConversion#getParameterValues()}.
      * It is usually not necessary to specify those parameters because they are inferred
either from
@@ -389,6 +397,16 @@ public class ReferencingServices extends
     }
 
     /**
+     * Returns the coordinate system of a geocentric CRS using axes in the given unit of
measurement.
+     *
+     * @param  unit The unit of measurement for the geocentric CRS axes.
+     * @return The coordinate system for a geocentric CRS with axes using the given unit
of measurement.
+     */
+    public CartesianCS getGeocentricCS(final Unit<Length> unit) {
+        throw referencingModuleNotFound();
+    }
+
+    /**
      * Creates a coordinate system of unknown type. This method is used during parsing of
WKT version 1,
      * since that legacy format did not specified any information about the coordinate system
in use.
      * This method should not need to be invoked for parsing WKT version 2.
@@ -421,4 +439,15 @@ public class ReferencingServices extends
     {
         throw referencingModuleNotFound();
     }
+
+    /**
+     * Creates the {@code TOWGS84} element during parsing of a WKT version 1. This is an
optional operation:
+     * this method is allowed to return {@code null} if the "sis-referencing" module is not
in the classpath.
+     *
+     * @param  values The 7 Bursa-Wolf parameter values.
+     * @return The {@link org.apache.sis.referencing.datum.BursaWolfParameters}, or {@code
null}.
+     */
+    public Object createToWGS84(final double[] values) {
+        return null;
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java?rev=1683594&r1=1683593&r2=1683594&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
[UTF-8] Thu Jun  4 16:58:33 2015
@@ -20,6 +20,9 @@ import java.util.Map;
 import java.util.Iterator;
 import java.util.Collection;
 import java.util.Collections;
+import javax.measure.unit.SI;
+import javax.measure.unit.Unit;
+import javax.measure.quantity.Length;
 
 import org.opengis.util.FactoryException;
 import org.opengis.parameter.ParameterDescriptor;
@@ -31,6 +34,7 @@ import org.opengis.referencing.crs.Tempo
 import org.opengis.referencing.crs.VerticalCRS;
 import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.cs.CartesianCS;
 import org.opengis.referencing.cs.CoordinateSystem;
 import org.opengis.referencing.cs.CoordinateSystemAxis;
 import org.opengis.referencing.operation.Matrix;
@@ -51,8 +55,11 @@ import org.apache.sis.referencing.Common
 import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.referencing.AbstractIdentifiedObject;
 import org.apache.sis.referencing.cs.AbstractCS;
+import org.apache.sis.referencing.cs.AxisFilter;
+import org.apache.sis.referencing.cs.CoordinateSystems;
 import org.apache.sis.referencing.crs.DefaultDerivedCRS;
 import org.apache.sis.referencing.crs.DefaultTemporalCRS;
+import org.apache.sis.referencing.datum.BursaWolfParameters;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
 import org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory;
 import org.apache.sis.parameter.DefaultParameterDescriptor;
@@ -444,6 +451,25 @@ public final class ServicesForMetadata e
     }
 
     /**
+     * Returns the coordinate system of a geocentric CRS using axes in the given unit of
measurement.
+     *
+     * @param  unit The unit of measurement for the geocentric CRS axes.
+     * @return The coordinate system for a geocentric CRS with axes using the given unit
of measurement.
+     */
+    @Override
+    public CartesianCS getGeocentricCS(final Unit<Length> unit) {
+        CartesianCS cs = (CartesianCS) CommonCRS.WGS84.geocentric().getCoordinateSystem();
+        if (!SI.METRE.equals(unit)) {
+            cs = (CartesianCS) CoordinateSystems.replaceAxes(cs, new AxisFilter() {
+                @Override public Unit<?> getUnitReplacement(final Unit<?> unit)
{
+                    return unit;
+                }
+            });
+        }
+        return cs;
+    }
+
+    /**
      * Creates a coordinate system of unknown type. This method is used during parsing of
WKT version 1,
      * since that legacy format did not specified any information about the coordinate system
in use.
      * This method should not need to be invoked for parsing WKT version 2.
@@ -479,4 +505,17 @@ public final class ServicesForMetadata e
     {
         return DefaultDerivedCRS.create(properties, baseCRS, null, method, baseToDerived,
derivedCS);
     }
+
+    /**
+     * Creates the {@code TOWGS84} element during parsing of a WKT version 1.
+     *
+     * @param  values The 7 Bursa-Wolf parameter values.
+     * @return The {@link BursaWolfParameters}.
+     */
+    @Override
+    public Object createToWGS84(final double[] values) {
+        final BursaWolfParameters info = new BursaWolfParameters(CommonCRS.WGS84.datum(),
null);
+        info.setValues(values);
+        return info;
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java?rev=1683594&r1=1683593&r2=1683594&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
[UTF-8] Thu Jun  4 16:58:33 2015
@@ -49,9 +49,6 @@ import org.opengis.referencing.operation
 
 import org.apache.sis.measure.Units;
 import org.apache.sis.referencing.CommonCRS;
-import org.apache.sis.referencing.cs.AxisFilter;
-import org.apache.sis.referencing.cs.CoordinateSystems;
-import org.apache.sis.referencing.datum.BursaWolfParameters;
 import org.apache.sis.metadata.iso.ImmutableIdentifier;
 import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.internal.metadata.WKTKeywords;
@@ -64,7 +61,6 @@ import org.apache.sis.util.resources.Err
 import org.apache.sis.util.iso.Types;
 
 import static java.util.Collections.singletonMap;
-import static org.apache.sis.referencing.datum.DefaultGeodeticDatum.BURSA_WOLF_KEY;
 
 
 /**
@@ -96,6 +92,11 @@ import static org.apache.sis.referencing
  */
 final class GeodeticObjectParser extends MathTransformParser {
     /**
+     * The name of the 7 parameters in a {@code TOWGS84[…]} element.
+     */
+    private static final String[] ToWGS84 = {"dx", "dy", "dz", "ex", "ey", "ez", "ppm"};
+
+    /**
      * The factory to use for creating {@link CoordinateReferenceSystem} instances.
      */
     private final CRSFactory crsFactory;
@@ -465,27 +466,24 @@ final class GeodeticObjectParser extends
      * }
      *
      * @param  parent The parent element.
-     * @return The {@code "TOWGS84"} element as a {@link BursaWolfParameters} object,
+     * @return The {@code "TOWGS84"} element as a {@link org.apache.sis.referencing.datum.BursaWolfParameters}
object,
      *         or {@code null} if no {@code "TOWGS84"} has been found.
      * @throws ParseException if the {@code "TOWGS84"} can not be parsed.
      */
-    private BursaWolfParameters parseToWGS84(final Element parent) throws ParseException
{
+    private Object parseToWGS84(final Element parent) throws ParseException {
         final Element element = parent.pullOptionalElement(WKTKeywords.ToWGS84);
         if (element == null) {
             return null;
         }
-        final BursaWolfParameters info = new BursaWolfParameters(CommonCRS.WGS84.datum(),
null);
-        info.tX = element.pullDouble("dx");
-        info.tY = element.pullDouble("dy");
-        info.tZ = element.pullDouble("dz");
-        if (element.peek() != null) {
-            info.rX = element.pullDouble("ex");
-            info.rY = element.pullDouble("ey");
-            info.rZ = element.pullDouble("ez");
-            info.dS = element.pullDouble("ppm");
+        final double[] values = new double[ToWGS84.length];
+        for (int i=0; i<values.length;) {
+            values[i] = element.pullDouble(ToWGS84[i]);
+            if ((++i % 3) == 0 && element.peek() == null) {
+                break;  // It is legal to have only 3 or 6 elements.
+            }
         }
         element.close(ignoredElements);
-        return info;
+        return referencing.createToWGS84(values);
     }
 
     /**
@@ -565,10 +563,10 @@ final class GeodeticObjectParser extends
         final Element             element    = parent.pullElement(WKTKeywords.Datum);
         final String              name       = element.pullString("name");
         final Ellipsoid           ellipsoid  = parseSpheroid(element);
-        final BursaWolfParameters toWGS84    = parseToWGS84(element);     // Optional; may
be null.
+        final Object              toWGS84    = parseToWGS84(element);     // Optional; may
be null.
         final Map<String,Object>  properties = parseAuthorityAndClose(element, name);
         if (toWGS84 != null) {
-            properties.put(BURSA_WOLF_KEY, toWGS84);
+            properties.put(ReferencingServices.BURSA_WOLF_KEY, toWGS84);
         }
         try {
             return datumFactory.createGeodeticDatum(properties, ellipsoid, meridian);
@@ -716,14 +714,7 @@ final class GeodeticObjectParser extends
                 cs = csFactory.createCartesianCS(properties, axis0, axis1, axis2);
                 cs = Legacy.forGeocentricCRS(cs, false);
             } else {
-                cs = (CartesianCS) CommonCRS.WGS84.geocentric().getCoordinateSystem();
-                if (!SI.METRE.equals(linearUnit)) {
-                    cs = (CartesianCS) CoordinateSystems.replaceAxes(cs, new AxisFilter()
{
-                        @Override public Unit<?> getUnitReplacement(final Unit<?>
unit) {
-                            return linearUnit;
-                        }
-                    });
-                }
+                cs = referencing.getGeocentricCS(linearUnit);
             }
             return crsFactory.createGeocentricCRS(properties, datum, cs);
         } catch (FactoryException exception) {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java?rev=1683594&r1=1683593&r2=1683594&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java
[UTF-8] Thu Jun  4 16:58:33 2015
@@ -27,7 +27,6 @@ import org.apache.sis.referencing.operat
 import org.apache.sis.io.wkt.FormattableObject;
 import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.util.resources.Errors;
-import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.internal.util.DoubleDouble;
 import org.apache.sis.internal.metadata.WKTKeywords;
 import org.apache.sis.referencing.IdentifiedObjects;
@@ -124,7 +123,7 @@ import java.util.Objects;
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.6
  * @module
  *
  * @see DefaultGeodeticDatum#getBursaWolfParameters()
@@ -226,7 +225,7 @@ public class BursaWolfParameters extends
     }
 
     /**
-     * Verifies parameters validity after initialization.
+     * Verifies parameters validity after initialization of {@link DefaultGeodeticDatum}.
      */
     void verify() {
         ensureFinite("tX", tX);
@@ -252,6 +251,70 @@ public class BursaWolfParameters extends
     }
 
     /**
+     * Returns the parameter values. The length of the returned array depends on the values:
+     *
+     * <ul>
+     *   <li>If this instance is an {@link TimeDependentBWP}, then the array length
will be 14.</li>
+     *   <li>Otherwise if this instance contains a non-zero {@link #dS} value, then
the array length will be 7 with
+     *       {@link #tX}, {@link #tY}, {@link #tZ}, {@link #rX}, {@link #rY}, {@link #rZ}
and {@link #dS} values
+     *       in that order.</li>
+     *   <li>Otherwise if this instance contains non-zero rotation terms,
+     *       then this method returns the first 6 of the above-cited values.</li>
+     *   <li>Otherwise (i.e. this instance {@linkplain #isTranslation() is a translation}),
+     *       this method returns only the first 3 of the above-cited values.</li>
+     * </ul>
+     *
+     * @return The parameter values as an array of length 3, 6, 7 or 14.
+     *
+     * @since 0.6
+     */
+    @SuppressWarnings("fallthrough")
+    public double[] getValues() {
+        final double[] elements = new double[(dS != 0) ? 7 : (rZ != 0 || rY != 0 || rX !=
0) ? 6 : 3];
+        switch (elements.length) {
+            default: elements[6] = dS;  // Fallthrough everywhere.
+            case 6:  elements[5] = rZ;
+                     elements[4] = rY;
+                     elements[3] = rX;
+            case 3:  elements[2] = tZ;
+                     elements[1] = tY;
+                     elements[0] = tX;
+        }
+        return elements;
+    }
+
+    /**
+     * Sets the parameters to the given values. The given array can have any length. The
first array elements will be
+     * assigned to the {@link #tX}, {@link #tY}, {@link #tZ}, {@link #rX}, {@link #rY}, {@link
#rZ} and {@link #dS}
+     * fields in that order.
+     *
+     * <ul>
+     *   <li>If the length of the given array is not sufficient for assigning a value
to every fields,
+     *       then the remaining fields are left unchanged (they are <strong>not</strong>
reset to zero,
+     *       but this is not a problem if this {@code BursaWolfParameters} is a new instance).</li>
+     *   <li>If the length of the given array is greater than necessary, then extra
elements are ignored by this base
+     *       class. Note however that those extra elements may be used by subclasses like
{@link TimeDependentBWP}.</li>
+     * </ul>
+     *
+     * @param elements The new parameter values, as an array of any length.
+     *
+     * @since 0.6
+     */
+    @SuppressWarnings("fallthrough")
+    public void setValues(final double... elements) {
+        switch (elements.length) {
+            default: dS = elements[6];  // Fallthrough everywhere.
+            case 6:  rZ = elements[5];
+            case 5:  rY = elements[4];
+            case 4:  rX = elements[3];
+            case 3:  tZ = elements[2];
+            case 2:  tY = elements[1];
+            case 1:  tX = elements[0];
+            case 0:  break;
+         }
+    }
+
+    /**
      * Returns {@code true} if the {@linkplain #targetDatum target datum} is equals (at least
on computation purpose)
      * to the WGS84 datum. If the datum is unspecified, then this method returns {@code true}
since WGS84 is the only
      * datum supported by the WKT 1 format, and is what users often mean.
@@ -302,13 +365,11 @@ public class BursaWolfParameters extends
      * because the parameter values are very small (parts per millions and arc-seconds).
      */
     public void invert() {
-        tX = -tX;
-        tY = -tY;
-        tZ = -tZ;
-        rX = -rX;
-        rY = -rY;
-        rZ = -rZ;
-        dS = -dS;
+        final double[] values = getValues();
+        for (int i=0; i<values.length; i++) {
+            values[i] = -values[i];
+        }
+        setValues(values);
     }
 
     /**
@@ -556,15 +617,9 @@ public class BursaWolfParameters extends
     public boolean equals(final Object object) {
         if (object != null && object.getClass() == getClass()) {
             final BursaWolfParameters that = (BursaWolfParameters) object;
-            return Numerics.equals(this.tX, that.tX) &&
-                   Numerics.equals(this.tY, that.tY) &&
-                   Numerics.equals(this.tZ, that.tZ) &&
-                   Numerics.equals(this.rX, that.rX) &&
-                   Numerics.equals(this.rY, that.rY) &&
-                   Numerics.equals(this.rZ, that.rZ) &&
-                   Numerics.equals(this.dS, that.dS) &&
-                    Objects.equals(this.targetDatum, that.targetDatum) &&
-                    Objects.equals(this.domainOfValidity, that.domainOfValidity);
+            return Arrays.equals(this.getValues(),      that.getValues()) &&
+                  Objects.equals(this.targetDatum,      that.targetDatum) &&
+                  Objects.equals(this.domainOfValidity, that.domainOfValidity);
         }
         return false;
     }
@@ -572,12 +627,11 @@ public class BursaWolfParameters extends
     /**
      * Returns a hash value for this object.
      *
-     * @return The hash code value. This value doesn't need to be the same
-     *         in past or future versions of this class.
+     * @return The hash code value. This value does not need to be the same in past or future
versions of this class.
      */
     @Override
     public int hashCode() {
-        return Arrays.hashCode(new double[] {tX, tY, tZ, rX, rY, rZ, dS}) ^ (int) serialVersionUID;
+        return Arrays.hashCode(getValues()) ^ (int) serialVersionUID;
     }
 
     /**
@@ -599,14 +653,14 @@ public class BursaWolfParameters extends
      */
     @Override
     protected String formatTo(final Formatter formatter) {
-        formatter.append(tX);
-        formatter.append(tY);
-        formatter.append(tZ);
-        formatter.append(rX);
-        formatter.append(rY);
-        formatter.append(rZ);
-        formatter.append(dS);
+        final double[] values = getValues();
+        for (final double value : values) {
+            formatter.append(value);
+        }
         if (isToWGS84()) {
+            if (values.length > 7) {
+                formatter.setInvalidWKT(BursaWolfParameters.class, null);
+            }
             return WKTKeywords.ToWGS84;
         }
         formatter.setInvalidWKT(BursaWolfParameters.class, null);

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java?rev=1683594&r1=1683593&r2=1683594&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
[UTF-8] Thu Jun  4 16:58:33 2015
@@ -34,6 +34,7 @@ import org.apache.sis.referencing.operat
 import org.apache.sis.referencing.operation.matrix.NoninvertibleMatrixException;
 import org.apache.sis.metadata.iso.extent.Extents;
 import org.apache.sis.internal.metadata.WKTKeywords;
+import org.apache.sis.internal.metadata.ReferencingServices;
 import org.apache.sis.internal.referencing.ExtentSelector;
 import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.util.logging.Logging;
@@ -141,7 +142,7 @@ public class DefaultGeodeticDatum extend
      * The <code>{@value #BURSA_WOLF_KEY}</code> property for
      * {@linkplain #getBursaWolfParameters() Bursa-Wolf parameters}.
      */
-    public static final String BURSA_WOLF_KEY = "bursaWolf";
+    public static final String BURSA_WOLF_KEY = ReferencingServices.BURSA_WOLF_KEY;
 
     /**
      * The array to be returned by {@link #getBursaWolfParameters()} when there is no Bursa-Wolf
parameters.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java?rev=1683594&r1=1683593&r2=1683594&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java
[UTF-8] Thu Jun  4 16:58:33 2015
@@ -17,7 +17,6 @@
 package org.apache.sis.referencing.datum;
 
 import java.util.Date;
-import java.util.Arrays;
 import org.opengis.metadata.extent.Extent;
 import org.opengis.referencing.datum.GeodeticDatum;
 import org.apache.sis.internal.util.Numerics;
@@ -60,7 +59,7 @@ import static org.apache.sis.internal.re
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.6
  * @module
  */
 public class TimeDependentBWP extends BursaWolfParameters {
@@ -201,7 +200,50 @@ public class TimeDependentBWP extends Bu
     }
 
     /**
+     * Returns the parameter values. The first 14 elements are always {@link #tX tX}, {@link
#tY tY}, {@link #tZ tZ},
+     * {@link #rX rX}, {@link #rY rY}, {@link #rZ rZ}, {@link #dS dS}, {@link #dtX}, {@link
#dtY}, {@link #dtZ},
+     * {@link #drX}, {@link #drY}, {@link #drZ} and {@link #ddS} in that order.
+     *
+     * @return The parameter values as an array of length 14.
+     *
+     * @since 0.6
+     */
+    @Override
+    public double[] getValues() {
+        return new double[] {tX, tY, tZ, rX, rY, rZ, dS, dtX, dtY, dtZ, drX, drY, drZ, ddS};
+    }
+
+    /**
+     * Sets the parameters to the given values. The given array can have any length. The
first array elements will be
+     * assigned to the {@link #tX tX}, {@link #tY tY}, {@link #tZ tZ}, {@link #rX rX}, {@link
#rY rY}, {@link #rZ rZ},
+     * {@link #dS dS}, {@link #dtX}, {@link #dtY}, {@link #dtZ}, {@link #drX}, {@link #drY},
{@link #drZ} and
+     * {@link #ddS} fields in that order.
+     *
+     * @param elements The new parameter values, as an array of any length.
+     *
+     * @since 0.6
+     */
+    @Override
+    @SuppressWarnings("fallthrough")
+    public void setValues(final double... elements) {
+        if (elements.length >= 8) {
+            switch (elements.length) {
+                default:  ddS = elements[13];  // Fallthrough everywhere.
+                case 13:  drZ = elements[12];
+                case 12:  drY = elements[11];
+                case 11:  drX = elements[10];
+                case 10:  dtZ = elements[ 9];
+                case  9:  dtY = elements[ 8];
+                case  8:  dtX = elements[ 7];
+            }
+        }
+        super.setValues(elements);
+    }
+
+    /**
      * {@inheritDoc}
+     *
+     * @return {@code true} if the parameters describe no operation.
      */
     @Override
     public boolean isIdentity() {
@@ -210,6 +252,8 @@ public class TimeDependentBWP extends Bu
 
     /**
      * {@inheritDoc}
+     *
+     * @return {@code true} if the parameters describe a translation only.
      */
     @Override
     public boolean isTranslation() {
@@ -232,45 +276,21 @@ public class TimeDependentBWP extends Bu
 
     /**
      * {@inheritDoc}
-     */
-    @Override
-    public void invert() {
-        super.invert();
-        dtX = -dtX;
-        dtY = -dtY;
-        dtZ = -dtZ;
-        drX = -drX;
-        drY = -drY;
-        drZ = -drZ;
-        ddS = -ddS;
-    }
-
-    /**
-     * {@inheritDoc}
+     *
+     * @return {@code true} if the given object is equal to this {@code TimeDependentBWP}.
      */
     @Override
     public boolean equals(final Object object) {
-        if (super.equals(object)) {
-            final TimeDependentBWP that = (TimeDependentBWP) object;
-            return timeReference == that.timeReference &&
-                   Numerics.equals(this.dtX, that.dtX) &&
-                   Numerics.equals(this.dtY, that.dtY) &&
-                   Numerics.equals(this.dtZ, that.dtZ) &&
-                   Numerics.equals(this.drX, that.drX) &&
-                   Numerics.equals(this.drY, that.drY) &&
-                   Numerics.equals(this.drZ, that.drZ) &&
-                   Numerics.equals(this.ddS, that.ddS);
-        }
-        return false;
+        return super.equals(object) && timeReference == ((TimeDependentBWP) object).timeReference;
     }
 
     /**
      * {@inheritDoc}
+     *
+     * @return The hash code value. This value does not need to be the same in past or future
versions of this class.
      */
     @Override
     public int hashCode() {
-        return ((int) serialVersionUID) ^ Arrays.hashCode(new double[] {
-            tX, tY, tZ, rX, rY, rZ, dS, dtX, dtY, dtZ, drX, drY, drZ, ddS, timeReference
-        });
+        return super.hashCode() ^ Numerics.hashCode(timeReference);
     }
 }



Mime
View raw message