sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1661241 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/ sis-referencing/src/main/java/org/apache/sis/parameter/ sis-referencing/src...
Date Fri, 20 Feb 2015 23:34:12 GMT
Author: desruisseaux
Date: Fri Feb 20 23:34:12 2015
New Revision: 1661241

URL: http://svn.apache.org/r1661241
Log:
Adapt the parameter group name depending on wether the matrix is compliant with EPSG:9624
definition or not.
EPSG:9624 is only for affine matrix of size 3x3, while OGC definition is does not put any
restriction.

We are still trying to figure out the best way to manage both definitions (EPSG and OGC) transparently.
A next commit may try to get ride of MatrixParametersEPSG private class in an effort to simplify.

Added:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/EPSGName.java
  (with props)
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixValues.java
  (with props)
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixValuesTest.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Affine.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParametersEPSG.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorParameters.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorValues.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixParametersEPSGTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorValuesTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Constants.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java?rev=1661241&r1=1661240&r2=1661241&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] Fri Feb 20 23:34:12 2015
@@ -870,7 +870,7 @@ public class Formatter implements Locali
                 final Matrix matrix = ReferencingServices.getInstance().getMatrix(transform);
                 if (matrix != null) {
                     openElement(true, "Param_MT");
-                    buffer.appendCodePoint(symbols.getOpeningQuote(0)).append("Affine")
+                    buffer.appendCodePoint(symbols.getOpeningQuote(0)).append(Constants.AFFINE)
                           .appendCodePoint(symbols.getClosingQuote(0));
                     indent(+1);
                     append(matrix);

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Affine.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Affine.java?rev=1661241&r1=1661240&r2=1661241&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Affine.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Affine.java
[UTF-8] Fri Feb 20 23:34:12 2015
@@ -66,6 +66,16 @@ public final class Affine extends Abstra
     private static final long serialVersionUID = 649555815622129472L;
 
     /**
+     * The operation method name as defined in the EPSG database.
+     * Must matches exactly the EPSG name (this will be verified by JUnit tests).
+     *
+     * <p>Note: in contrast, the name used by OGC is just "Affine".</p>
+     *
+     * @see org.apache.sis.internal.util.Constants#AFFINE
+     */
+    public static final String NAME = "Affine general parametric transformation";
+
+    /**
      * The number of dimensions used by the EPSG:9624 definition. This will be used as the
      * default number of dimensions. Operation methods of other dimensions, where we have
      * no EPSG definition, shall use the Well Known Text (WKT) parameter names.
@@ -73,7 +83,8 @@ public final class Affine extends Abstra
     public static final int EPSG_DIMENSION = 2;
 
     /**
-     * The maximal number of dimension to be cached in the {@link #cached} array.
+     * The maximal number of dimensions to be cached. Descriptors having more than
+     * this amount of dimensions will be recreated every time they are requested.
      */
     private static final int MAX_CACHED_DIMENSION = 6;
 

Added: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/EPSGName.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/EPSGName.java?rev=1661241&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/EPSGName.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/EPSGName.java
[UTF-8] Fri Feb 20 23:34:12 2015
@@ -0,0 +1,84 @@
+/*
+ * 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.internal.referencing.provider;
+
+import java.util.Map;
+import java.util.HashMap;
+import org.opengis.util.InternationalString;
+import org.apache.sis.internal.util.Constants;
+import org.apache.sis.metadata.iso.ImmutableIdentifier;
+import org.apache.sis.metadata.iso.citation.Citations;
+import org.apache.sis.referencing.NamedIdentifier;
+
+import static org.opengis.referencing.IdentifiedObject.NAME_KEY;
+import static org.opengis.referencing.IdentifiedObject.ALIAS_KEY;
+import static org.opengis.referencing.IdentifiedObject.IDENTIFIERS_KEY;
+
+
+/**
+ * Placeholder for the name of an operation method or a parameter defined in the EPSG database.
+ * We use this placeholder for remembering where to manage {@code IdentifiedObject} version.
+ * Future implementation may also be able to read the remarks from the database if requested.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.6
+ * @version 0.6
+ * @module
+ */
+public final class EPSGName {  // TODO: consider extending NamedIdentifier if we implement
deferred reading of remarks.
+    /**
+     * Version of the operation method, or {@code null} if unknown.
+     *
+     * This is unspecified in current Apache SIS implementation.
+     * However future SIS implementations may fetch this information from the EPSG database.
+     */
+    private static final String VERSION = null;
+
+    /**
+     * Placeholder for what may be (in a future Apache SIS version) an implementation
+     * capable to fetch the remarks from the database using the given identifier code.
+     */
+    private static final InternationalString REMARKS = null;
+
+    /**
+     * Do not allow (for now) instantiation of this class.
+     */
+    private EPSGName() {
+    }
+
+    /**
+     * Creates a map of properties to be given to the construction of an operation method.
+     * The returned map is modifiable - callers can add or remove entries after this method
call.
+     *
+     * @param  identifier The EPSG code.
+     * @param  name       The EPSG name.
+     * @param  nameOGC    The OGC name, or {@code null} if none.
+     * @return A map of properties for building the operation method.
+     */
+    public static Map<String,Object> properties(final short identifier, final String
name, final String nameOGC) {
+        final Map<String,Object> properties = new HashMap<>(4);
+        properties.put(NAME_KEY, new NamedIdentifier(
+                Citations.OGP, Constants.EPSG, name, VERSION, REMARKS));
+        properties.put(IDENTIFIERS_KEY, new ImmutableIdentifier(
+                Citations.OGP, Constants.EPSG, Short.toString(identifier).intern(), VERSION,
REMARKS));
+        if (nameOGC != null) {
+            // Version and remarks are intentionally null here, since they are not EPSG version
or remarks.
+            properties.put(ALIAS_KEY, new NamedIdentifier(Citations.OGC, Constants.OGC, nameOGC,
null, null));
+        }
+        return properties;
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/EPSGName.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParametersEPSG.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParametersEPSG.java?rev=1661241&r1=1661240&r2=1661241&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParametersEPSG.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParametersEPSG.java
[UTF-8] Fri Feb 20 23:34:12 2015
@@ -30,7 +30,7 @@ import static org.apache.sis.internal.ut
 
 /**
  * A special case of {@link MatrixParameters} implementing the "magic" for the EPSG:9624
parameters.
- * The "magical" behavior is to hide {@code "num_row"}, {@cod "num_col"} and last row parameters
if
+ * The "magical" behavior is to hide {@code "num_row"}, {@code "num_col"} and last row parameters
if
  * the matrix has exactly the dimensions required by the EPSG:9624 operation method, which
is 3×3.
  * The intend is to get a descriptor matching the one defined in the EPSG database.
  *

Added: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixValues.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixValues.java?rev=1661241&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixValues.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixValues.java
[UTF-8] Fri Feb 20 23:34:12 2015
@@ -0,0 +1,130 @@
+/*
+ * 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.parameter;
+
+import java.util.Set;
+import java.util.Collection;
+import java.util.Collections;
+import org.opengis.util.GenericName;
+import org.opengis.metadata.Identifier;
+import org.opengis.parameter.ParameterValueGroup;
+import org.apache.sis.internal.util.Constants;
+import org.apache.sis.internal.referencing.provider.Affine;
+import org.apache.sis.internal.referencing.provider.EPSGName;
+
+import static org.apache.sis.internal.util.CollectionsExt.first;
+
+
+/**
+ * The values for a group of matrix parameters. This value group provides the same extensibility
than
+ * the one described in {@link TensorValues}, plus the capability to adapt the group name
and identifier
+ * according the matrix size. Consequently, this {@code ParameterValueGroup} is also its
own mutable
+ * {@code ParameterDescriptorGroup}.
+ *
+ * <p>This class is where we implement the "magic" for using the EPSG:9624 parameter
names when the
+ * matrix is compliant with the EPSG restrictions, and using the OGC parameter names in other
cases.</p>
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.6
+ * @version 0.6
+ * @module
+ */
+final class MatrixValues extends TensorValues<Double> {
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = 2169049712239591110L;
+
+    /**
+     * Constructs a new group of matrix parameters.
+     */
+    MatrixValues() {
+        super(EPSGName.properties((short) 9624, Affine.NAME, Constants.AFFINE), TensorParameters.EPSG);
+    }
+
+    /**
+     * Constructs a copy of the given matrix parameters.
+     * If {@code clone} is true, the new group will be a clone of the given group.
+     * If {@code clone} is false, the new group will be initialized to default values.
+     */
+    private MatrixValues(final MatrixValues other, final boolean clone) {
+        super(other, clone);
+    }
+
+    /**
+     * Returns {@code true} if this matrix is compliant with the EPSG definition.
+     * This is {@code true} if this matrix is affine and of size 3×3.
+     */
+    private boolean isEPSG() {
+        return isAffine(Affine.EPSG_DIMENSION + 1);
+    }
+
+    /**
+     * Returns the object to use for computing parameter descriptions.
+     * We can use the EPSG descriptors only if this matrix size matches EPSG expectations.
+     *
+     * @return Object to use for computing parameter descriptions.
+     */
+    @Override
+    TensorParameters<Double> provider() {
+        return isEPSG() ? super.provider() : TensorParameters.WKT1;
+    }
+
+    /**
+     * Returns the EPSG name if this matrix is compliant with the EPSG definition,
+     * or the OGC name otherwise.
+     *
+     * @see #getAlias()
+     */
+    @Override
+    public Identifier getName() {
+        return isEPSG() ? super.getName() : (Identifier) first(super.getAlias());
+    }
+
+    /**
+     * Returns the EPSG identifier if this matrix is compliant with the EPSG definition,
+     * or an empty set otherwise.
+     */
+    @Override
+    public Set<Identifier> getIdentifiers() {
+        return isEPSG() ? super.getIdentifiers() : Collections.emptySet();
+    }
+
+    /**
+     * Do not returns the OGC name if we already returned it with {@link #getName()}.
+     */
+    @Override
+    public Collection<GenericName> getAlias() {
+        return isEPSG() ? super.getAlias() : Collections.emptySet();
+    }
+
+    /**
+     * Returns a clone of this group.
+     */
+    @Override
+    public ParameterValueGroup clone() {
+        return new MatrixValues(this, true);
+    }
+
+    /**
+     * Returns a new group initialized to default values.
+     */
+    @Override
+    public ParameterValueGroup createValue() {
+        return new MatrixValues(this, false);
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixValues.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorParameters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorParameters.java?rev=1661241&r1=1661240&r2=1661241&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorParameters.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorParameters.java
[UTF-8] Fri Feb 20 23:34:12 2015
@@ -168,12 +168,12 @@ public class TensorParameters<E> impleme
      * This implementation accepts also parameters for matrix of different size (for example
{@code "C4"} for row 3
      * and column 4), but such extensions are not official EPSG parameter names.
      *
-     * <p>In addition, each parameter accepts also the {@link WKT1} name (e.g. {@code
"elt_1_2"})
+     * <p>In addition, each parameter accepts also the {@link #WKT1} name (e.g. {@code
"elt_1_2"})
      * as an {@linkplain ParameterDescriptor#getAlias() alias}.</p>
      *
      * @since 0.6
      */
-    public static final TensorParameters<Double> EPSG;
+    static final TensorParameters<Double> EPSG;
 
     /**
      * Parses and creates matrix parameters with names matching the
@@ -544,7 +544,8 @@ public class TensorParameters<E> impleme
     /**
      * Returns the descriptor in this group for the specified name.
      *
-     * @param  name The case insensitive name of the parameter to search for.
+     * @param  caller     The {@link TensorValues} instance invoking this method, used only
in case of errors.
+     * @param  name       The case insensitive name of the parameter to search for.
      * @param  actualSize The current values of parameters that define the matrix (or tensor)
dimensions.
      * @return The parameter for the given name.
      * @throws ParameterNotFoundException if there is no parameter for the given name.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorValues.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorValues.java?rev=1661241&r1=1661240&r2=1661241&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorValues.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorValues.java
[UTF-8] Fri Feb 20 23:34:12 2015
@@ -57,7 +57,7 @@ import org.apache.sis.util.resources.Err
  * @version 0.6
  * @module
  */
-final class TensorValues<E> extends AbstractParameterDescriptor
+class TensorValues<E> extends AbstractParameterDescriptor
         implements ParameterDescriptorGroup, ParameterValueGroup, Cloneable
 {
     /**
@@ -66,7 +66,11 @@ final class TensorValues<E> extends Abst
     private static final long serialVersionUID = -7747712999115044943L;
 
     /**
-     * A provider of matrix descriptors.
+     * A provider of descriptors for matrix parameters. This object is used like a collection
of
+     * {@link ParameterDescriptor}s, even if it does not implement any standard collection
API.
+     *
+     * @see TensorParameters#descriptor(ParameterDescriptorGroup, String, int[])
+     * @see TensorParameters#descriptors(int[])
      */
     private final TensorParameters<E> descriptors;
 
@@ -102,7 +106,7 @@ final class TensorValues<E> extends Abst
      * If {@code clone} is true, the new group will be a clone of the given group.
      * If {@code clone} is false, the new group will be initialized to default values.
      */
-    private TensorValues(final TensorValues<E> other, final boolean clone) {
+    TensorValues(final TensorValues<E> other, final boolean clone) {
         super(other);
         descriptors = other.descriptors;
         dimensions = other.dimensions.clone();
@@ -156,7 +160,7 @@ final class TensorValues<E> extends Abst
      * the description depends on {@code "num_row"} and {@code "num_col"} parameter values.
      */
     @Override
-    public ParameterDescriptorGroup getDescriptor() {
+    public final ParameterDescriptorGroup getDescriptor() {
         return this;
     }
 
@@ -165,8 +169,19 @@ final class TensorValues<E> extends Abst
      * on the value of {@code "num_row"} and {@code "num_col"} parameters.
      */
     @Override
-    public List<GeneralParameterDescriptor> descriptors() {
-        return descriptors.descriptors(size());
+    public final List<GeneralParameterDescriptor> descriptors() {
+        return provider().descriptors(size());
+    }
+
+    /**
+     * Returns the object to use for computing parameter descriptions.
+     * This should always be the {@link #descriptors} field, unless we
+     * want to vary parameter descriptions according the matrix size.
+     *
+     * @return Object to use for computing parameter descriptions.
+     */
+    TensorParameters<E> provider() {
+        return descriptors;
     }
 
     /**
@@ -188,10 +203,10 @@ final class TensorValues<E> extends Abst
      * @throws ParameterNotFoundException if there is no parameter for the given name.
      */
     @Override
-    public GeneralParameterDescriptor descriptor(String name) throws ParameterNotFoundException
{
+    public final GeneralParameterDescriptor descriptor(String name) throws ParameterNotFoundException
{
         name = CharSequences.trimWhitespaces(name);
         ArgumentChecks.ensureNonEmpty("name", name);
-        return descriptors.descriptor(this, name, size());
+        return provider().descriptor(this, name, size());
     }
 
     /**
@@ -202,13 +217,14 @@ final class TensorValues<E> extends Abst
      * @throws ParameterNotFoundException if there is no parameter for the given name.
      */
     @Override
-    public ParameterValue<?> parameter(String name) throws ParameterNotFoundException
{
+    public final ParameterValue<?> parameter(String name) throws ParameterNotFoundException
{
         name = CharSequences.trimWhitespaces(name);
         ArgumentChecks.ensureNonEmpty("name", name);
         IllegalArgumentException cause = null;
+        final TensorParameters<E> provider = provider();
         int[] indices = null;
         try {
-            indices = descriptors.nameToIndices(name);
+            indices = provider.nameToIndices(name);
         } catch (IllegalArgumentException exception) {
             cause = exception;
         }
@@ -223,9 +239,9 @@ final class TensorValues<E> extends Abst
          * Verify if the requested parameters is one of those that
          * specify the matrix/tensor size ("num_row" or "num_col").
          */
-        final int rank = descriptors.rank();
+        final int rank = provider.rank();
         for (int i=0; i<rank; i++) {
-            final ParameterDescriptor<Integer> param = descriptors.getDimensionDescriptor(i);
+            final ParameterDescriptor<Integer> param = provider.getDimensionDescriptor(i);
             if (IdentifiedObjects.isHeuristicMatchForName(param, name)) {
                 return dimensions[i];
             }
@@ -283,11 +299,12 @@ final class TensorValues<E> extends Abst
             parent = (Object[]) element;
             element = parent[indices[i]];
         }
+        final TensorParameters<E> provider = provider();
         if (element == null) {
-            element = descriptors.getElementDescriptor(indices).createValue();
+            element = provider.getElementDescriptor(indices).createValue();
             parent[indices[rank - 1]] = element;
         }
-        return Parameters.cast((ParameterValue<?>) element, descriptors.getElementType());
+        return Parameters.cast((ParameterValue<?>) element, provider.getElementType());
     }
 
     /**
@@ -297,7 +314,7 @@ final class TensorValues<E> extends Abst
      * Never requested elements are left to their default value and omitted from the returned
array.
      */
     @Override
-    public List<GeneralParameterValue> values() {
+    public final List<GeneralParameterValue> values() {
         final List<GeneralParameterValue> addTo = new ArrayList<>();
         for (final ParameterValue<Integer> dimension : dimensions) {
             if (!isOmitted(dimension)) {
@@ -362,6 +379,32 @@ final class TensorValues<E> extends Abst
     }
 
     /**
+     * Returns {@code true} if this matrix is square and affine with the given size.
+     * This operation is allowed only for tensors of {@linkplain #rank() rank} 2.
+     */
+    final boolean isAffine(int size) {
+        if (dimensions[0].intValue() != size ||
+            dimensions[1].intValue() != size)
+        {
+            return false;
+        }
+        if (values != null) {
+            final ParameterValue<?>[] row = (ParameterValue<?>[]) values[size
- 1];
+            if (row != null) {
+                double expected = 1;
+                while (--size >= 0) {
+                    final ParameterValue<?> element = row[size];
+                    if (element != null && element.doubleValue() != expected) {
+                        return false;
+                    }
+                    expected = 0;
+                }
+            }
+        }
+        return true;
+    }
+
+    /**
      * Creates a matrix from this group of parameters.
      * This operation is allowed only for tensors of {@linkplain #rank() rank} 2.
      *
@@ -394,7 +437,7 @@ final class TensorValues<E> extends Abst
      *
      * @param matrix The matrix to copy in this group of parameters.
      */
-    public void setMatrix(final Matrix matrix) {
+    final void setMatrix(final Matrix matrix) {
         final int numRow = matrix.getNumRow();
         final int numCol = matrix.getNumCol();
         dimensions[0].setValue(numRow);
@@ -406,7 +449,7 @@ final class TensorValues<E> extends Abst
             ParameterValue<?>[] row = null;
             for (int i=0; i<numCol; i++) {
                 indices[1] = i;
-                ParameterDescriptor<E> descriptor = descriptors.getElementDescriptor(indices);
+                ParameterDescriptor<E> descriptor = provider().getElementDescriptor(indices);
                 final E def = descriptor.getDefaultValue();
                 final double element = matrix.getElement(j,i);
                 if (!(def instanceof Number) || !Numerics.equalsIgnoreZeroSign(element, ((Number)
def).doubleValue())) {
@@ -429,7 +472,7 @@ final class TensorValues<E> extends Abst
      * Compares this object with the specified one for equality.
      */
     @Override
-    public boolean equals(final Object object, final ComparisonMode mode) {
+    public final boolean equals(final Object object, final ComparisonMode mode) {
         if (object == this) {
             return true; // Slight optimization.
         }
@@ -447,7 +490,7 @@ final class TensorValues<E> extends Abst
      * @return {@inheritDoc}
      */
     @Override
-    protected long computeHashCode() {
+    protected final long computeHashCode() {
         return super.computeHashCode() + descriptors.hashCode();
         // Do not use any field other than descriptors, because they are not immutable.
     }
@@ -459,7 +502,7 @@ final class TensorValues<E> extends Abst
      * @return {@code "ParameterGroup"}.
      */
     @Override
-    protected String formatTo(final Formatter formatter) {
+    protected final String formatTo(final Formatter formatter) {
         WKTUtilities.appendName(this, formatter, ElementKind.PARAMETER);
         WKTUtilities.append(this, formatter);
         return "ParameterGroup";

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java?rev=1661241&r1=1661240&r2=1661241&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
[UTF-8] Fri Feb 20 23:34:12 2015
@@ -190,8 +190,8 @@ public abstract class Builder<B extends
     protected Builder() {
         assert verifyParameterizedType(getClass());
         properties  = new HashMap<>(8);
-        aliases     = new ArrayList<>(4);
-        identifiers = new ArrayList<>(4);
+        aliases     = new ArrayList<>();  // Will often stay empty (default constructor
handles those cases well).
+        identifiers = new ArrayList<>();
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixParametersEPSGTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixParametersEPSGTest.java?rev=1661241&r1=1661240&r2=1661241&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixParametersEPSGTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixParametersEPSGTest.java
[UTF-8] Fri Feb 20 23:34:12 2015
@@ -32,7 +32,7 @@ import static org.apache.sis.test.Assert
  * @version 0.6
  * @module
  */
-@DependsOn(TensorParametersTest.class)
+@DependsOn(MatrixParametersTest.class)
 public final strictfp class MatrixParametersEPSGTest extends MatrixParametersTest {
     /**
      * The expected parameter identifiers for the matrix elements, or 0 if none.

Added: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixValuesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixValuesTest.java?rev=1661241&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixValuesTest.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixValuesTest.java
[UTF-8] Fri Feb 20 23:34:12 2015
@@ -0,0 +1,75 @@
+/*
+ * 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.parameter;
+
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.apache.sis.test.MetadataAssert.*;
+
+
+/**
+ * Tests the {@link MatrixValues} class.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.6
+ * @version 0.6
+ * @module
+ */
+@DependsOn({
+    MatrixParametersEPSGTest.class,
+    TensorValuesTest.class
+})
+public final strictfp class MatrixValuesTest extends TestCase {
+    /**
+     * Tests WKT formatting, and in particular the adjustment according
+     * whether we comply with EPSG:9624 definition or not.
+     */
+    @Test
+    public void testWKT() {
+        final MatrixValues matrix = new MatrixValues();
+        assertWktEquals(
+                "ParameterGroup[“Affine general parametric transformation”," +
+                " Id[“EPSG”, 9624, Citation[“OGP”]]]", matrix);
+        /*
+         * Try arbitrary values.
+         */
+        matrix.parameter("A1").setValue( 2);
+        matrix.parameter("B1").setValue( 0);
+        matrix.parameter("B2").setValue(-1);
+        assertWktEquals(
+                "ParameterGroup[“Affine general parametric transformation”,\n" +
+                "  Parameter[“A1”, 2.0, Id[“EPSG”, 8624]],\n"  +
+                "  Parameter[“B1”, 0.0, Id[“EPSG”, 8640]],\n" +
+                "  Parameter[“B2”, -1.0, Id[“EPSG”, 8641]],\n" +
+                "  Id[“EPSG”, 9624, Citation[“OGP”]]]", matrix);
+        /*
+         * Setting a value on the last row make the matrix non-affine.
+         * So it should not ne anymore EPSG:9624.
+         *
+         * TODO: The parameter should also be renamed as "elt_0_1", "elt_1_1", etc.
+         */
+        matrix.parameter("C0").setValue(3);
+        assertWktEquals(
+                "ParameterGroup[“Affine”,\n" +
+                "  Parameter[“A1”, 2.0, Id[“EPSG”, 8624]],\n"  +
+                "  Parameter[“B1”, 0.0, Id[“EPSG”, 8640]],\n" +
+                "  Parameter[“B2”, -1.0, Id[“EPSG”, 8641]],\n" +
+                "  Parameter[“C0”, 3.0]]", matrix);
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixValuesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixValuesTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorValuesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorValuesTest.java?rev=1661241&r1=1661240&r2=1661241&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorValuesTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorValuesTest.java
[UTF-8] Fri Feb 20 23:34:12 2015
@@ -26,6 +26,8 @@ import org.opengis.parameter.GeneralPara
 import org.opengis.parameter.ParameterNotFoundException;
 import org.opengis.referencing.operation.Matrix;
 import org.apache.sis.referencing.operation.matrix.Matrices;
+import org.apache.sis.internal.referencing.provider.Affine;
+import org.apache.sis.internal.util.Constants;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
@@ -290,21 +292,21 @@ public final strictfp class TensorValues
     @DependsOnMethod("testParameter")
     public void testClone() {
         final ParameterValueGroup group = createWKT1();
-        group.parameter(NUM_ROW).setValue(2);
+        group.parameter( NUM_ROW ).setValue(2);
         group.parameter("elt_0_1").setValue(4);
         group.parameter("elt_1_0").setValue(2);
         /*
          * Creates a clone, modify some values, keep other values.
          */
         final ParameterValueGroup clone = group.clone();
-        clone.parameter(NUM_ROW).setValue(4);
+        clone.parameter( NUM_ROW ).setValue(4);
         clone.parameter("elt_0_1").setValue(3);
         /*
          * Verify that changes in cloned values did not affected
          * values in the original object.
          */
-        assertEquals(2, group.parameter(NUM_ROW).intValue());
-        assertEquals(4, clone.parameter(NUM_ROW).intValue());
+        assertEquals(2, group.parameter( NUM_ROW ).intValue());
+        assertEquals(4, clone.parameter( NUM_ROW ).intValue());
         assertEquals(4, group.parameter("elt_0_1").intValue());
         assertEquals(3, clone.parameter("elt_0_1").intValue());
         assertEquals(2, group.parameter("elt_1_0").intValue());
@@ -327,7 +329,7 @@ public final strictfp class TensorValues
         matrix.setElement(1,0, -2);
         matrix.setElement(2,3,  7);
         final ParameterValueGroup group = TensorParameters.WKT1.createValueGroup(
-                singletonMap(TensorValues.NAME_KEY, "Affine"), matrix);
+                singletonMap(TensorValues.NAME_KEY, Constants.AFFINE), matrix);
         validate(group);
         assertWktEquals(
                 "ParameterGroup[“Affine”,\n"      +
@@ -354,7 +356,7 @@ public final strictfp class TensorValues
         matrix.setElement(1,0, -2);
         matrix.setElement(2,1,  7);
         final ParameterValueGroup group = TensorParameters.EPSG.createValueGroup(
-                singletonMap(TensorValues.NAME_KEY, "Affine general parametric transformation"),
matrix);
+                singletonMap(TensorValues.NAME_KEY, Affine.NAME), matrix);
         validate(group);
         assertWktEquals(
                 "ParameterGroup[“Affine general parametric transformation”,\n" +

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1661241&r1=1661240&r2=1661241&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Fri Feb 20 23:34:12 2015
@@ -78,6 +78,7 @@ import org.junit.BeforeClass;
     org.apache.sis.parameter.MatrixParametersTest.class,
     org.apache.sis.parameter.MatrixParametersEPSGTest.class,
     org.apache.sis.parameter.TensorValuesTest.class,
+    org.apache.sis.parameter.MatrixValuesTest.class,
 
     org.apache.sis.referencing.operation.DefaultFormulaTest.class,
     org.apache.sis.referencing.operation.DefaultOperationMethodTest.class,

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Constants.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Constants.java?rev=1661241&r1=1661240&r2=1661241&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Constants.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Constants.java
[UTF-8] Fri Feb 20 23:34:12 2015
@@ -82,6 +82,13 @@ public final class Constants extends Sta
     public static final String NUM_ROW = "num_row", NUM_COL = "num_col";
 
     /**
+     * The OGC name for <cite>Affine general parametric transformation"</cite>.
+     *
+     * @see org.apache.sis.internal.referencing.provider.Affine#NAME
+     */
+    public static final String AFFINE = "Affine";
+
+    /**
      * EPSG code of the {@code A0} coefficient used in affine (general parametric) and polynomial
transformations.
      * Codes for parameters {@code A1} to {@code A8} inclusive follow, but the affine coefficients
stop at {@code A2}.
      */



Mime
View raw message