Author: desruisseaux
Date: Sun Feb 22 17:02:00 2015
New Revision: 1661494
URL: http://svn.apache.org/r1661494
Log:
Partial rollback of previous commit, which was an attempt to adjust
automatically the ParameterDescriptorGroup content
according whether the matrix content matches the EPSG:9624 definition or not.
This was complicated and probably at risk
to cause confusion to the users. Instead, we will accept that the parameter
description provided by:
DefaultOperationMethod.getParameters()
may not be identical to the description provided by:
ParameterValueGroup.getDescriptor()
in the particular case of "Affine general parametric transformation".
We should document this potential mismatch somewhere, but it is not yet clear
where exactly.
Added:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParametersAlphaNum.java
- copied, changed from r1661241,
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParametersEPSG.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixParametersAlphaNumTest.java
- copied, changed from r1661241,
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixParametersEPSGTest.java
Removed:
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/MatrixValues.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/MatrixValuesTest.java
Modified:
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/MatrixParameters.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/test/java/org/apache/sis/internal/referencing/provider/AffineTest.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorParametersTest.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
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=1661494&r1=1661493&r2=1661494&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] Sun Feb 22 17:02:00 2015
@@ -18,7 +18,6 @@ package org.apache.sis.internal.referenc
import java.util.Map;
import java.util.Collections;
-import org.opengis.parameter.ParameterDescriptor;
import org.opengis.parameter.ParameterDescriptorGroup;
import org.opengis.parameter.ParameterNotFoundException;
import org.opengis.parameter.ParameterValueGroup;
@@ -26,6 +25,7 @@ import org.opengis.referencing.operation
import org.opengis.referencing.operation.Conversion;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.OperationMethod;
+import org.apache.sis.internal.util.Constants;
import org.apache.sis.metadata.iso.citation.Citations;
import org.apache.sis.parameter.DefaultParameterDescriptorGroup;
import org.apache.sis.parameter.TensorParameters;
@@ -116,39 +116,17 @@ public final class Affine extends Abstra
static final int EPSG_INDEX = (EPSG_DIMENSION - 1) * MAX_CACHED_DIMENSION
+ (EPSG_DIMENSION - 1);
/**
- * The name, aliases and identifiers of the "Affine" method.
- */
- private static final Map<String,?> IDENTIFICATION =
- Collections.singletonMap(NAME_KEY, new
NamedIdentifier(Citations.OGC, "Affine"));
-
- /**
- * The group of all parameters expected by this coordinate operation.
- */
- private static final ParameterDescriptorGroup PARAMETERS;
- static {
- final int[] indices = new int[2]; // The length of this array is the
number of tensor dimensions.
- @SuppressWarnings("rawtypes")
- final ParameterDescriptor<?>[] parameters =
- new ParameterDescriptor[indices.length + (EPSG_DIMENSION +1) *
(EPSG_DIMENSION + 1)];
- int k = 0;
- do {
- parameters[k] = TensorParameters.WKT1.getDimensionDescriptor(k);
- } while (++k < indices.length);
- for (int j=0; j <= EPSG_DIMENSION; j++) {
- for (int i=0; i <= EPSG_DIMENSION; i++) {
- indices[0] = j;
- indices[1] = i;
- parameters[k++] =
TensorParameters.WKT1.getElementDescriptor(indices);
- }
- }
- PARAMETERS = new DefaultParameterDescriptorGroup(IDENTIFICATION, 1, 1,
parameters);
- }
-
- /**
* Creates a provider for affine transform with a default matrix size.
*/
public Affine() {
- super(EPSG_DIMENSION, EPSG_DIMENSION, PARAMETERS);
+ super(EPSG_DIMENSION, EPSG_DIMENSION, new
DefaultParameterDescriptorGroup(
+ Collections.singletonMap(NAME_KEY, new
NamedIdentifier(Citations.EPSG, NAME)), 1, 1,
+ TensorParameters.ALPHANUM.getAllDescriptors(EPSG_DIMENSION,
EPSG_DIMENSION)));
+ /*
+ * Unconditionally cache this instance because this constructor is
typically invoked by ServiceLoader
+ * when DefaultMathTransformFactory scans the classpath. This normally
happen only once, so the instance
+ * that we create here is probably the unique instance than we want to
keep for the JVM lifetime.
+ */
synchronized (cached) {
cached[EPSG_INDEX] = this;
}
@@ -158,7 +136,16 @@ public final class Affine extends Abstra
* Creates a provider for affine transform with the specified dimensions.
*/
private Affine(final int sourceDimensions, final int targetDimensions) {
- super(sourceDimensions, targetDimensions, PARAMETERS);
+ super(sourceDimensions, targetDimensions, new
DefaultParameterDescriptorGroup(
+ Collections.singletonMap(NAME_KEY, new
NamedIdentifier(Citations.OGC, Constants.AFFINE)), 1, 1,
+ TensorParameters.WKT1.getAllDescriptors(sourceDimensions,
targetDimensions)));
+ }
+
+ /**
+ * Returns {@code true} if the given dimensions are those of EPSG:9624
operation method.
+ */
+ private static boolean isEPSG(final int sourceDimensions, final int
targetDimensions) {
+ return (sourceDimensions == EPSG_DIMENSION && targetDimensions ==
EPSG_DIMENSION);
}
/**
@@ -222,7 +209,8 @@ public final class Affine extends Abstra
* At this point, no existing instance has been found in the cache.
* Create a new instance and cache it if its dimension is not too
large.
*/
- final Affine method = new Affine(sourceDimensions, targetDimensions);
+ final Affine method = isEPSG(sourceDimensions, targetDimensions)
+ ? new Affine() : new Affine(sourceDimensions,
targetDimensions);
if (i >= 0) {
synchronized (Affine.class) {
final Affine other = cached[i]; // May have been created
in another thread.
@@ -253,7 +241,10 @@ public final class Affine extends Abstra
* @return The parameters of the given matrix.
*/
public static ParameterValueGroup parameters(final Matrix matrix) {
- return
TensorParameters.WKT1.createValueGroup(IdentifiedObjects.getProperties(
- descriptor(matrix.getNumRow() - 1, matrix.getNumCol() - 1)),
matrix);
+ final int sourceDimensions = matrix.getNumCol() - 1;
+ final int targetDimensions = matrix.getNumRow() - 1;
+ Map<String,?> properties =
IdentifiedObjects.getProperties(descriptor(sourceDimensions, targetDimensions));
+ return (isEPSG(sourceDimensions, targetDimensions) ?
TensorParameters.ALPHANUM : TensorParameters.WKT1)
+ .createValueGroup(properties, matrix);
}
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParameters.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParameters.java?rev=1661494&r1=1661493&r2=1661494&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParameters.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParameters.java
[UTF-8] Sun Feb 22 17:02:00 2015
@@ -127,8 +127,9 @@ class MatrixParameters extends TensorPar
/**
* Returns the indices of matrix element for the given parameter name, or
{@code null} if none.
- * This implementation unconditionally checks for the EPSG name first
since this is a very quick check.
- * If the given name does not use the EPSG syntax, then this method
fallback on the WKT1 syntax.
+ * This implementation unconditionally checks for the alphanumeric
(EPSG-like) name first since
+ * this is a very quick check. If the given name does not use the EPSG
syntax, then this method
+ * fallback on the WKT1 syntax.
*/
@Override
protected int[] nameToIndices(final String name) throws
IllegalArgumentException {
@@ -141,8 +142,16 @@ class MatrixParameters extends TensorPar
/**
* Creates a new parameter descriptor for a matrix element at the given
indices.
- * This method creates both the OGC name (e.g. {@code "elt_1_2"}) and the
EPSG name (e.g. {@code "B2"}).
- * The EPSG identifier are not created by this method, but rather by the
{@link MatrixParametersEPSG} subclass.
+ * This method creates:
+ *
+ * <ul>
+ * <li>The OGC name (e.g. {@code "elt_1_2"}) as primary name</li>
+ * <li>The EPSG name (e.g. {@code "B2"}) as an alias</li>
+ * </ul>
+ *
+ * This method does <strong>not</strong> create the EPSG identifiers (e.g.
EPSG:8641) because the primary name
+ * created by this method is not the EPSG name. However the {@link
MatrixParametersAlphaNum} subclass uses the
+ * EPSG name as the primary name. Consequently that subclass will create
the EPSG identifier.
*/
@Override
protected ParameterDescriptor<Double> createElementDescriptor(final int[]
indices) throws IllegalArgumentException {
Copied:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParametersAlphaNum.java
(from r1661241,
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/MatrixParametersAlphaNum.java?p2=sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParametersAlphaNum.java&p1=sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParametersEPSG.java&r1=1661241&r2=1661494&rev=1661494&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/MatrixParametersAlphaNum.java
[UTF-8] Sun Feb 22 17:02:00 2015
@@ -19,9 +19,9 @@ package org.apache.sis.parameter;
import java.util.Map;
import java.util.HashMap;
import java.io.ObjectStreamException;
+import org.opengis.util.GenericName;
import org.opengis.parameter.ParameterDescriptor;
import org.apache.sis.internal.util.Constants;
-import org.apache.sis.internal.referencing.provider.Affine;
import org.apache.sis.metadata.iso.ImmutableIdentifier;
import org.apache.sis.metadata.iso.citation.Citations;
@@ -29,17 +29,29 @@ 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"}, {@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.
+ * A special case of {@link MatrixParameters} which create EPSG:9624 parameter
names and identifiers.
+ * The parameters created by this class are close, but not identical, to the
EPSG:9624 definition of
+ * {@code "A0"}, {@code "A1"}, {@code "A2"}, {@code "B0"}, {@code "B1"} and
{@code "B2"}.
+ * The differences are:
+ *
+ * <ul>
+ * <li>EPSG:9624 is only for matrices of size 3×3 and consequently does not
have {@code "num_row"} and
+ * {@code "num_col"} parameters. This class extends the definition to
matrices of arbitrary size
+ * and consequently accepts {@code "num_row"} and {@code "num_col"} as
optional parameters.</li>
+ * <li>EPSG:9624 is restricted to affine matrices and consequently define
parameters only for the two
+ * first rows. This class accepts also parameters for the last row
(namely {@code "C0"}, {@code "C1"}
+ * and {@code "C2"} in a 3×3 matrices).</li>
+ * </ul>
+ *
+ * Because of the above-cited extensions, this class is not named like "EPSG
matrix parameters", but rater
+ * like "Alphanumeric matrix parameters"
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.6
* @version 0.6
* @module
*/
-final class MatrixParametersEPSG extends MatrixParameters {
+final class MatrixParametersAlphaNum extends MatrixParameters {
/**
* For cross-version compatibility.
*/
@@ -51,44 +63,11 @@ final class MatrixParametersEPSG extends
* @param numRow The parameter for the number of rows.
* @param numCol The parameter for the number of columns.
*/
- MatrixParametersEPSG(final ParameterDescriptor<Integer> numRow, final
ParameterDescriptor<Integer> numCol) {
+ MatrixParametersAlphaNum(final ParameterDescriptor<Integer> numRow, final
ParameterDescriptor<Integer> numCol) {
super(numRow, numCol);
}
/**
- * Returns 0 if the dimension parameters ({@code "num_row"} and {@code
"num_col"}) shall be hidden.
- * Those parameters need to be hidden for the EPSG:9624 operation method,
since the EPSG database
- * does not define those parameters.
- */
- @Override
- final int numDimensions(final int[] actualSize) {
- if (actualSize[0] == Affine.EPSG_DIMENSION + 1 &&
- actualSize[1] == Affine.EPSG_DIMENSION + 1)
- {
- return 0;
- }
- return super.numDimensions(actualSize);
- }
-
- /**
- * Returns the number of elements (e.g. {@code "elt_0_0"}) when formatting
the parameter descriptors for a tensor
- * of the given size. This is the total number of elements in the tensor,
except for matrices which are intended
- * to be affine (like {@link #EPSG}) where the last row is omitted.
- */
- @Override
- final int numElements(final int[] actualSize) {
- int numRow = actualSize[0];
- int numCol = actualSize[1];
- assert super.numElements(actualSize) == (numRow * numCol);
- if (numRow == Affine.EPSG_DIMENSION + 1 &&
- numCol == Affine.EPSG_DIMENSION + 1)
- {
- numRow--; // Ommit last row of an affine matrix.
- }
- return numRow * numCol;
- }
-
- /**
* Returns the parameter descriptor name of a matrix element at the given
indices.
* Overridden as a matter of principle, but not used directly by this
implementation.
*/
@@ -100,7 +79,7 @@ final class MatrixParametersEPSG extends
/**
* Creates a new parameter descriptor for a matrix element at the given
indices. This method creates both the
* OGC name (e.g. {@code "elt_1_2"}) and the EPSG name (e.g. {@code
"B2"}), together with the EPSG identifier
- * (e.g. {@code "EPSG:8641"}) it it exists. See {@link
org.apache.sis.internal.referencing.provider.Affine}
+ * (e.g. {@code "EPSG:8641"}) if it exists. See {@link
org.apache.sis.internal.referencing.provider.Affine}
* for a table summarizing the parameter names and identifiers.
*/
@Override
@@ -117,12 +96,19 @@ final class MatrixParametersEPSG extends
throw new AssertionError();
}
final ParameterDescriptor<Double> wkt =
WKT1.getElementDescriptor(indices); // Really 'WKT1', not 'super'.
+ final GenericName name = first(wkt.getAlias());
+ if (name == null) {
+ /*
+ * Outside the range of names (e.g. more than 26 rows or more than
10 columns).
+ * Returns the OGC name as-is.
+ */
+ return wkt;
+ }
final Map<String,Object> properties = new HashMap<>(6);
properties.put(ParameterDescriptor.NAME_KEY, first(wkt.getAlias()));
properties.put(ParameterDescriptor.ALIAS_KEY, wkt.getName());
/*
- * For the WKT1 convention, create an alias matching the EPSG pattern
("A0", "A1", etc.) for all
- * indices but declare the EPSG authority and identifier only for A0,
A1, A2, B0, B1 and B2.
+ * Declare the EPSG identifier only for A0, A1, A2, B0, B1 and B2.
*/
if (isEPSG(indices)) {
final ImmutableIdentifier id;
@@ -130,7 +116,7 @@ final class MatrixParametersEPSG extends
id = new ImmutableIdentifier(Citations.OGP, Constants.EPSG,
String.valueOf(code));
properties.put(ParameterDescriptor.IDENTIFIERS_KEY, id);
}
- return new DefaultParameterDescriptor<>(properties, 0, 1,
Double.class, null, null, getDefaultValue(indices));
+ return new DefaultParameterDescriptor<>(properties, 0, 1,
Double.class, null, null, wkt.getDefaultValue());
}
/**
@@ -138,6 +124,6 @@ final class MatrixParametersEPSG extends
*/
@Override
Object readResolve() throws ObjectStreamException {
- return EPSG;
+ return equals(ALPHANUM) ? ALPHANUM : this;
}
}
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=1661494&r1=1661493&r2=1661494&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] Sun Feb 22 17:02:00 2015
@@ -41,7 +41,6 @@ import org.apache.sis.referencing.Identi
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.internal.util.UnmodifiableArrayList;
import org.apache.sis.metadata.iso.citation.Citations;
import org.apache.sis.measure.NumberRange;
import org.apache.sis.util.Numbers;
@@ -156,24 +155,54 @@ public class TensorParameters<E> impleme
private static final long serialVersionUID = -7386537348359343836L;
/**
- * Parses and creates matrix parameters with names matching the
<cite>"Affine parametric transformation"</cite>
- * (EPSG:9624) operation method. The matrix size is 3×3 and the parameter
names are {@code "A0"}, {@code "A1"},
- * {@code "A2"}, {@code "B0"}, {@code "B1"} and {@code "B2"} where:
+ * Parses and creates matrix parameters with alphanumeric names.
+ * {@linkplain DefaultParameterDescriptor#getName() Names} are made of a
letter indicating the row
+ * (first row is {@code "A"}), followed by a digit indicating the column
index (first column is {@code "0"}).
+ * {@linkplain DefaultParameterDescriptor#getAlias() Aliases} are the
names as they were defined in version 1
+ * of <cite>Well Known Text</cite> (WKT) format.
+ *
+ * <table class="sis">
+ * <caption>Parameter names for a 3×3 matrix</caption>
+ * <tr>
+ * <th>Primary name</th>
+ * <th class="sep">Alias</th>
+ * </tr>
+ * <tr><td>
+ * {@preformat text
+ * ┌ ┐
+ * │ A0 A1 A2 │
+ * │ B0 B1 B2 │
+ * │ C0 C1 C2 │
+ * └ ┘
+ * }</td><td class="sep">
+ * {@preformat text
+ * ┌ ┐
+ * │ elt_0_0 elt_0_1 elt_0_2 │
+ * │ elt_1_0 elt_1_1 elt_1_2 │
+ * │ elt_2_0 elt_2_1 elt_2_2 │
+ * └ ┘
+ * }</td></tr>
+ * </table>
+ *
+ * {@section Relationship with EPSG}
+ * The above-cited group of parameters are close, but not identical, to
the definitions provided
+ * by the <cite>"Affine general parametric transformation"</cite>
(EPSG:9624) operation method.
+ * The differences are:
*
* <ul>
- * <li>the letter indicates the row (first row is {@code "A"}),
- * <li>the digit is the column index (first column is {@code "0"}).</li>
+ * <li>EPSG:9624 is for matrices of size 3×3 and does not provide any
way to specify the matrix size.
+ * This {@code ALPHANUM} convention extends the definition to
matrices of arbitrary size and accepts
+ * {@code "num_row"} and {@code "num_col"} as optional
parameters.</li>
+ * <li>EPSG:9624 is restricted to affine matrices and consequently
define parameters only for the two
+ * first rows. This class accepts also parameters for the last row
(namely {@code "C0"}, {@code "C1"}
+ * and {@code "C2"} in a 3×3 matrices).</li>
* </ul>
*
- * 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"})
- * as an {@linkplain ParameterDescriptor#getAlias() alias}.</p>
+ * Because of the above-cited extensions, this {@code TensorParameters}
constant can not be named {@code EPSG}.
*
* @since 0.6
*/
- static final TensorParameters<Double> EPSG;
+ public static final TensorParameters<Double> ALPHANUM;
/**
* Parses and creates matrix parameters with names matching the
@@ -223,7 +252,7 @@ public class TensorParameters<E> impleme
0, 1, Integer.class, valueDomain, null, defaultSize);
numCol = new
DefaultParameterDescriptor<>(IdentifiedObjects.getProperties(numCol),
0, 1, Integer.class, valueDomain, null, defaultSize);
- EPSG = new MatrixParametersEPSG(numRow, numCol);
+ ALPHANUM = new MatrixParametersAlphaNum(numRow, numCol);
}
/**
@@ -359,10 +388,23 @@ public class TensorParameters<E> impleme
}
/**
+ * Verifies that the length of the given array is equals to the tensor
rank.
+ */
+ private void verifyRank(final int[] indices) {
+ if (indices.length != rank()) {
+ throw new IllegalArgumentException(Errors.format(
+ Errors.Keys.UnexpectedArrayLength_2, rank(),
indices.length));
+ }
+ }
+
+ /**
* Returns the parameter descriptor for the dimension at the given index.
*
* @param i The dimension index, from 0 inclusive to {@link #rank()}
exclusive.
* @return The parameter descriptor for the dimension at the given index.
+ *
+ * @see #getElementDescriptor(int...)
+ * @see #getAllDescriptors(int...)
*/
public final ParameterDescriptor<Integer> getDimensionDescriptor(final int
i) {
return dimensions[i];
@@ -377,8 +419,12 @@ public class TensorParameters<E> impleme
* @param indices The indices of the tensor element for which to get the
descriptor.
* @return The parameter descriptor for the given tensor element.
* @throws IllegalArgumentException If the given array does not have the
expected length or have illegal value.
+ *
+ * @see #getDimensionDescriptor(int)
+ * @see #getAllDescriptors(int...)
*/
public final ParameterDescriptor<E> getElementDescriptor(final int...
indices) {
+ verifyRank(indices);
final int cacheIndex = cacheIndex(indices);
if (cacheIndex >= 0) {
final ParameterDescriptor<E> param;
@@ -414,6 +460,7 @@ public class TensorParameters<E> impleme
int cacheIndex = 0;
for (int i=0; i<indices.length; i++) {
final int index = indices[i];
+ ArgumentChecks.ensurePositive("indices", index);
if (i < CACHE_RANK) {
if (index >= 0 && index < CACHE_SIZE) {
cacheIndex = (cacheIndex * CACHE_SIZE) + index;
@@ -475,10 +522,7 @@ public class TensorParameters<E> impleme
* @throws IllegalArgumentException If the given array does not have the
expected length or have illegal value.
*/
protected String indicesToName(final int[] indices) throws
IllegalArgumentException {
- if (indices.length != rank()) {
- throw new IllegalArgumentException(Errors.format(
- Errors.Keys.UnexpectedArrayLength_2, rank(),
indices.length));
- }
+ verifyRank(indices);
final StringBuilder name = new StringBuilder();
String s = prefix;
for (final int i : indices) {
@@ -594,39 +638,34 @@ public class TensorParameters<E> impleme
}
/**
- * Returns the number of dimensions (e.g. {@code "num_row"} and {@code
"num_col"}) when formatting the parameter
- * descriptors for a tensor of the given size. This is the {@linkplain
#rank() rank}, except in the special case
- * of {@link #EPSG} with a matrix size matching the expectation of the
standard EPSG:9624 operation method.
+ * Returns the number of elements (e.g. {@code "elt_0_0"}) when formatting
the parameter descriptors
+ * for a tensor of the given size. This is the total number of elements in
the tensor.
*/
- int numDimensions(final int[] actualSize) {
- return actualSize.length;
- }
-
- /**
- * Returns the number of elements (e.g. {@code "elt_0_0"}) when formatting
the parameter descriptors for a tensor
- * of the given size. This is the total number of elements in the tensor,
except for matrices which are intended
- * to be affine (like {@link #EPSG}) where the last row is omitted.
- */
- int numElements(final int[] actualSize) {
- int n = actualSize[0];
- for (int i=1; i<actualSize.length; i++) {
- n *= actualSize[i];
+ private int numElements(final int[] actualSize) {
+ int n = 1;
+ for (int s : actualSize) {
+ ArgumentChecks.ensurePositive("actualSize", s);
+ n *= s;
}
return n;
}
/**
* Returns all parameters in this group for a tensor of the specified
dimensions.
+ * The returned array contains all descriptors returned by {@link
#getDimensionDescriptor(int)}
+ * and {@link #getElementDescriptor(int...)}.
*
- * @param actualSize The current values of parameters that define the
matrix (or tensor) dimensions.
- * It is caller's responsibility to ensure that this array does
not contain negative values.
- * @return The matrix parameters, including all elements.
+ * @param actualSize The matrix (or tensor) dimensions for which to get
the parameters.
+ * @return The tensor parameters, including all elements.
+ *
+ * @see #getDimensionDescriptor(int)
+ * @see #getElementDescriptor(int...)
*/
- final List<GeneralParameterDescriptor> descriptors(final int[] actualSize)
{
- assert actualSize.length == rank();
- final int numDimensions = numDimensions(actualSize);
+ public ParameterDescriptor<?>[] getAllDescriptors(final int... actualSize)
{
+ verifyRank(actualSize);
+ final int numDimensions = actualSize.length;
final int numElements = numElements(actualSize);
- final GeneralParameterDescriptor[] parameters = new
GeneralParameterDescriptor[numDimensions + numElements];
+ final ParameterDescriptor<?>[] parameters = new
ParameterDescriptor<?>[numDimensions + numElements];
System.arraycopy(dimensions, 0, parameters, 0, numDimensions);
final int[] indices = new int[rank()];
/*
@@ -642,7 +681,7 @@ public class TensorParameters<E> impleme
indices[j] = 0; // We have done a full turn at that dimension.
Will increment next dimension.
}
}
- return UnmodifiableArrayList.wrap(parameters);
+ return parameters;
}
/**
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=1661494&r1=1661493&r2=1661494&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] Sun Feb 22 17:02:00 2015
@@ -34,6 +34,7 @@ import org.apache.sis.referencing.Identi
import org.apache.sis.referencing.operation.matrix.Matrices;
import org.apache.sis.internal.referencing.WKTUtilities;
import org.apache.sis.internal.util.Numerics;
+import org.apache.sis.internal.util.UnmodifiableArrayList;
import org.apache.sis.io.wkt.ElementKind;
import org.apache.sis.io.wkt.Formatter;
import org.apache.sis.util.Utilities;
@@ -57,7 +58,7 @@ import org.apache.sis.util.resources.Err
* @version 0.6
* @module
*/
-class TensorValues<E> extends AbstractParameterDescriptor
+final class TensorValues<E> extends AbstractParameterDescriptor
implements ParameterDescriptorGroup, ParameterValueGroup, Cloneable
{
/**
@@ -70,7 +71,7 @@ class TensorValues<E> extends AbstractPa
* {@link ParameterDescriptor}s, even if it does not implement any
standard collection API.
*
* @see TensorParameters#descriptor(ParameterDescriptorGroup, String,
int[])
- * @see TensorParameters#descriptors(int[])
+ * @see TensorParameters#getAllDescriptors(int[])
*/
private final TensorParameters<E> descriptors;
@@ -160,7 +161,7 @@ class TensorValues<E> extends AbstractPa
* the description depends on {@code "num_row"} and {@code "num_col"}
parameter values.
*/
@Override
- public final ParameterDescriptorGroup getDescriptor() {
+ public ParameterDescriptorGroup getDescriptor() {
return this;
}
@@ -169,19 +170,8 @@ class TensorValues<E> extends AbstractPa
* on the value of {@code "num_row"} and {@code "num_col"} parameters.
*/
@Override
- 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;
+ public List<GeneralParameterDescriptor> descriptors() {
+ return
UnmodifiableArrayList.wrap(descriptors.getAllDescriptors(size()));
}
/**
@@ -203,10 +193,10 @@ class TensorValues<E> extends AbstractPa
* @throws ParameterNotFoundException if there is no parameter for the
given name.
*/
@Override
- public final GeneralParameterDescriptor descriptor(String name) throws
ParameterNotFoundException {
+ public GeneralParameterDescriptor descriptor(String name) throws
ParameterNotFoundException {
name = CharSequences.trimWhitespaces(name);
ArgumentChecks.ensureNonEmpty("name", name);
- return provider().descriptor(this, name, size());
+ return descriptors.descriptor(this, name, size());
}
/**
@@ -217,14 +207,13 @@ class TensorValues<E> extends AbstractPa
* @throws ParameterNotFoundException if there is no parameter for the
given name.
*/
@Override
- public final ParameterValue<?> parameter(String name) throws
ParameterNotFoundException {
+ public 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 = provider.nameToIndices(name);
+ indices = descriptors.nameToIndices(name);
} catch (IllegalArgumentException exception) {
cause = exception;
}
@@ -239,9 +228,9 @@ class TensorValues<E> extends AbstractPa
* Verify if the requested parameters is one of those that
* specify the matrix/tensor size ("num_row" or "num_col").
*/
- final int rank = provider.rank();
+ final int rank = descriptors.rank();
for (int i=0; i<rank; i++) {
- final ParameterDescriptor<Integer> param =
provider.getDimensionDescriptor(i);
+ final ParameterDescriptor<Integer> param =
descriptors.getDimensionDescriptor(i);
if (IdentifiedObjects.isHeuristicMatchForName(param, name)) {
return dimensions[i];
}
@@ -299,12 +288,11 @@ class TensorValues<E> extends AbstractPa
parent = (Object[]) element;
element = parent[indices[i]];
}
- final TensorParameters<E> provider = provider();
if (element == null) {
- element = provider.getElementDescriptor(indices).createValue();
+ element = descriptors.getElementDescriptor(indices).createValue();
parent[indices[rank - 1]] = element;
}
- return Parameters.cast((ParameterValue<?>) element,
provider.getElementType());
+ return Parameters.cast((ParameterValue<?>) element,
descriptors.getElementType());
}
/**
@@ -314,7 +302,7 @@ class TensorValues<E> extends AbstractPa
* Never requested elements are left to their default value and omitted
from the returned array.
*/
@Override
- public final List<GeneralParameterValue> values() {
+ public List<GeneralParameterValue> values() {
final List<GeneralParameterValue> addTo = new ArrayList<>();
for (final ParameterValue<Integer> dimension : dimensions) {
if (!isOmitted(dimension)) {
@@ -379,32 +367,6 @@ class TensorValues<E> extends AbstractPa
}
/**
- * 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.
*
@@ -449,7 +411,7 @@ class TensorValues<E> extends AbstractPa
ParameterValue<?>[] row = null;
for (int i=0; i<numCol; i++) {
indices[1] = i;
- ParameterDescriptor<E> descriptor =
provider().getElementDescriptor(indices);
+ ParameterDescriptor<E> descriptor =
descriptors.getElementDescriptor(indices);
final E def = descriptor.getDefaultValue();
final double element = matrix.getElement(j,i);
if (!(def instanceof Number) ||
!Numerics.equalsIgnoreZeroSign(element, ((Number) def).doubleValue())) {
@@ -472,7 +434,7 @@ class TensorValues<E> extends AbstractPa
* Compares this object with the specified one for equality.
*/
@Override
- public final boolean equals(final Object object, final ComparisonMode
mode) {
+ public boolean equals(final Object object, final ComparisonMode mode) {
if (object == this) {
return true; // Slight optimization.
}
@@ -490,7 +452,7 @@ class TensorValues<E> extends AbstractPa
* @return {@inheritDoc}
*/
@Override
- protected final long computeHashCode() {
+ protected long computeHashCode() {
return super.computeHashCode() + descriptors.hashCode();
// Do not use any field other than descriptors, because they are not
immutable.
}
@@ -502,7 +464,7 @@ class TensorValues<E> extends AbstractPa
* @return {@code "ParameterGroup"}.
*/
@Override
- protected final String formatTo(final Formatter formatter) {
+ protected 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/test/java/org/apache/sis/internal/referencing/provider/AffineTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AffineTest.java?rev=1661494&r1=1661493&r2=1661494&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AffineTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AffineTest.java
[UTF-8] Sun Feb 22 17:02:00 2015
@@ -16,11 +16,13 @@
*/
package org.apache.sis.internal.referencing.provider;
+import org.opengis.parameter.ParameterValueGroup;
+import org.apache.sis.referencing.operation.matrix.Matrices;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.apache.sis.test.MetadataAssert.*;
/**
@@ -31,7 +33,7 @@ import static org.junit.Assert.*;
* @version 0.6
* @module
*/
-@DependsOn(org.apache.sis.parameter.MatrixParametersTest.class)
+@DependsOn(org.apache.sis.parameter.TensorValuesTest.class)
public final strictfp class AffineTest extends TestCase {
/**
* Ensures that the {@link Affine#EPSG_INDEX} value is consistent with
@@ -41,4 +43,40 @@ public final strictfp class AffineTest e
public void testEpsgIndex() {
assertEquals("EPSG_INDEX", Affine.cacheIndex(Affine.EPSG_DIMENSION,
Affine.EPSG_DIMENSION), Affine.EPSG_INDEX);
}
+
+ /**
+ * Tests WKT formatting, and in particular the adjustment according
+ * whether we comply with EPSG:9624 definition or not.
+ */
+ public void testWKT() {
+ final ParameterValueGroup matrix =
Affine.parameters(Matrices.createDiagonal(3, 3));
+ 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);
+ }
}
Copied:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixParametersAlphaNumTest.java
(from r1661241,
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/MatrixParametersAlphaNumTest.java?p2=sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixParametersAlphaNumTest.java&p1=sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/MatrixParametersEPSGTest.java&r1=1661241&r2=1661494&rev=1661494&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/MatrixParametersAlphaNumTest.java
[UTF-8] Sun Feb 22 17:02:00 2015
@@ -23,9 +23,8 @@ import static org.apache.sis.test.Assert
/**
- * Tests the {@link MatrixParametersEPSG} class using the {@link
TensorParameters#EPSG} constant.
- * This class inherits all the tests from {@link TensorParametersTest}, but
applies them on a
- * different instance.
+ * Tests the {@link MatrixParametersAlphaNum} class using the {@link
TensorParameters#ALPHANUM} constant.
+ * This class inherits all the tests from {@link TensorParametersTest}, but
applies them on a different instance.
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.6
@@ -33,7 +32,7 @@ import static org.apache.sis.test.Assert
* @module
*/
@DependsOn(MatrixParametersTest.class)
-public final strictfp class MatrixParametersEPSGTest extends
MatrixParametersTest {
+public final strictfp class MatrixParametersAlphaNumTest extends
MatrixParametersTest {
/**
* The expected parameter identifiers for the matrix elements, or 0 if
none.
* Note that the EPSG database contains A3 and B3 parameters, but they are
@@ -49,8 +48,8 @@ public final strictfp class MatrixParame
/**
* Creates a new test case for {@link MatrixParameters}.
*/
- public MatrixParametersEPSGTest() {
- super(TensorParameters.EPSG, ALPHANUM_NAMES, ELEMENT_NAMES,
IDENTIFIERS);
+ public MatrixParametersAlphaNumTest() {
+ super(TensorParameters.ALPHANUM, ALPHANUM_NAMES, ELEMENT_NAMES,
IDENTIFIERS);
}
/**
@@ -82,7 +81,7 @@ public final strictfp class MatrixParame
}
/**
- * Tests {@link MatrixParametersEPSG#indicesToName(int[])}.
+ * Tests {@link MatrixParametersAlphaNum#indicesToName(int[])}.
*/
@Test
@Override
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorParametersTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorParametersTest.java?rev=1661494&r1=1661493&r2=1661494&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorParametersTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorParametersTest.java
[UTF-8] Sun Feb 22 17:02:00 2015
@@ -17,11 +17,9 @@
package org.apache.sis.parameter;
import java.util.Map;
-import java.util.List;
import java.util.Random;
import org.opengis.parameter.ParameterValueGroup;
import org.opengis.parameter.ParameterDescriptor;
-import org.opengis.parameter.GeneralParameterDescriptor;
import org.opengis.referencing.operation.Matrix;
import org.apache.sis.referencing.operation.matrix.Matrices;
import org.apache.sis.test.TestUtilities;
@@ -90,7 +88,7 @@ public strictfp class TensorParametersTe
/**
* The expected parameter identifiers for all matrix elements, or {@code
null} for no identifier.
- * Example: {@link MatrixParametersEPSGTest#IDENTIFIERS}.
+ * Example: {@link MatrixParametersAlphaNum#IDENTIFIERS}.
*/
private final short[][] identifiers;
@@ -144,10 +142,10 @@ public strictfp class TensorParametersTe
* @param actual The actual parameter to verify.
*/
private static void verifyDescriptor(final String name, final Number
defaultValue,
- final GeneralParameterDescriptor actual)
+ final ParameterDescriptor<?> actual)
{
assertEquals("name", name, actual.getName().getCode());
- assertEquals("defaultValue", defaultValue, ((ParameterDescriptor<?>)
actual).getDefaultValue());
+ assertEquals("defaultValue", defaultValue, actual.getDefaultValue());
}
/**
@@ -158,13 +156,13 @@ public strictfp class TensorParametersTe
* @param row Row index of the matrix element to test.
* @param column Column index of the matrix element to test.
*/
- private void verifyDescriptor(final Number defaultValue, final
GeneralParameterDescriptor actual,
+ private void verifyDescriptor(final Number defaultValue, final
ParameterDescriptor<?> actual,
final int row, final int column)
{
assertEquals("name", names[row][column], actual.getName().getCode());
assertAliasTipEquals((aliases != null) ? aliases[row][column] : null,
actual);
assertIdentifierEqualsEPSG((identifiers != null) ?
identifiers[row][column] : 0, actual);
- assertEquals("defaultValue", defaultValue, ((ParameterDescriptor<?>)
actual).getDefaultValue());
+ assertEquals("defaultValue", defaultValue, actual.getDefaultValue());
}
/**
@@ -236,72 +234,65 @@ public strictfp class TensorParametersTe
}
/**
- * Tests {@link TensorParameters#descriptors(int[])} for a 1×1, 2×3 and
3×3 matrices.
+ * Tests {@link TensorParameters#getAllDescriptors(int[])} for a 1×1, 2×3
and 3×3 matrices.
*/
@Test
@DependsOnMethod("testGetElementDescriptor")
- public void testDescriptors() {
- final boolean isEPSG = (identifiers != null);
-
+ public void testGetAllDescriptors() {
final Double N0 = 0.0;
final Double N1 = 1.0;
final Integer N3 = 3;
- List<GeneralParameterDescriptor> descriptors = param.descriptors(new
int[] {1, 1});
- verifyDescriptor(NUM_ROW, N3, descriptors.get(0));
- verifyDescriptor(NUM_COL, N3, descriptors.get(1));
- verifyDescriptor(N1, descriptors.get(2), 0, 0);
- assertEquals("size", 3, descriptors.size());
-
- descriptors = param.descriptors(new int[] {2, 3});
- verifyDescriptor(NUM_ROW, N3, descriptors.get(0));
- verifyDescriptor(NUM_COL, N3, descriptors.get(1));
- verifyDescriptor(N1, descriptors.get(2), 0, 0);
- verifyDescriptor(N0, descriptors.get(3), 0, 1);
- verifyDescriptor(N0, descriptors.get(4), 0, 2);
- verifyDescriptor(N0, descriptors.get(5), 1, 0);
- verifyDescriptor(N1, descriptors.get(6), 1, 1);
- verifyDescriptor(N0, descriptors.get(7), 1, 2);
- assertEquals("size", 8, descriptors.size());
-
- descriptors = param.descriptors(new int[] {3, 3});
- int i = 0;
- if (!isEPSG) {
- verifyDescriptor(NUM_ROW, N3, descriptors.get(i++));
- verifyDescriptor(NUM_COL, N3, descriptors.get(i++));
- }
- verifyDescriptor(N1, descriptors.get(i++), 0, 0);
- verifyDescriptor(N0, descriptors.get(i++), 0, 1);
- verifyDescriptor(N0, descriptors.get(i++), 0, 2);
- verifyDescriptor(N0, descriptors.get(i++), 1, 0);
- verifyDescriptor(N1, descriptors.get(i++), 1, 1);
- verifyDescriptor(N0, descriptors.get(i++), 1, 2);
- if (!isEPSG) {
- verifyDescriptor(N0, descriptors.get(i++), 2, 0);
- verifyDescriptor(N0, descriptors.get(i++), 2, 1);
- verifyDescriptor(N1, descriptors.get(i++), 2, 2);
- }
- assertEquals("size", i, descriptors.size());
-
- descriptors = param.descriptors(new int[] {4, 4});
- verifyDescriptor(NUM_ROW, N3, descriptors.get(0));
- verifyDescriptor(NUM_COL, N3, descriptors.get(1));
- verifyDescriptor(N1, descriptors.get( 2), 0, 0);
- verifyDescriptor(N0, descriptors.get( 3), 0, 1);
- verifyDescriptor(N0, descriptors.get( 4), 0, 2);
- verifyDescriptor(N0, descriptors.get( 5), 0, 3);
- verifyDescriptor(N0, descriptors.get( 6), 1, 0);
- verifyDescriptor(N1, descriptors.get( 7), 1, 1);
- verifyDescriptor(N0, descriptors.get( 8), 1, 2);
- verifyDescriptor(N0, descriptors.get( 9), 1, 3);
- verifyDescriptor(N0, descriptors.get(10), 2, 0);
- verifyDescriptor(N0, descriptors.get(11), 2, 1);
- verifyDescriptor(N1, descriptors.get(12), 2, 2);
- verifyDescriptor(N0, descriptors.get(13), 2, 3);
- verifyDescriptor(N0, descriptors.get(14), 3, 0);
- verifyDescriptor(N0, descriptors.get(15), 3, 1);
- verifyDescriptor(N0, descriptors.get(16), 3, 2);
- verifyDescriptor(N1, descriptors.get(17), 3, 3);
- assertEquals("size", 18, descriptors.size());
+ ParameterDescriptor<?>[] descriptors = param.getAllDescriptors(1, 1);
+ verifyDescriptor(NUM_ROW, N3, descriptors[0]);
+ verifyDescriptor(NUM_COL, N3, descriptors[1]);
+ verifyDescriptor(N1, descriptors[2], 0, 0);
+ assertEquals("size", 3, descriptors.length);
+
+ descriptors = param.getAllDescriptors(2, 3);
+ verifyDescriptor(NUM_ROW, N3, descriptors[0]);
+ verifyDescriptor(NUM_COL, N3, descriptors[1]);
+ verifyDescriptor(N1, descriptors[2], 0, 0);
+ verifyDescriptor(N0, descriptors[3], 0, 1);
+ verifyDescriptor(N0, descriptors[4], 0, 2);
+ verifyDescriptor(N0, descriptors[5], 1, 0);
+ verifyDescriptor(N1, descriptors[6], 1, 1);
+ verifyDescriptor(N0, descriptors[7], 1, 2);
+ assertEquals("size", 8, descriptors.length);
+
+ descriptors = param.getAllDescriptors(3, 3);
+ verifyDescriptor(NUM_ROW, N3, descriptors[0]);
+ verifyDescriptor(NUM_COL, N3, descriptors[1]);
+ verifyDescriptor(N1, descriptors[ 2], 0, 0);
+ verifyDescriptor(N0, descriptors[ 3], 0, 1);
+ verifyDescriptor(N0, descriptors[ 4], 0, 2);
+ verifyDescriptor(N0, descriptors[ 5], 1, 0);
+ verifyDescriptor(N1, descriptors[ 6], 1, 1);
+ verifyDescriptor(N0, descriptors[ 7], 1, 2);
+ verifyDescriptor(N0, descriptors[ 8], 2, 0);
+ verifyDescriptor(N0, descriptors[ 9], 2, 1);
+ verifyDescriptor(N1, descriptors[10], 2, 2);
+ assertEquals("size", 11, descriptors.length);
+
+ descriptors = param.getAllDescriptors(4, 4);
+ verifyDescriptor(NUM_ROW, N3, descriptors[0]);
+ verifyDescriptor(NUM_COL, N3, descriptors[1]);
+ verifyDescriptor(N1, descriptors[ 2], 0, 0);
+ verifyDescriptor(N0, descriptors[ 3], 0, 1);
+ verifyDescriptor(N0, descriptors[ 4], 0, 2);
+ verifyDescriptor(N0, descriptors[ 5], 0, 3);
+ verifyDescriptor(N0, descriptors[ 6], 1, 0);
+ verifyDescriptor(N1, descriptors[ 7], 1, 1);
+ verifyDescriptor(N0, descriptors[ 8], 1, 2);
+ verifyDescriptor(N0, descriptors[ 9], 1, 3);
+ verifyDescriptor(N0, descriptors[10], 2, 0);
+ verifyDescriptor(N0, descriptors[11], 2, 1);
+ verifyDescriptor(N1, descriptors[12], 2, 2);
+ verifyDescriptor(N0, descriptors[13], 2, 3);
+ verifyDescriptor(N0, descriptors[14], 3, 0);
+ verifyDescriptor(N0, descriptors[15], 3, 1);
+ verifyDescriptor(N0, descriptors[16], 3, 2);
+ verifyDescriptor(N1, descriptors[17], 3, 3);
+ assertEquals("size", 18, descriptors.length);
}
/**
@@ -309,7 +300,7 @@ public strictfp class TensorParametersTe
* {@link TensorParameters#toMatrix(ParameterValueGroup)}.
*/
@Test
- @DependsOnMethod("testDescriptors")
+ @DependsOnMethod("testGetAllDescriptors")
public void testMatrixConversion() {
final int size = Math.min(6, TensorParameters.CACHE_SIZE);
final Random random = TestUtilities.createRandomNumberGenerator();
@@ -322,7 +313,7 @@ public strictfp class TensorParametersTe
}
}
final ParameterValueGroup group = param.createValueGroup(
- singletonMap(GeneralParameterDescriptor.NAME_KEY,
"Test"), matrix);
+ singletonMap(ParameterDescriptor.NAME_KEY, "Test"),
matrix);
validate(group);
assertEquals(NUM_ROW, numRow,
group.parameter(NUM_ROW).intValue());
assertEquals(NUM_COL, numCol,
group.parameter(NUM_COL).intValue());
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=1661494&r1=1661493&r2=1661494&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] Sun Feb 22 17:02:00 2015
@@ -63,10 +63,10 @@ public final strictfp class TensorValues
}
/**
- * Creates an instance for a matrix using the EPSG conventions.
+ * Creates an instance for a matrix using the alphanumeric (EPSG)
conventions.
*/
- private static ParameterValueGroup createEPSG() {
- return
TensorParameters.EPSG.createValueGroup(singletonMap(TensorValues.NAME_KEY,
GROUP_NAME));
+ private static ParameterValueGroup createAlphaNumeric() {
+ return
TensorParameters.ALPHANUM.createValueGroup(singletonMap(TensorValues.NAME_KEY,
GROUP_NAME));
}
/**
@@ -100,7 +100,7 @@ public final strictfp class TensorValues
* Tests {@link TensorValues#descriptors()} using WKT1 contentions.
*/
@Test
- public void testDescriptorsWKT1() {
+ public void testDescriptors() {
final Double N0 = 0.0;
final Double N1 = 1.0;
final Integer N3 = 3;
@@ -129,39 +129,28 @@ public final strictfp class TensorValues
}
/**
- * Tests {@link TensorValues#descriptors()} using EPSG contentions.
+ * Tests {@link TensorValues#descriptors()} using alphanumeric (EPSG)
contentions.
*/
@Test
- public void testDescriptorsEPSG() {
+ @DependsOnMethod("testDescriptors")
+ public void testAlphaNumericDescriptors() {
+ final Double N0 = 0.0;
+ final Double N1 = 1.0;
final Integer N3 = 3;
- final ParameterValueGroup group = createEPSG();
- List<GeneralParameterDescriptor> descriptors =
group.getDescriptor().descriptors();
- verifyDescriptorsEPSG(descriptors, 0);
- /*
- * Use non-standard matrix size. The "num_row" and "num_col"
- * parameters shall be included in the list of descriptors.
- */
- group.parameter(NUM_ROW).setValue(2);
- descriptors = group.getDescriptor().descriptors();
+ final ParameterValueGroup group = createAlphaNumeric();
+ final List<GeneralParameterDescriptor> descriptors =
group.getDescriptor().descriptors();
assertDescriptorEquals(NUM_ROW, N3, descriptors.get(0));
assertDescriptorEquals(NUM_COL, N3, descriptors.get(1));
- verifyDescriptorsEPSG(descriptors, 2);
- }
-
- /**
- * Verifies that all remaining elements in the given descriptors, starting
at index <var>i</var>,
- * are A0, A1, A2, B0, B1, B1 parameters.
- */
- private static void verifyDescriptorsEPSG(final
List<GeneralParameterDescriptor> descriptors, int i) {
- final Double N0 = 0.0;
- final Double N1 = 1.0;
- assertDescriptorEquals("A0", N1, descriptors.get(i++));
- assertDescriptorEquals("A1", N0, descriptors.get(i++));
- assertDescriptorEquals("A2", N0, descriptors.get(i++));
- assertDescriptorEquals("B0", N0, descriptors.get(i++));
- assertDescriptorEquals("B1", N1, descriptors.get(i++));
- assertDescriptorEquals("B2", N0, descriptors.get(i++));
- assertEquals("size", i, descriptors.size());
+ assertDescriptorEquals("A0", N1, descriptors.get( 2));
+ assertDescriptorEquals("A1", N0, descriptors.get( 3));
+ assertDescriptorEquals("A2", N0, descriptors.get( 4));
+ assertDescriptorEquals("B0", N0, descriptors.get( 5));
+ assertDescriptorEquals("B1", N1, descriptors.get( 6));
+ assertDescriptorEquals("B2", N0, descriptors.get( 7));
+ assertDescriptorEquals("C0", N0, descriptors.get( 8));
+ assertDescriptorEquals("C1", N0, descriptors.get( 9));
+ assertDescriptorEquals("C2", N1, descriptors.get(10));
+ assertEquals("size", 11, descriptors.size());
}
/**
@@ -324,27 +313,27 @@ public final strictfp class TensorValues
*/
@Test
public void testWKT1() {
- final Matrix matrix = Matrices.createIdentity(4);
+ final Matrix matrix = Matrices.createIdentity(3);
matrix.setElement(0,2, 4);
matrix.setElement(1,0, -2);
- matrix.setElement(2,3, 7);
+ matrix.setElement(2,2, 7);
final ParameterValueGroup group =
TensorParameters.WKT1.createValueGroup(
singletonMap(TensorValues.NAME_KEY, Constants.AFFINE), matrix);
validate(group);
assertWktEquals(
"ParameterGroup[“Affine”,\n" +
- " Parameter[“num_row”, 4],\n" +
- " Parameter[“num_col”, 4],\n" +
+ " Parameter[“num_row”, 3],\n" + // Shall be shown even
if equals to the defautl value.
+ " Parameter[“num_col”, 3],\n" +
" Parameter[“elt_0_2”, 4.0],\n" +
" Parameter[“elt_1_0”, -2.0],\n" +
- " Parameter[“elt_2_3”, 7.0]]", group);
+ " Parameter[“elt_2_2”, 7.0]]", group);
}
/**
- * Tests {@link TensorParameters#EPSG} formatting.
+ * Tests {@link TensorParameters#ALPHANUM} formatting.
* <ul>
* <li>Group name shall be {@code "Affine general parametric
transformation"}.</li>
- * <li>No {@code "num_row"} or {@code "num_col"} parameters.</li>
+ * <li>No {@code "num_row"} or {@code "num_col"} parameters if their
value is equals to 3.</li>
* <li>Parameter names shall be of the form {@code "A0"}.</li>
* <li>Identifiers present, but only for A0-A2 and B0-B2.</li>
* </ul>
@@ -354,15 +343,15 @@ public final strictfp class TensorValues
final Matrix matrix = Matrices.createIdentity(3);
matrix.setElement(0,2, 4);
matrix.setElement(1,0, -2);
- matrix.setElement(2,1, 7);
- final ParameterValueGroup group =
TensorParameters.EPSG.createValueGroup(
+ matrix.setElement(2,2, 7);
+ final ParameterValueGroup group =
TensorParameters.ALPHANUM.createValueGroup(
singletonMap(TensorValues.NAME_KEY, Affine.NAME), matrix);
validate(group);
assertWktEquals(
"ParameterGroup[“Affine general parametric transformation”,\n"
+
" Parameter[“A2”, 4.0, Id[“EPSG”, 8625]],\n" +
" Parameter[“B0”, -2.0, Id[“EPSG”, 8639]],\n" +
- " Parameter[“C1”, 7.0]]", group);
+ " Parameter[“C2”, 7.0]]", group);
}
/**
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=1661494&r1=1661493&r2=1661494&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] Sun Feb 22 17:02:00 2015
@@ -76,9 +76,8 @@ import org.junit.BeforeClass;
org.apache.sis.parameter.ParameterFormatTest.class,
org.apache.sis.parameter.TensorParametersTest.class,
org.apache.sis.parameter.MatrixParametersTest.class,
- org.apache.sis.parameter.MatrixParametersEPSGTest.class,
+ org.apache.sis.parameter.MatrixParametersAlphaNumTest.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,