Author: desruisseaux
Date: Sun Mar 27 20:24:40 2016
New Revision: 1736815
URL: http://svn.apache.org/viewvc?rev=1736815&view=rev
Log:
Add more tests and debug CoordinateOperationInference.
Added:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/InverseOperationMethod.java
(with props)
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/AbstractProvider.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/internal/referencing/provider/GeocentricAffine.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicOffsets.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Properties.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationInference.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationInferenceTest.java
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/AbstractProvider.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/AbstractProvider.java?rev=1736815&r1=1736814&r2=1736815&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/AbstractProvider.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/AbstractProvider.java
[UTF-8] Sun Mar 27 20:24:40 2016
@@ -214,4 +214,14 @@ public abstract class AbstractProvider e
public int getEllipsoidsMask() {
return 0;
}
+
+ /**
+ * Returns {@code true} if the inverse of this operation method is the
same operation method with some parameter
+ * values changed (typically with sign inverted). The default
implementation returns {@code false}.
+ *
+ * @return {@code true} if the inverse of this operation method can be
described by the same operation method.
+ */
+ public boolean isInvertible() {
+ return false;
+ }
}
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=1736815&r1=1736814&r2=1736815&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 Mar 27 20:24:40 2016
@@ -179,6 +179,16 @@ public final class Affine extends Abstra
*/
/**
+ * The inverse of this operation can be described by the same operation
with different parameter values.
+ *
+ * @return {@code true} for all {@code Affine}.
+ */
+ @Override
+ public final boolean isInvertible() {
+ return true;
+ }
+
+ /**
* Creates a projective transform from the specified group of parameter
values.
*
* @param factory Ignored (can be null).
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeocentricAffine.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeocentricAffine.java?rev=1736815&r1=1736814&r2=1736815&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeocentricAffine.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeocentricAffine.java
[UTF-8] Sun Mar 27 20:24:40 2016
@@ -177,6 +177,16 @@ public abstract class GeocentricAffine e
abstract int getType();
/**
+ * The inverse of this operation is the same operation with parameter
signs inverted.
+ *
+ * @return {@code true} for all {@code GeocentricAffine}.
+ */
+ @Override
+ public final boolean isInvertible() {
+ return true;
+ }
+
+ /**
* Creates a math transform from the specified group of parameter values.
* The default implementation creates an affine transform, but some
subclasses
* will wrap that affine operation into Geographic/Geocentric conversions.
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicOffsets.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicOffsets.java?rev=1736815&r1=1736814&r2=1736815&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicOffsets.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicOffsets.java
[UTF-8] Sun Mar 27 20:24:40 2016
@@ -101,6 +101,16 @@ public class GeographicOffsets extends A
}
/**
+ * The inverse of this operation is the same operation with parameter
signs inverted.
+ *
+ * @return {@code true} for all {@code GeocentricAffine}.
+ */
+ @Override
+ public final boolean isInvertible() {
+ return true;
+ }
+
+ /**
* Creates a transform from the specified group of parameter values.
* The parameter values are unconditionally converted to degrees and
metres.
*
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java?rev=1736815&r1=1736814&r2=1736815&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java
[UTF-8] Sun Mar 27 20:24:40 2016
@@ -90,6 +90,10 @@ public final class IdentifiedObjects ext
* <td>{@link CoordinateOperation#getOperationVersion()}</td></tr>
* <tr><td>{@value
org.opengis.referencing.operation.CoordinateOperation#COORDINATE_OPERATION_ACCURACY_KEY}</td>
* <td>{@link
CoordinateOperation#getCoordinateOperationAccuracy()}</td></tr>
+ * <tr><td>{@value
org.opengis.referencing.operation.OperationMethod#FORMULA_KEY}</td>
+ * <td>{@link
org.opengis.referencing.operation.OperationMethod#getFormula()}</td></tr>
+ * <tr><td>{@value
org.apache.sis.referencing.AbstractIdentifiedObject#DEPRECATED_KEY}</td>
+ * <td>{@link AbstractIdentifiedObject#isDeprecated()}</td></tr>
* </table>
*
* <div class="note"><b>Note:</b>
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Properties.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Properties.java?rev=1736815&r1=1736814&r2=1736815&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Properties.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Properties.java
[UTF-8] Sun Mar 27 20:24:40 2016
@@ -26,8 +26,10 @@ import org.opengis.referencing.datum.Dat
import org.opengis.referencing.ReferenceSystem;
import org.opengis.referencing.IdentifiedObject;
import org.opengis.referencing.operation.CoordinateOperation;
+import org.opengis.referencing.operation.OperationMethod;
import org.opengis.metadata.quality.PositionalAccuracy;
import org.apache.sis.internal.util.AbstractMap;
+import org.apache.sis.util.Deprecable;
/**
@@ -40,7 +42,7 @@ import org.apache.sis.internal.util.Abst
*
* @author Martin Desruisseaux (IRD)
* @since 0.4
- * @version 0.4
+ * @version 0.7
* @module
*/
final class Properties extends AbstractMap<String,Object> implements
Serializable {
@@ -55,14 +57,16 @@ final class Properties extends AbstractM
* of {@link #INDICES}.
*/
private static final String[] KEYS = {
- /*[0]*/ IdentifiedObject .NAME_KEY,
- /*[1]*/ IdentifiedObject .IDENTIFIERS_KEY,
- /*[2]*/ IdentifiedObject .ALIAS_KEY,
- /*[3]*/ IdentifiedObject .REMARKS_KEY,
- /*[4]*/ CoordinateOperation .SCOPE_KEY, // same in Datum
and ReferenceSystem
- /*[5]*/ CoordinateOperation .DOMAIN_OF_VALIDITY_KEY, // same in Datum
and ReferenceSystem
- /*[6]*/ CoordinateOperation .OPERATION_VERSION_KEY,
- /*[7]*/ CoordinateOperation .COORDINATE_OPERATION_ACCURACY_KEY
+ /*[0]*/ IdentifiedObject .NAME_KEY,
+ /*[1]*/ IdentifiedObject .IDENTIFIERS_KEY,
+ /*[2]*/ IdentifiedObject .ALIAS_KEY,
+ /*[3]*/ IdentifiedObject .REMARKS_KEY,
+ /*[4]*/ CoordinateOperation .SCOPE_KEY, //
same in Datum and ReferenceSystem
+ /*[5]*/ CoordinateOperation .DOMAIN_OF_VALIDITY_KEY, //
same in Datum and ReferenceSystem
+ /*[6]*/ CoordinateOperation .OPERATION_VERSION_KEY,
+ /*[7]*/ CoordinateOperation .COORDINATE_OPERATION_ACCURACY_KEY,
+ /*[8]*/ OperationMethod .FORMULA_KEY,
+ /*[9]*/ AbstractIdentifiedObject.DEPRECATED_KEY
/*
* The current implementation does not look for minimum and maximum
values in ParameterDescriptor
@@ -182,6 +186,18 @@ final class Properties extends AbstractM
}
break;
}
+ case 8: { // FORMULA_KEY
+ if (object instanceof OperationMethod) {
+ return ((OperationMethod) object).getFormula();
+ }
+ break;
+ }
+ case 9: { // DEPRECATED_KEY
+ if (object instanceof Deprecable) {
+ return ((Deprecable) object).isDeprecated();
+ }
+ break;
+ }
default: throw new AssertionError(key);
}
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java?rev=1736815&r1=1736814&r2=1736815&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
[UTF-8] Sun Mar 27 20:24:40 2016
@@ -651,16 +651,29 @@ check: for (int isTarget=0; ; isTar
* {@linkplain #transform}, if possible. If no descriptor can be inferred
from the math transform,
* then this method fallback on the {@link OperationMethod} parameters.
*/
- ParameterDescriptorGroup getParameterDescriptors() throws
UnsupportedOperationException {
- MathTransform mt = transform;
- while (mt != null) {
- if (mt instanceof Parameterized) {
+ ParameterDescriptorGroup getParameterDescriptors() {
+ ParameterDescriptorGroup descriptor =
getParameterDescriptors(transform);
+ if (descriptor == null) {
+ final OperationMethod method = getMethod();
+ if (method != null) {
+ descriptor = method.getParameters();
+ }
+ }
+ return descriptor;
+ }
+
+ /**
+ * Returns the parameter descriptors for the given transform, or {@code
null} if unknown.
+ */
+ static ParameterDescriptorGroup getParameterDescriptors(MathTransform
transform) {
+ while (transform != null) {
+ if (transform instanceof Parameterized) {
final ParameterDescriptorGroup param;
if (Semaphores.queryAndSet(Semaphores.ENCLOSED_IN_OPERATION)) {
- throw new AssertionError(); // Should never happen.
+ throw new AssertionError();
// Should never happen.
}
try {
- param = ((Parameterized) mt).getParameterDescriptors();
+ param = ((Parameterized)
transform).getParameterDescriptors();
} finally {
Semaphores.clear(Semaphores.ENCLOSED_IN_OPERATION);
}
@@ -668,14 +681,13 @@ check: for (int isTarget=0; ; isTar
return param;
}
}
- if (mt instanceof PassThroughTransform) {
- mt = ((PassThroughTransform) mt).getSubTransform();
+ if (transform instanceof PassThroughTransform) {
+ transform = ((PassThroughTransform)
transform).getSubTransform();
} else {
break;
}
}
- final OperationMethod method = getMethod();
- return (method != null) ? method.getParameters() : null;
+ return null;
}
/**
@@ -686,13 +698,13 @@ check: for (int isTarget=0; ; isTar
* @throws UnsupportedOperationException if the parameter values can not
* be determined for the current math transform implementation.
*/
- ParameterValueGroup getParameterValues() {
+ ParameterValueGroup getParameterValues() throws
UnsupportedOperationException {
MathTransform mt = transform;
while (mt != null) {
if (mt instanceof Parameterized) {
final ParameterValueGroup param;
if (Semaphores.queryAndSet(Semaphores.ENCLOSED_IN_OPERATION)) {
- throw new AssertionError(); // Should never happen.
+ throw new AssertionError();
// Should never happen.
}
try {
param = ((Parameterized) mt).getParameterValues();
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationInference.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationInference.java?rev=1736815&r1=1736814&r2=1736815&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationInference.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationInference.java
[UTF-8] Sun Mar 27 20:24:40 2016
@@ -46,7 +46,6 @@ import org.apache.sis.internal.util.Cons
import org.apache.sis.measure.Units;
import org.apache.sis.metadata.iso.citation.Citations;
import org.apache.sis.metadata.iso.extent.Extents;
-import org.apache.sis.parameter.Parameterized;
import org.apache.sis.parameter.TensorParameters;
import org.apache.sis.referencing.CRS;
import org.apache.sis.referencing.CommonCRS;
@@ -334,8 +333,9 @@ public class CoordinateOperationInferenc
final GeneralDerivedCRS
targetCRS)
throws FactoryException
{
- CoordinateOperation step1 = createOperation(sourceCRS,
targetCRS.getBaseCRS());
- return concatenate(step1, targetCRS.getConversionFromBase());
+ final CoordinateOperation step1 = createOperation(sourceCRS,
targetCRS.getBaseCRS());
+ final CoordinateOperation step2 = targetCRS.getConversionFromBase();
+ return concatenate(step1, step2);
}
/**
@@ -358,16 +358,9 @@ public class CoordinateOperationInferenc
final SingleCRS
targetCRS)
throws FactoryException
{
- final SingleCRS base = sourceCRS.getBaseCRS();
- CoordinateOperation step2 = createOperation(base, targetCRS);
- CoordinateOperation step1 = sourceCRS.getConversionFromBase();
- MathTransform transform = step1.getMathTransform();
- try {
- transform = transform.inverse();
- } catch (NoninvertibleTransformException exception) {
- throw new OperationNotFoundException(notFoundMessage(sourceCRS,
base), exception);
- }
- step1 = createFromMathTransform(properties(INVERSE_OPERATION),
sourceCRS, base, transform, null, null);
+ // Create first the operation that is more at risk to fail.
+ final CoordinateOperation step2 =
createOperation(sourceCRS.getBaseCRS(), targetCRS);
+ final CoordinateOperation step1 =
inverse(sourceCRS.getConversionFromBase());
return concatenate(step1, step2);
}
@@ -390,11 +383,11 @@ public class CoordinateOperationInferenc
final GeneralDerivedCRS
targetCRS)
throws FactoryException
{
- final SingleCRS sourceBase = sourceCRS.getBaseCRS();
- final SingleCRS targetBase = targetCRS.getBaseCRS();
- return concatenate(createOperation(sourceCRS, sourceBase),
- createOperation(sourceBase, targetBase),
- createOperation(targetBase, targetCRS));
+ // Create first the operations that are more at risk to fail.
+ final CoordinateOperation step2 =
createOperation(sourceCRS.getBaseCRS(), targetCRS.getBaseCRS());
+ final CoordinateOperation step1 =
inverse(sourceCRS.getConversionFromBase());
+ final CoordinateOperation step3 = targetCRS.getConversionFromBase();
+ return concatenate(step1, step2, step3);
}
/**
@@ -661,13 +654,14 @@ public class CoordinateOperationInferenc
* the {@code name} identifier was {@link #DATUM_SHIFT} or {@link
#ELLIPSOID_CHANGE}.</li>
*
* <li>If the given {@code method} is {@code null}, then infer an
operation method by inspecting the given transform.
- * The transform needs to implement the {@link Parameterized}
interface in order to allow operation method discovery.</li>
+ * The transform needs to implement the {@link
org.apache.sis.parameter.Parameterized} interface in order to allow
+ * operation method discovery.</li>
*
* <li>Delegate to {@link
DefaultCoordinateOperationFactory#createSingleOperation
* DefaultCoordinateOperationFactory.createSingleOperation(…)}.</li>
* </ul>
*
- * @param properties The properties to give to the operation.
+ * @param properties The properties to give to the operation, as a
modifiable map.
* @param sourceCRS The source coordinate reference system.
* @param targetCRS The destination coordinate reference system.
* @param transform The math transform.
@@ -676,7 +670,7 @@ public class CoordinateOperationInferenc
* @return A coordinate operation using the specified math transform.
* @throws FactoryException if the operation can not be created.
*/
- private CoordinateOperation createFromMathTransform(final Map<String,?>
properties,
+ private CoordinateOperation createFromMathTransform(final
Map<String,Object> properties,
final
CoordinateReferenceSystem sourceCRS,
final
CoordinateReferenceSystem targetCRS,
final MathTransform
transform,
@@ -716,8 +710,8 @@ public class CoordinateOperationInferenc
final Matrix matrix = MathTransforms.getMatrix(transform);
if (matrix != null) {
method = Affine.getProvider(transform.getSourceDimensions(),
transform.getTargetDimensions(), Matrices.isAffine(matrix));
- } else if (transform instanceof Parameterized) {
- final ParameterDescriptorGroup descriptor = ((Parameterized)
transform).getParameterDescriptors();
+ } else {
+ final ParameterDescriptorGroup descriptor =
AbstractCoordinateOperation.getParameterDescriptors(transform);
if (descriptor != null) {
final Identifier name = descriptor.getName();
if (name != null) {
@@ -732,9 +726,24 @@ public class CoordinateOperationInferenc
}
}
}
- final Map<String,Object> p = new HashMap<>(properties);
- p.put(ReferencingServices.OPERATION_TYPE_KEY, type);
- return factorySIS.createSingleOperation(p, sourceCRS, targetCRS, null,
method, transform);
+ properties.put(ReferencingServices.OPERATION_TYPE_KEY, type);
+ return factorySIS.createSingleOperation(properties, sourceCRS,
targetCRS, null, method, transform);
+ }
+
+ /**
+ * Creates the inverse of the given operation.
+ */
+ private CoordinateOperation inverse(final SingleOperation op) throws
FactoryException {
+ final CoordinateReferenceSystem sourceCRS = op.getSourceCRS();
+ final CoordinateReferenceSystem targetCRS = op.getTargetCRS();
+ MathTransform transform = op.getMathTransform();
+ try {
+ transform = transform.inverse();
+ } catch (NoninvertibleTransformException exception) {
+ throw new OperationNotFoundException(notFoundMessage(targetCRS,
sourceCRS), exception);
+ }
+ return createFromMathTransform(properties(INVERSE_OPERATION),
targetCRS, sourceCRS,
+ transform, InverseOperationMethod.create(op.getMethod()),
null);
}
/**
@@ -770,7 +779,7 @@ public class CoordinateOperationInferenc
* dimensions in order to avoid mismatch with the method's
dimensions.
*/
final MathTransformFactory mtFactory =
factorySIS.getMathTransformFactory();
- return
createFromMathTransform(IdentifiedObjects.getProperties(step),
+ return createFromMathTransform(new
HashMap<>(IdentifiedObjects.getProperties(step)),
sourceCRS, targetCRS,
mtFactory.createConcatenatedTransform(mt1, mt2),
((SingleOperation) step).getMethod(),
SingleOperation.class);
}
@@ -822,17 +831,17 @@ public class CoordinateOperationInferenc
* However, we noticed that the EPSG database do not always defines a
version neither.
* Consequently, the Apache SIS implementation relaxes the rule requiring
an operation
* version and we do not try to provide this information here for
now.</div>
+ *
+ * @param name The name to put in a map.
+ * @return a modifiable map containing the given name. Callers can put
other entries in this map.
*/
private static Map<String,Object> properties(final Identifier name) {
- final Map<String,Object> properties;
+ final Map<String,Object> properties = new HashMap<>(4);
+ properties.put(CoordinateOperation.NAME_KEY, name);
if ((name == DATUM_SHIFT) || (name == ELLIPSOID_CHANGE)) {
- properties = new HashMap<>(4);
- properties.put(CoordinateOperation.NAME_KEY, name);
properties.put(CoordinateOperation.COORDINATE_OPERATION_ACCURACY_KEY, new
PositionalAccuracy[] {
(name == DATUM_SHIFT) ?
PositionalAccuracyConstant.DATUM_SHIFT_APPLIED
:
PositionalAccuracyConstant.DATUM_SHIFT_OMITTED});
- } else {
- properties =
Collections.singletonMap(CoordinateOperation.NAME_KEY, name);
}
return properties;
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java?rev=1736815&r1=1736814&r2=1736815&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
[UTF-8] Sun Mar 27 20:24:40 2016
@@ -450,7 +450,7 @@ next: for (int i=components.size(); --
}
if (method instanceof DefaultOperationMethod) {
final Class<? extends SingleOperation> c =
((DefaultOperationMethod) method).getOperationType();
- if (c != null) { // Paranoiac check (above method should not
return null).
+ if (c != null) { // Paranoiac check (above
method should not return null).
if (baseType.isAssignableFrom(c)) {
baseType = c;
} else if (!c.isAssignableFrom(baseType)) {
Added:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/InverseOperationMethod.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/InverseOperationMethod.java?rev=1736815&view=auto
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/InverseOperationMethod.java
(added)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/InverseOperationMethod.java
[UTF-8] Sun Mar 27 20:24:40 2016
@@ -0,0 +1,79 @@
+/*
+ * 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.referencing.operation;
+
+import java.util.Map;
+import java.util.HashMap;
+import javax.xml.bind.annotation.XmlTransient;
+import org.opengis.metadata.Identifier;
+import org.opengis.referencing.operation.OperationMethod;
+import org.apache.sis.internal.referencing.provider.AbstractProvider;
+import org.apache.sis.metadata.iso.ImmutableIdentifier;
+import org.apache.sis.util.Deprecable;
+
+
+/**
+ * Description of the inverse of another method. This class should be used
only when no operation is defined
+ * for the inverse, or when the inverse operation can not be represented by
inverting the sign of parameters.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.7
+ * @version 0.7
+ * @module
+ */
+@XmlTransient
+final class InverseOperationMethod extends DefaultOperationMethod {
+ /**
+ * For cross-version compatibility.
+ */
+ private static final long serialVersionUID = 6395008927817202180L;
+
+ /**
+ * The original operation method for which this {@code
InverseOperationMethod} is the inverse.
+ */
+ private final OperationMethod inverse;
+
+ /**
+ * Creates the inverse of the given method.
+ */
+ private InverseOperationMethod(final Map<String,?> properties, final
OperationMethod method) {
+ super(properties, method.getTargetDimensions(),
method.getSourceDimensions(), method.getParameters());
+ inverse = method;
+ }
+
+ /**
+ * Returns or create the inverse of the given operation method.
+ */
+ static OperationMethod create(final OperationMethod method) {
+ if (method instanceof InverseOperationMethod) {
+ return ((InverseOperationMethod) method).inverse;
+ }
+ if (method instanceof AbstractProvider && ((AbstractProvider)
method).isInvertible()) {
+ return method;
+ }
+ Identifier name = method.getName();
+ name = new ImmutableIdentifier(null, name.getCodeSpace(), "Inverse " +
name.getCode());
+ final Map<String,Object> properties = new HashMap<>(6);
+ properties.put(NAME_KEY, name);
+ properties.put(FORMULA_KEY, method.getFormula());
+ properties.put(REMARKS_KEY, method.getRemarks());
+ if (method instanceof Deprecable) {
+ properties.put(DEPRECATED_KEY, ((Deprecable)
method).isDeprecated());
+ }
+ return new InverseOperationMethod(properties, method);
+ }
+}
Propchange:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/InverseOperationMethod.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/InverseOperationMethod.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java?rev=1736815&r1=1736814&r2=1736815&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java
[UTF-8] Sun Mar 27 20:24:40 2016
@@ -300,9 +300,9 @@ public final strictfp class BuilderTest
assertNull(properties.put(AbstractIdentifiedObject.REMARKS_KEY,
"Some remarks"));
final BuilderMock builder = new BuilderMock(new
AbstractIdentifiedObject(properties));
- assertEquals("Expected only name and remarks.", 2,
builder.properties.size());
+ assertEquals("Expected only name, remarks and deprecated status.", 3,
builder.properties.size());
builder.onCreate(false);
- assertEquals("Expected name, aliases, identifiers and remarks.", 4,
builder.properties.size());
+ assertEquals("Expected name, aliases, identifiers and remarks.", 5,
builder.properties.size());
assertEquals(AbstractIdentifiedObject.NAME_KEY, "Dummy object",
builder.properties.get(AbstractIdentifiedObject.NAME_KEY).toString());
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationInferenceTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationInferenceTest.java?rev=1736815&r1=1736814&r2=1736815&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationInferenceTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationInferenceTest.java
[UTF-8] Sun Mar 27 20:24:40 2016
@@ -76,8 +76,18 @@ public final strictfp class CoordinateOp
*/
@Test
public void testIdentityTransform() throws FactoryException {
- CoordinateReferenceSystem crs = CommonCRS.WGS84.normalizedGeographic();
- CoordinateOperation operation = factory.createOperation(crs, crs);
+ testIdentityTransform(CommonCRS.WGS84.geographic());
+ testIdentityTransform(CommonCRS.WGS84.geographic3D());
+ testIdentityTransform(CommonCRS.WGS84.geocentric());
+ testIdentityTransform(CommonCRS.WGS84.spherical());
+ testIdentityTransform(CommonCRS.WGS84.UTM(0, 0));
+ }
+
+ /**
+ * Implementation of {@link #testIdentityTransform()} using the given CRS.
+ */
+ private static void testIdentityTransform(final CoordinateReferenceSystem
crs) throws FactoryException {
+ final CoordinateOperation operation = factory.createOperation(crs,
crs);
assertSame("sourceCRS", crs, operation.getSourceCRS());
assertSame("targetCRS", crs, operation.getTargetCRS());
assertTrue("isIdentity", operation.getMathTransform().isIdentity());