Copied: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/ProvidersTest.java (from r1738656, sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AllProvidersTest.java) URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/ProvidersTest.java?p2=sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/ProvidersTest.java&p1=sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AllProvidersTest.java&r1=1738656&r2=1738658&rev=1738658&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AllProvidersTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/ProvidersTest.java [UTF-8] Mon Apr 11 22:31:34 2016 @@ -24,6 +24,7 @@ import org.opengis.metadata.Identifier; import org.opengis.parameter.GeneralParameterDescriptor; import org.opengis.parameter.ParameterDescriptorGroup; import org.opengis.referencing.operation.OperationMethod; +import org.apache.sis.referencing.operation.DefaultOperationMethod; import org.apache.sis.test.DependsOn; import org.apache.sis.test.TestCase; import org.junit.Test; @@ -32,7 +33,7 @@ import static org.junit.Assert.*; /** - * Tests all providers defined in this package. + * Tests {@link Providers} and some consistency rules of all providers defined in this package. * * @author Martin Desruisseaux (Geomatys) * @since 0.6 @@ -45,7 +46,7 @@ import static org.junit.Assert.*; LongitudeRotationTest.class, MapProjectionTest.class }) -public final strictfp class AllProvidersTest extends TestCase { +public final strictfp class ProvidersTest extends TestCase { /** * Returns all providers to test. */ @@ -94,11 +95,34 @@ public final strictfp class AllProviders NTv2.class, NADCON.class, FranceGeocentricInterpolation.class, + MolodenskyInterpolation.class, Interpolation1D.class }; } /** + * Returns the subset of {@link #methods()} which are expected to support + * {@link AbstractProvider#redimension(int, int)}. + */ + private static Class<?>[] redimensionables() { + return new Class<?>[] { + Affine.class, + LongitudeRotation.class, + GeographicOffsets.class, + GeographicOffsets2D.class, + CoordinateFrameRotation2D.class, + CoordinateFrameRotation3D.class, + PositionVector7Param2D.class, + PositionVector7Param3D.class, + GeocentricTranslation2D.class, + GeocentricTranslation3D.class, + Molodensky.class, + AbridgedMolodensky.class, + FranceGeocentricInterpolation.class + }; + } + + /** * Ensures that every parameter instance is unique. Actually this test is not strong requirement. * This is only for sharing existing resources by avoiding unnecessary objects duplication. * @@ -151,4 +175,52 @@ public final strictfp class AllProviders } } } + + /** + * Tests {@link AbstractProvider#redimension(int, int)} on all providers managed by {@link Providers}. + */ + @Test + public void testRedimension() { + final Map<Class<?>,Boolean> redimensionables = new HashMap<>(100); + for (final Class<?> type : methods()) { + assertNull(type.getName(), redimensionables.put(type, Boolean.FALSE)); + } + for (final Class<?> type : redimensionables()) { + assertEquals(type.getName(), Boolean.FALSE, redimensionables.put(type, Boolean.TRUE)); + } + final Providers providers = new Providers(); + for (final OperationMethod method : providers) { + if (method instanceof ProviderMock) { + continue; // Skip the methods that were defined only for test purpose. + } + final int sourceDimensions = method.getSourceDimensions(); + final int targetDimensions = method.getTargetDimensions(); + final Boolean isRedimensionable = redimensionables.get(method.getClass()); + assertNotNull(method.getClass().getName(), isRedimensionable); + if (isRedimensionable) { + for (int newSource = 2; newSource <= 3; newSource++) { + for (int newTarget = 2; newTarget <= 3; newTarget++) { + final OperationMethod redim = ((DefaultOperationMethod) method).redimension(newSource, newTarget); + assertEquals("sourceDimensions", newSource, redim.getSourceDimensions().intValue()); + assertEquals("targetDimensions", newTarget, redim.getTargetDimensions().intValue()); + if (!(method instanceof Affine)) { + if (newSource == sourceDimensions && newTarget == targetDimensions) { + assertSame("When asking the original number of dimensions, expected the original instance.", method, redim); + } else { + assertNotSame("When asking a different number of dimensions, expected a different instance.", method, redim); + } + assertSame("When asking the original number of dimensions, expected the original instance.", + method, ((DefaultOperationMethod) redim).redimension(sourceDimensions, targetDimensions)); + } + } + } + } else try { + ((DefaultOperationMethod) method).redimension(sourceDimensions ^ 1, targetDimensions ^ 1); + fail("Type " + method.getClass().getName() + " is not in our list of redimensionable methods."); + } catch (IllegalArgumentException e) { + final String message = e.getMessage(); + assertTrue(message, message.contains(method.getName().getCode())); + } + } + } }
Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/SeismicBinGridMock.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/SeismicBinGridMock.java?rev=1738658&r1=1738657&r2=1738658&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/SeismicBinGridMock.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/SeismicBinGridMock.java [UTF-8] Mon Apr 11 22:31:34 2016 @@ -38,7 +38,7 @@ import org.apache.sis.parameter.Paramete * @module */ @SuppressWarnings("serial") -public final strictfp class SeismicBinGridMock extends MockProvider { +public final strictfp class SeismicBinGridMock extends ProviderMock { /** * The group of all parameters expected by this coordinate operation. */ Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/TopocentricConversionMock.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/TopocentricConversionMock.java?rev=1738658&r1=1738657&r2=1738658&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/TopocentricConversionMock.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/TopocentricConversionMock.java [UTF-8] Mon Apr 11 22:31:34 2016 @@ -36,7 +36,7 @@ import org.apache.sis.parameter.Paramete * @module */ @SuppressWarnings("serial") -public final strictfp class TopocentricConversionMock extends MockProvider { +public final strictfp class TopocentricConversionMock extends ProviderMock { /** * The group of all parameters expected by this coordinate operation. */ Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationRegistryTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationRegistryTest.java?rev=1738658&r1=1738657&r2=1738658&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationRegistryTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationRegistryTest.java [UTF-8] Mon Apr 11 22:31:34 2016 @@ -27,6 +27,7 @@ import org.opengis.referencing.operation import org.opengis.referencing.operation.CoordinateOperation; import org.opengis.referencing.operation.CoordinateOperationAuthorityFactory; import org.opengis.referencing.operation.TransformException; +import org.apache.sis.internal.referencing.Formulas; import org.apache.sis.referencing.CommonCRS; import org.apache.sis.referencing.CRS; import org.apache.sis.io.wkt.WKTFormat; @@ -39,7 +40,6 @@ import org.junit.BeforeClass; import org.junit.AfterClass; import org.junit.Test; -import static org.apache.sis.internal.referencing.Formulas.ANGULAR_TOLERANCE; import static org.apache.sis.test.ReferencingAssert.*; import static org.junit.Assume.*; @@ -158,7 +158,7 @@ public final strictfp class CoordinateOp assertEpsgNameAndIdentifierEqual("NTF (Paris) to WGS 84 (1)", 8094, operation); assertEpsgNameAndIdentifierEqual("NTF (Paris)", 4807, operation.getSourceCRS()); assertEpsgNameAndIdentifierEqual("WGS 84", 4326, operation.getTargetCRS()); - verifyNTF(operation); + verifyNTF(operation, "geog2D domain"); /* * Same test point than the one used in FranceGeocentricInterpolationTest: * @@ -166,7 +166,7 @@ public final strictfp class CoordinateOp * RGF: 48°50′39.9967″N 2°25′29.8273″E (close to WGS84) */ transform = operation.getMathTransform(); - tolerance = ANGULAR_TOLERANCE; + tolerance = Formulas.ANGULAR_TOLERANCE; λDimension = new int[] {1}; verifyTransform(new double[] {54.271680278, 0.098269657}, // in grads east of Paris new double[] {48.844443528, 2.424952028}); // in degrees east of Greenwich @@ -196,10 +196,10 @@ public final strictfp class CoordinateOp final CoordinateReferenceSystem targetCRS = CommonCRS.WGS84.normalizedGeographic(); final CoordinateOperation operation = registry.createOperation(sourceCRS, targetCRS); - verifyNTF(operation); + verifyNTF(operation, "geog2D domain"); transform = operation.getMathTransform(); - tolerance = ANGULAR_TOLERANCE; + tolerance = Formulas.ANGULAR_TOLERANCE; λDimension = new int[] {1}; verifyTransform(new double[] {0.088442691, 48.844512250}, // in degrees east of Paris new double[] {2.424952028, 48.844443528}); // in degrees east of Greenwich @@ -207,9 +207,46 @@ public final strictfp class CoordinateOp } /** + * Tests <cite>"NTF (Paris) to WGS 84 (1)"</cite> operation with three-dimensional source and target CRS. + * {@link CoordinateOperationRegistry} should be able to find the operation despite the difference in + * number of dimensions. + * + * @throws ParseException if a CRS used in this test can not be parsed. + * @throws FactoryException if the operation can not be created. + * @throws TransformException if an error occurred while converting the test points. + */ + @Test + @DependsOnMethod("testLongitudeRotationBetweenConformCRS") + public void testLongitudeRotationBetweenGeographic3D() throws ParseException, FactoryException, TransformException { + final CoordinateReferenceSystem sourceCRS = parse( + "GeodeticCRS[“NTF (Paris)”,\n" + + " $NTF,\n" + + " PrimeMeridian[“Paris”, 2.5969213],\n" + + " CS[ellipsoidal, 3],\n" + + " Axis[“Latitude (φ)”, NORTH, Unit[“grade”, 0.015707963267948967]],\n" + + " Axis[“Longitude (λ)”, EAST, Unit[“grade”, 0.015707963267948967]],\n" + + " Axis[“Height (h)”, UP, Unit[“m”, 1]]]"); + + final CoordinateReferenceSystem targetCRS = CommonCRS.WGS84.geographic3D(); + final CoordinateOperation operation = registry.createOperation(sourceCRS, targetCRS); + verifyNTF(operation, "geog3D domain"); + + transform = operation.getMathTransform(); + tolerance = Formulas.ANGULAR_TOLERANCE; + zTolerance = Formulas.LINEAR_TOLERANCE; + zDimension = new int[] {2}; + λDimension = new int[] {1}; + verifyTransform(new double[] {54.271680278, 0.098269657, 20.00}, // in grads east of Paris + new double[] {48.844443528, 2.424952028, 63.15}); // in degrees east of Greenwich + validate(); + } + + /** * Verifies a coordinate operation which is expected to be <cite>"NTF (Paris) to WGS 84 (1)"</cite> (EPSG:8094). + * + * @param domain either {@code "geog2D domain"} or either {@code "geog3D domain"}. */ - static void verifyNTF(final CoordinateOperation operation) { + static void verifyNTF(final CoordinateOperation operation, final String domain) { assertEquals("name", "NTF (Paris) to WGS 84 (1)", operation.getName().getCode()); assertEquals("sourceCRS.name", "NTF (Paris)", operation.getSourceCRS().getName().getCode()); assertEquals("targetCRS.name", "WGS 84", operation.getTargetCRS().getName().getCode()); @@ -222,11 +259,11 @@ public final strictfp class CoordinateOp final SingleOperation step1 = (SingleOperation) steps.get(0); final SingleOperation step2 = (SingleOperation) steps.get(1); - assertSame("SourceCRS shall be the targetCRS of previous step.", step1.getTargetCRS(), step2.getSourceCRS()); - assertEquals("Step 1", "NTF (Paris) to NTF (1)", step1.getName().getCode()); - assertEquals("Step 2", "NTF to WGS 84 (1)", step2.getName().getCode()); - assertEquals("Method 1", "Longitude rotation", step1.getMethod().getName().getCode()); - assertEquals("Method 2", "Geocentric translations (geog2D domain)", step2.getMethod().getName().getCode()); + assertSame("SourceCRS shall be the targetCRS of previous step.", step1.getTargetCRS(), step2.getSourceCRS()); + assertEquals("Step 1", "NTF (Paris) to NTF (1)", step1.getName().getCode()); + assertEquals("Step 2", "NTF to WGS 84 (1)", step2.getName().getCode()); + assertEquals("Method 1", "Longitude rotation", step1.getMethod().getName().getCode()); + assertEquals("Method 2", "Geocentric translations (" + domain + ')', step2.getMethod().getName().getCode()); final ParameterValueGroup p1 = step1.getParameterValues(); final ParameterValueGroup p2 = step2.getParameterValues(); Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java?rev=1738658&r1=1738657&r2=1738658&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java [UTF-8] Mon Apr 11 22:31:34 2016 @@ -62,7 +62,7 @@ import static org.opengis.test.Assert.*; * @module */ @DependsOn({ - org.apache.sis.internal.referencing.provider.AllProvidersTest.class, + org.apache.sis.internal.referencing.provider.ProvidersTest.class, OperationMethodSetTest.class }) public final strictfp class DefaultMathTransformFactoryTest extends TestCase { 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=1738658&r1=1738657&r2=1738658&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] Mon Apr 11 22:31:34 2016 @@ -148,7 +148,7 @@ import org.junit.BeforeClass; org.apache.sis.internal.referencing.provider.NADCONTest.class, org.apache.sis.internal.referencing.provider.MapProjectionTest.class, org.apache.sis.internal.referencing.provider.TransverseMercatorTest.class, - org.apache.sis.internal.referencing.provider.AllProvidersTest.class, + org.apache.sis.internal.referencing.provider.ProvidersTest.class, org.apache.sis.referencing.operation.transform.InterpolatedTransformTest.class, org.apache.sis.referencing.operation.transform.InterpolatedGeocentricTransformTest.class, org.apache.sis.referencing.operation.transform.InterpolatedMolodenskyTransformTest.class, Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java?rev=1738658&r1=1738657&r2=1738658&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java [UTF-8] Mon Apr 11 22:31:34 2016 @@ -16,8 +16,10 @@ */ package org.apache.sis.internal.util; +import java.util.List; import java.util.Arrays; import java.util.Iterator; +import java.util.ServiceLoader; import java.util.NoSuchElementException; import org.apache.sis.util.Workaround; @@ -35,7 +37,8 @@ import java.util.Objects; * a new iteration. See * {@link org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory#DefaultMathTransformFactory()}.</p> * - * <p>Another usage for this class is to prepend some values before the elements given by the source {@code Iterable}.</p> + * <p>Some usages for this class are to prepend some values before the elements given by the source {@code Iterable}, + * or to replace some values when they are loaded.</p> * * <p>This class is not thread-safe. Synchronization, if desired, shall be done by the caller.</p> * @@ -49,9 +52,9 @@ import java.util.Objects; @Workaround(library="JDK", version="1.8.0_31-b13") public class LazySet<E> extends SetOfUnknownSize<E> { /** - * The original source of elements, or {@code null} if unknown. + * The type of service to request with {@link ServiceLoader}, or {@code null} if unknown. */ - private final Iterable<? extends E> source; + private final Class<E> service; /** * The iterator to use for filling this set, or {@code null} if the iteration did not started yet @@ -82,11 +85,11 @@ public class LazySet<E> extends SetOfUnk * only when first needed, and at most one iteration will be performed (unless {@link #reload()} * is invoked). * - * @param source The source of elements to use for filling this set. + * @param service the type of service to request with {@link ServiceLoader}, or {@code null} if unknown. */ - public LazySet(final Iterable<? extends E> source) { - Objects.requireNonNull(source); - this.source = source; + public LazySet(final Class<E> service) { + Objects.requireNonNull(service); + this.service = service; } /** @@ -98,23 +101,19 @@ public class LazySet<E> extends SetOfUnk public LazySet(final Iterator<? extends E> iterator) { Objects.requireNonNull(iterator); sourceIterator = iterator; - source = null; + service = null; createCache(); } /** * Notifies this {@code LazySet} that it should re-fetch the elements from the source given at construction time. - * This method does not verify if the source needs also to be reloaded; it is up to the caller to verify. - * - * @return The original source of elements, or {@code null} if unknown. */ - public Iterable<? extends E> reload() { - if (source != null) { + public void reload() { + if (service != null) { sourceIterator = null; cachedElements = null; numCached = 0; } - return source; } /** @@ -156,7 +155,7 @@ public class LazySet<E> extends SetOfUnk */ private boolean canPullMore() { if (sourceIterator == null && cachedElements == null) { - sourceIterator = source.iterator(); + sourceIterator = ServiceLoader.load(service).iterator(); if (createCache()) { return true; } @@ -198,11 +197,12 @@ public class LazySet<E> extends SetOfUnk } /** - * Adds the given element to the {@link #cachedElements} array. + * Caches a new element. Subclasses can override this method is they want to substitute the given value + * by another value. * * @param element The element to add to the cache. */ - private void cache(final E element) { + protected void cache(final E element) { if (numCached >= cachedElements.length) { cachedElements = Arrays.copyOf(cachedElements, numCached << 1); } @@ -210,6 +210,16 @@ public class LazySet<E> extends SetOfUnk } /** + * Returns an unmodifiable view over the elements cached so far. + * The returned list does not contain any elements that were not yet fetched from the source. + * + * @return the elements cached so far. + */ + protected final List<E> cached() { + return UnmodifiableArrayList.wrap(cachedElements, 0, numCached); + } + + /** * Returns {@code true} if an element exists at the given index. * The element is not loaded immediately. * Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/LazySetTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/LazySetTest.java?rev=1738658&r1=1738657&r2=1738658&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/LazySetTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/LazySetTest.java [UTF-8] Mon Apr 11 22:31:34 2016 @@ -43,7 +43,7 @@ public final strictfp class LazySetTest * Creates the set to use for testing purpose. */ private static LazySet<String> create() { - return new LazySet<>(Arrays.asList(LABELS)); + return new LazySet<>(Arrays.asList(LABELS).iterator()); } /**
