sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1726714 [3/3] - in /sis/branches/JDK8: core/sis-referencing/src/main/java/org/apache/sis/referencing/ core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ core/sis-referencing/src/main/java/org/apache/sis/referencing/oper...
Date Tue, 26 Jan 2016 00:02:36 GMT
Added: sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.crs.CRSAuthorityFactory
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.crs.CRSAuthorityFactory?rev=1726714&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.crs.CRSAuthorityFactory
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.crs.CRSAuthorityFactory
[UTF-8] Tue Jan 26 00:02:35 2016
@@ -0,0 +1,2 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more contributor license
agreements.
+org.apache.sis.referencing.factory.CommonAuthorityFactory

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.crs.CRSAuthorityFactory
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.crs.CRSAuthorityFactory
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java?rev=1726714&r1=1726713&r2=1726714&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
[UTF-8] Tue Jan 26 00:02:35 2016
@@ -22,6 +22,10 @@ import org.opengis.referencing.crs.Singl
 import org.opengis.util.FactoryException;
 import org.apache.sis.referencing.crs.DefaultCompoundCRS;
 import org.apache.sis.referencing.crs.HardCodedCRS;
+import org.apache.sis.util.ComparisonMode;
+import org.apache.sis.util.Utilities;
+
+// Test imports
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
@@ -35,7 +39,7 @@ import static org.apache.sis.test.Assert
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.5
+ * @version 0.7
  * @module
  */
 @DependsOn({
@@ -46,7 +50,7 @@ public final strictfp class CRSTest exte
      * Asserts that the result of {@link CRS#forCode(String)} is the given CRS.
      */
     private static void verifyForCode(final SingleCRS expected, final String code) throws
FactoryException {
-        assertSame(code, expected, CRS.forCode(code));
+        assertTrue(code, Utilities.deepEquals(expected, CRS.forCode(code), ComparisonMode.IGNORE_METADATA));
     }
 
     /**
@@ -74,7 +78,13 @@ public final strictfp class CRSTest exte
         verifyForCode(CommonCRS.WGS72 .geographic3D(), "EPSG:4985");
         verifyForCode(CommonCRS.ETRS89.geographic3D(), "EPSG:4937");
         verifyForCode(CommonCRS.Vertical.MEAN_SEA_LEVEL.crs(), "EPSG:5714");
-        verifyForCode(CommonCRS.Vertical.DEPTH.crs(), "EPSG:5715");
+        /*
+         * Following test is skipped when using the EPSG factory because EPSG uses
+         * the "Gravity-related depth" axis name while ISO 19111 mandates "Depth".
+         */
+        if (AuthorityFactories.EPSG() instanceof EPSGFactoryFallback) {
+            verifyForCode(CommonCRS.Vertical.DEPTH.crs(), "EPSG:5715");
+        }
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java?rev=1726714&r1=1726713&r2=1726714&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java
[UTF-8] Tue Jan 26 00:02:35 2016
@@ -18,8 +18,6 @@ package org.apache.sis.referencing;
 
 import java.util.Date;
 import org.opengis.parameter.ParameterValueGroup;
-import org.opengis.util.FactoryException;
-import org.opengis.referencing.crs.SingleCRS;
 import org.opengis.referencing.crs.TemporalCRS;
 import org.opengis.referencing.crs.VerticalCRS;
 import org.opengis.referencing.crs.GeographicCRS;
@@ -222,43 +220,4 @@ public final strictfp class CommonCRSTes
         assertSame("Expected a cached instance.", crs, CommonCRS.WGS72.UTM(-45, -122));
         assertNotSame("Expected a new instance.", crs, CommonCRS.WGS72.UTM(+45, -122));
     }
-
-    /**
-     * Tests {@link CommonCRS#forCode(String, String, FactoryException)}.
-     *
-     * @throws FactoryException If a CRS can not be constructed.
-     *
-     * @see CRSTest#testForEpsgCode()
-     * @see CRSTest#testForCrsCode()
-     *
-     * @since 0.5
-     */
-    @Test
-    public void testForCode() throws FactoryException {
-        verifyForCode(CommonCRS.WGS84 .geographic(),            Constants.EPSG, "4326");
-        verifyForCode(CommonCRS.WGS72 .geographic(),            Constants.EPSG, "4322");
-        verifyForCode(CommonCRS.SPHERE.geographic(),            Constants.EPSG, "4047");
-        verifyForCode(CommonCRS.NAD83 .geographic(),            Constants.EPSG, "4269");
-        verifyForCode(CommonCRS.NAD27 .geographic(),            Constants.EPSG, "4267");
-        verifyForCode(CommonCRS.ETRS89.geographic(),            Constants.EPSG, "4258");
-        verifyForCode(CommonCRS.ED50  .geographic(),            Constants.EPSG, "4230");
-        verifyForCode(CommonCRS.WGS84 .geocentric(),            Constants.EPSG, "4978");
-        verifyForCode(CommonCRS.WGS72 .geocentric(),            Constants.EPSG, "4984");
-        verifyForCode(CommonCRS.ETRS89.geocentric(),            Constants.EPSG, "4936");
-        verifyForCode(CommonCRS.WGS84 .geographic3D(),          Constants.EPSG, "4979");
-        verifyForCode(CommonCRS.WGS72 .geographic3D(),          Constants.EPSG, "4985");
-        verifyForCode(CommonCRS.ETRS89.geographic3D(),          Constants.EPSG, "4937");
-        verifyForCode(CommonCRS.Vertical.MEAN_SEA_LEVEL.crs(),  Constants.EPSG, "5714");
-        verifyForCode(CommonCRS.Vertical.DEPTH.crs(),           Constants.EPSG, "5715");
-        verifyForCode(CommonCRS.WGS84.normalizedGeographic(),   Constants.CRS,  "84");
-        verifyForCode(CommonCRS.NAD83.normalizedGeographic(),   Constants.CRS,  "83");
-        verifyForCode(CommonCRS.NAD27.normalizedGeographic(),   Constants.CRS,  "27");
-    }
-
-    /**
-     * Asserts that the result of {@link CommonCRS#forCode(String, String, FactoryException)}
is the given CRS.
-     */
-    private static void verifyForCode(final SingleCRS expected, final String authority, final
String code) throws FactoryException {
-        assertSame(code, expected, CommonCRS.forCode(authority, code, null));
-    }
 }

Copied: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java
(from r1725652, sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java?p2=sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java&p1=sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java&r1=1725652&r2=1726714&rev=1726714&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java
[UTF-8] Tue Jan 26 00:02:35 2016
@@ -16,249 +16,61 @@
  */
 package org.apache.sis.referencing;
 
-import java.util.Date;
-import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.util.FactoryException;
 import org.opengis.referencing.crs.SingleCRS;
-import org.opengis.referencing.crs.TemporalCRS;
-import org.opengis.referencing.crs.VerticalCRS;
-import org.opengis.referencing.crs.GeographicCRS;
-import org.opengis.referencing.crs.GeocentricCRS;
-import org.opengis.referencing.crs.ProjectedCRS;
-import org.opengis.referencing.cs.AxisDirection;
-import org.opengis.referencing.cs.CoordinateSystem;
-import org.opengis.referencing.cs.EllipsoidalCS;
-import org.opengis.referencing.datum.TemporalDatum;
-import org.opengis.referencing.datum.VerticalDatum;
-import org.opengis.referencing.datum.VerticalDatumType;
-import org.apache.sis.internal.metadata.AxisNames;
-import org.apache.sis.internal.metadata.VerticalDatumTypes;
-import org.apache.sis.internal.util.Constants;
 
 // Test dependencies
-import org.opengis.test.Validators;
-import org.apache.sis.test.DependsOnMethod;
 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.TestUtilities.*;
 
 
 /**
- * Tests the {@link CommonCRS} class.
+ * Tests the {@link EPSGFactoryFallback} class.
  *
- * @author  Martin Desruisseaux (IRD, Geomatys)
- * @since   0.4
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.7
  * @version 0.7
  * @module
  */
 @DependsOn({
-  org.apache.sis.referencing.crs.DefaultGeodeticCRSTest.class,
-  org.apache.sis.referencing.datum.DefaultVerticalDatumTest.class,
-  StandardDefinitionsTest.class
+  StandardDefinitionsTest.class,
+  CommonCRSTest.class
 })
-public final strictfp class CommonCRSTest extends TestCase {
+public final strictfp class EPSGFactoryFallbackTest extends TestCase {
     /**
-     * Length of a day in milliseconds.
-     */
-    private static final double DAY_LENGTH = 24 * 60 * 60 * 1000;
-
-    /**
-     * Tests the {@link CommonCRS#geographic()} method.
-     */
-    @Test
-    public void testGeographic() {
-        final GeographicCRS geographic = CommonCRS.WGS84.geographic();
-        Validators.validate(geographic);
-        GeodeticObjectVerifier.assertIsWGS84(geographic, true, true);
-        assertSame("Cached value", geographic, CommonCRS.WGS84.geographic());
-    }
-
-    /**
-     * Tests the {@link CommonCRS#normalizedGeographic()} method.
-     */
-    @Test
-    @DependsOnMethod("testGeographic")
-    public void testNormalizedGeographic() {
-        final GeographicCRS geographic = CommonCRS.WGS84.geographic();
-        final GeographicCRS normalized = CommonCRS.WGS84.normalizedGeographic();
-        Validators.validate(normalized);
-        assertSame(geographic.getDatum(), normalized.getDatum());
-
-        final CoordinateSystem φλ = geographic.getCoordinateSystem();
-        final CoordinateSystem λφ = normalized.getCoordinateSystem();
-        assertSame("Longitude", φλ.getAxis(1), λφ.getAxis(0));
-        assertSame("Latitude",  φλ.getAxis(0), λφ.getAxis(1));
-        assertSame("Cached value", normalized, CommonCRS.WGS84.normalizedGeographic());
-    }
-
-    /**
-     * Tests the {@link CommonCRS#geographic3D()} method.
-     */
-    @Test
-    @DependsOnMethod("testGeographic")
-    public void testGeographic3D() {
-        final GeographicCRS crs = CommonCRS.WGS72.geographic3D();
-        Validators.validate(crs);
-        assertEquals("WGS 72", crs.getName().getCode());
-        assertSame   (CommonCRS.WGS72.geographic().getDatum(), crs.getDatum());
-        assertNotSame(CommonCRS.WGS84.geographic().getDatum(), crs.getDatum());
-
-        final EllipsoidalCS cs = crs.getCoordinateSystem();
-        final String name = cs.getName().getCode();
-        assertTrue(name, name.startsWith("Ellipsoidal 3D"));
-        assertEquals("dimension", 3, cs.getDimension());
-        assertEquals(AxisDirection.NORTH, cs.getAxis(0).getDirection());
-        assertEquals(AxisDirection.EAST,  cs.getAxis(1).getDirection());
-        assertEquals(AxisDirection.UP,    cs.getAxis(2).getDirection());
-        assertSame("Cached value", crs, CommonCRS.WGS72.geographic3D());
-    }
-
-    /**
-     * Tests the {@link CommonCRS#geocentric()} method.
-     */
-    @Test
-    @DependsOnMethod("testGeographic3D")
-    public void testGeocentric() {
-        final GeocentricCRS crs = CommonCRS.WGS72.geocentric();
-        Validators.validate(crs);
-        assertEquals("WGS 72", crs.getName().getCode());
-        assertSame   (CommonCRS.WGS72.geographic().getDatum(), crs.getDatum());
-        assertNotSame(CommonCRS.WGS84.geographic().getDatum(), crs.getDatum());
-
-        final CoordinateSystem cs = crs.getCoordinateSystem();
-        final String name = cs.getName().getCode();
-        assertTrue(name, name.startsWith("Earth centred"));
-        assertEquals("dimension", 3, cs.getDimension());
-        assertEquals(AxisDirection.GEOCENTRIC_X, cs.getAxis(0).getDirection());
-        assertEquals(AxisDirection.GEOCENTRIC_Y, cs.getAxis(1).getDirection());
-        assertEquals(AxisDirection.GEOCENTRIC_Z, cs.getAxis(2).getDirection());
-        assertSame("Cached value", crs, CommonCRS.WGS72.geocentric());
-    }
-
-    /**
-     * Verifies the vertical datum enumeration.
-     */
-    @Test
-    public void testVertical() {
-        for (final CommonCRS.Vertical e : CommonCRS.Vertical.values()) {
-            final VerticalDatumType datumType;
-            final String axisName, datumName;
-            switch (e) {
-                case NAVD88:         axisName = AxisNames.GRAVITY_RELATED_HEIGHT; datumName
= "North American Vertical Datum 1988"; datumType = VerticalDatumType. GEOIDAL;       break;
-                case BAROMETRIC:     axisName = "Barometric altitude";            datumName
= "Constant pressure surface";          datumType = VerticalDatumType. BAROMETRIC;    break;
-                case MEAN_SEA_LEVEL: axisName = AxisNames.GRAVITY_RELATED_HEIGHT; datumName
= "Mean Sea Level";                     datumType = VerticalDatumType. GEOIDAL;       break;
-                case DEPTH:          axisName = AxisNames.DEPTH;                  datumName
= "Mean Sea Level";                     datumType = VerticalDatumType. GEOIDAL;       break;
-                case ELLIPSOIDAL:    axisName = AxisNames.ELLIPSOIDAL_HEIGHT;     datumName
= "Ellipsoid";                          datumType = VerticalDatumTypes.ELLIPSOIDAL;   break;
-                case OTHER_SURFACE:  axisName = "Height";                         datumName
= "Other surface";                      datumType = VerticalDatumType. OTHER_SURFACE; break;
-                default: throw new AssertionError(e);
-            }
-            final String        name  = e.name();
-            final VerticalDatum datum = e.datum();
-            final VerticalCRS   crs   = e.crs();
-            if (e.isEPSG) {
-                /*
-                 * BAROMETRIC, ELLIPSOIDAL and OTHER_SURFACE uses an axis named "Height",
which is not
-                 * a valid axis name according ISO 19111. We skip the validation test for
those enums.
-                 */
-                Validators.validate(crs);
-            }
-            assertSame  (name, datum,          e.datum()); // Datum before CRS creation.
-            assertSame  (name, crs.getDatum(), e.datum()); // Datum after CRS creation.
-            assertEquals(name, datumName, datum.getName().getCode());
-            assertEquals(name, datumType, datum.getVerticalDatumType());
-            assertEquals(name, axisName,  crs.getCoordinateSystem().getAxis(0).getName().getCode());
-        }
-    }
-
-    /**
-     * Verifies the epoch values of temporal enumeration compared to the Julian epoch.
-     *
-     * @see <a href="http://en.wikipedia.org/wiki/Julian_day">Wikipedia: Julian day</a>
-     */
-    @Test
-    public void testTemporal() {
-        final double julianEpoch = CommonCRS.Temporal.JULIAN.datum().getOrigin().getTime()
/ DAY_LENGTH;
-        assertTrue(julianEpoch < 0);
-        for (final CommonCRS.Temporal e : CommonCRS.Temporal.values()) {
-            final String epoch;
-            final double days;
-            switch (e) {
-                case JAVA:             // Fall through
-                case UNIX:             epoch = "1970-01-01 00:00:00"; days = 2440587.5; break;
-                case TRUNCATED_JULIAN: epoch = "1968-05-24 00:00:00"; days = 2440000.5; break;
-                case DUBLIN_JULIAN:    epoch = "1899-12-31 12:00:00"; days = 2415020.0; break;
-                case MODIFIED_JULIAN:  epoch = "1858-11-17 00:00:00"; days = 2400000.5; break;
-                case JULIAN:           epoch = "4713-01-01 12:00:00"; days = 0;         break;
-                default: throw new AssertionError(e);
-            }
-            final String        name   = e.name();
-            final TemporalDatum datum  = e.datum();
-            final TemporalCRS   crs    = e.crs();
-            final Date          origin = datum.getOrigin();
-            Validators.validate(crs);
-            assertSame  (name, datum,          e.datum()); // Datum before CRS creation.
-            assertSame  (name, crs.getDatum(), e.datum()); // Datum after CRS creation.
-            assertEquals(name, epoch, format(origin));
-            assertEquals(name, days, origin.getTime() / DAY_LENGTH - julianEpoch, 0);
-        }
-    }
-
-    /**
-     * Tests {@link CommonCRS#UTM(double, double)}.
-     *
-     * @since 0.7
-     */
-    @Test
-    @DependsOnMethod("testGeographic")
-    public void testUTM() {
-        final ProjectedCRS crs = CommonCRS.WGS72.UTM(-45, -122);
-        assertEquals("name", "WGS 72 / UTM zone 10S", crs.getName().getCode());
-        final ParameterValueGroup pg = crs.getConversionFromBase().getParameterValues();
-        assertEquals(Constants.LATITUDE_OF_ORIGIN, -123, pg.parameter(Constants.CENTRAL_MERIDIAN).doubleValue(),
STRICT);
-        assertEquals(Constants.FALSE_NORTHING, 10000000, pg.parameter(Constants.FALSE_NORTHING).doubleValue(),
  STRICT);
-        assertSame("Expected a cached instance.", crs, CommonCRS.WGS72.UTM(-45, -122));
-        assertNotSame("Expected a new instance.", crs, CommonCRS.WGS72.UTM(+45, -122));
-    }
-
-    /**
-     * Tests {@link CommonCRS#forCode(String, String, FactoryException)}.
+     * Tests {@link EPSGFactoryFallback#createCoordinateReferenceSystem(String)}.
      *
      * @throws FactoryException If a CRS can not be constructed.
      *
      * @see CRSTest#testForEpsgCode()
      * @see CRSTest#testForCrsCode()
-     *
-     * @since 0.5
      */
     @Test
     public void testForCode() throws FactoryException {
-        verifyForCode(CommonCRS.WGS84 .geographic(),            Constants.EPSG, "4326");
-        verifyForCode(CommonCRS.WGS72 .geographic(),            Constants.EPSG, "4322");
-        verifyForCode(CommonCRS.SPHERE.geographic(),            Constants.EPSG, "4047");
-        verifyForCode(CommonCRS.NAD83 .geographic(),            Constants.EPSG, "4269");
-        verifyForCode(CommonCRS.NAD27 .geographic(),            Constants.EPSG, "4267");
-        verifyForCode(CommonCRS.ETRS89.geographic(),            Constants.EPSG, "4258");
-        verifyForCode(CommonCRS.ED50  .geographic(),            Constants.EPSG, "4230");
-        verifyForCode(CommonCRS.WGS84 .geocentric(),            Constants.EPSG, "4978");
-        verifyForCode(CommonCRS.WGS72 .geocentric(),            Constants.EPSG, "4984");
-        verifyForCode(CommonCRS.ETRS89.geocentric(),            Constants.EPSG, "4936");
-        verifyForCode(CommonCRS.WGS84 .geographic3D(),          Constants.EPSG, "4979");
-        verifyForCode(CommonCRS.WGS72 .geographic3D(),          Constants.EPSG, "4985");
-        verifyForCode(CommonCRS.ETRS89.geographic3D(),          Constants.EPSG, "4937");
-        verifyForCode(CommonCRS.Vertical.MEAN_SEA_LEVEL.crs(),  Constants.EPSG, "5714");
-        verifyForCode(CommonCRS.Vertical.DEPTH.crs(),           Constants.EPSG, "5715");
-        verifyForCode(CommonCRS.WGS84.normalizedGeographic(),   Constants.CRS,  "84");
-        verifyForCode(CommonCRS.NAD83.normalizedGeographic(),   Constants.CRS,  "83");
-        verifyForCode(CommonCRS.NAD27.normalizedGeographic(),   Constants.CRS,  "27");
+        verifyForCode(CommonCRS.WGS84 .geographic(),            "4326");
+        verifyForCode(CommonCRS.WGS72 .geographic(),            "4322");
+        verifyForCode(CommonCRS.SPHERE.geographic(),            "4047");
+        verifyForCode(CommonCRS.NAD83 .geographic(),            "4269");
+        verifyForCode(CommonCRS.NAD27 .geographic(),            "4267");
+        verifyForCode(CommonCRS.ETRS89.geographic(),            "4258");
+        verifyForCode(CommonCRS.ED50  .geographic(),            "4230");
+        verifyForCode(CommonCRS.WGS84 .geocentric(),            "4978");
+        verifyForCode(CommonCRS.WGS72 .geocentric(),            "4984");
+        verifyForCode(CommonCRS.ETRS89.geocentric(),            "4936");
+        verifyForCode(CommonCRS.WGS84 .geographic3D(),          "4979");
+        verifyForCode(CommonCRS.WGS72 .geographic3D(),          "4985");
+        verifyForCode(CommonCRS.ETRS89.geographic3D(),          "4937");
+        verifyForCode(CommonCRS.Vertical.MEAN_SEA_LEVEL.crs(),  "5714");
+        verifyForCode(CommonCRS.Vertical.DEPTH.crs(),           "5715");
     }
 
     /**
      * Asserts that the result of {@link CommonCRS#forCode(String, String, FactoryException)}
is the given CRS.
      */
-    private static void verifyForCode(final SingleCRS expected, final String authority, final
String code) throws FactoryException {
-        assertSame(code, expected, CommonCRS.forCode(authority, code, null));
+    private static void verifyForCode(final SingleCRS expected, final String code) throws
FactoryException {
+        assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createCoordinateReferenceSystem(code));
     }
 }

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=1726714&r1=1726713&r2=1726714&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] Tue Jan 26 00:02:35 2016
@@ -170,6 +170,7 @@ import org.junit.BeforeClass;
 
     org.apache.sis.referencing.StandardDefinitionsTest.class,
     org.apache.sis.referencing.CommonCRSTest.class,
+    org.apache.sis.referencing.EPSGFactoryFallbackTest.class,
     org.apache.sis.referencing.CRSTest.class,
     org.apache.sis.referencing.factory.GIGS3002.class,
     org.apache.sis.referencing.factory.GIGS3003.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=1726714&r1=1726713&r2=1726714&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] Tue Jan 26 00:02:35 2016
@@ -21,17 +21,22 @@ import java.util.Iterator;
 import java.util.NoSuchElementException;
 import org.apache.sis.util.Workaround;
 
+// Branch-specific imports
+import java.util.Objects;
+
 
 /**
  * An immutable set built from an iterator, which will be filled only when needed.
  * This implementation does <strong>not</strong> check if all elements in the
iterator
  * are really unique; we assume that this condition was already verified by the caller.
  *
- * <p>One usage of {@code LazySet} is to workaround a {@link java.util.ServiceLoader}
bug which block usage of two
+ * <p>One usage of {@code LazySet} is to workaround a {@link java.util.ServiceLoader}
bug which blocks usage of two
  * {@link Iterator} instances together: the first iteration must be fully completed or abandoned
before we can start
  * 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>This class is not thread-safe. Synchronization, if desired, shall be done by
the caller.</p>
  *
  * @param <E> The type of elements in the set.
@@ -42,89 +47,125 @@ import org.apache.sis.util.Workaround;
  * @module
  */
 @Workaround(library="JDK", version="1.8.0_31-b13")
-public final class LazySet<E> extends SetOfUnknownSize<E> {
+public class LazySet<E> extends SetOfUnknownSize<E> {
     /**
      * The original source of elements, or {@code null} if unknown.
      */
-    public final Iterable<? extends E> source;
+    private final Iterable<? extends E> source;
 
     /**
      * The iterator to use for filling this set, or {@code null} if the iteration did not
started yet
-     * or is finished. Those two cases can be distinguished by looking whether the {@link
#elements}
+     * or is finished. Those two cases can be distinguished by looking whether the {@link
#cachedElements}
      * array is null or not.
+     *
+     * @see #sourceIterator()
      */
-    private Iterator<? extends E> iterator;
+    private Iterator<? extends E> sourceIterator;
 
     /**
-     * The elements in this set, or {@code null} if the iteration did not started yet.
+     * The elements that we cached so far, or {@code null} if the iteration did not started
yet.
      * After the iteration started, this array will grow as needed.
+     *
+     * @see #createCache()
+     * @see #cache(Object)
      */
-    private E[] elements;
+    private E[] cachedElements;
 
     /**
-     * The current position in the iteration. This position will be incremented as long as
-     * there is some elements remaining in the iterator.
+     * The number of valid elements in the {@link #cachedElements} array.
+     * This counter will be incremented as long as there is more elements returned by {@link
#sourceIterator}.
      */
-    private int position;
+    private int numCached;
 
     /**
      * Constructs a set to be filled by the elements from the specified source. Iteration
will starts
      * 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 the set.
+     * @param source The source of elements to use for filling this set.
      */
-    @SuppressWarnings("unchecked")
     public LazySet(final Iterable<? extends E> source) {
+        Objects.requireNonNull(source);
         this.source = source;
     }
 
     /**
      * Constructs a set to be filled using the specified iterator.
-     * Iteration in the given iterator will occurs only when needed.
+     * Iteration with the given iterator will occur only when needed.
      *
-     * @param iterator The iterator to use for filling the set.
+     * @param iterator The iterator to use for filling this set.
      */
-    @SuppressWarnings("unchecked")
     public LazySet(final Iterator<? extends E> iterator) {
+        Objects.requireNonNull(sourceIterator);
+        sourceIterator = iterator;
         source = null;
-        this.iterator = iterator;
-        elements = (E[]) new Object[4];
+        createCache();
     }
 
     /**
-     * Notify this {@code LazySet} that it should re-fetch the elements from the {@linkplain
#source}.
+     * 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 void reload() {
+    public Iterable<? extends E> reload() {
         if (source != null) {
-            iterator = null;
-            elements = null;
-            position = 0;
+            sourceIterator = null;
+            cachedElements = null;
+            numCached = 0;
         }
+        return source;
     }
 
     /**
-     * Returns the iterator over the source elements, or {@code null} if the iteration is
finished.
+     * Hook for subclasses that want to prepend some values before the source {@code Iterable}.
+     * This method is invoked only when first needed. It is safe to return a shared array
since
+     * {@code LazySet} will not write in that array ({@code LazySet} will create a new array
if
+     * it needs to add more values).
+     *
+     * @return Values to prepend before the source {@code Iterable}, or {@code null} if none.
+     *
+     * @since 0.7
+     */
+    protected E[] initialValues() {
+        return null;
+    }
+
+    /**
+     * Creates the {@link #cachedElements} array. This array will contains the elements
+     * given by {@link #initialContent()} if that method returned a non-null and non-empty
array.
+     *
+     * @return {@code true} if {@link #initialValues()} initialized the set with at least
one value.
      */
     @SuppressWarnings("unchecked")
-    private Iterator<? extends E> sourceElements() {
-        if (iterator == null && elements == null && source != null) {
-            iterator = source.iterator();
-            elements = (E[]) new Object[4];
+    private boolean createCache() {
+        cachedElements = initialValues();   // No need to clone.
+        if (cachedElements != null) {
+            numCached = cachedElements.length;
+            if (numCached != 0) {
+                return true;
+            }
         }
-        return iterator;
+        cachedElements = (E[]) new Object[4];
+        return false;
     }
 
     /**
-     * Returns {@code true} if the {@link #iterator} is non-null and have more elements to
return.
+     * Returns {@code true} if the {@link #sourceIterator} is non-null and have more elements
to return,
+     * or if we initialized the cache with some elements declared by {@link #initialValues()}.
      */
-    private boolean hasNext() {
-        final Iterator<? extends E> it = sourceElements();
-        if (it != null) {
-            if (it.hasNext()) {
+    private boolean canPullMore() {
+        if (sourceIterator == null && cachedElements == null) {
+            sourceIterator = source.iterator();
+            if (createCache()) {
                 return true;
             }
-            iterator = null;
+        }
+        if (sourceIterator != null) {
+            if (sourceIterator.hasNext()) {
+                return true;
+            }
+            sourceIterator = null;
         }
         return false;
     }
@@ -135,8 +176,8 @@ public final class LazySet<E> extends Se
      * @return {@code true} if this set has no element.
      */
     @Override
-    public boolean isEmpty() {
-        return (position == 0) && !hasNext();
+    public final boolean isEmpty() {
+        return (numCached == 0) && !canPullMore();
     }
 
     /**
@@ -146,25 +187,26 @@ public final class LazySet<E> extends Se
      * @return Number of elements in the iterator.
      */
     @Override
-    public int size() {
-        final Iterator<? extends E> it = sourceElements();
-        if (it != null) {
-            while (it.hasNext()) {
-                cache(it.next());
+    public final int size() {
+        if (canPullMore()) {
+            while (sourceIterator.hasNext()) {
+                cache(sourceIterator.next());
             }
-            iterator = null;
+            sourceIterator = null;
         }
-        return position;
+        return numCached;
     }
 
     /**
-     * Adds the given element to the {@link #elements} array.
+     * Adds the given element to the {@link #cachedElements} array.
+     *
+     * @param element The element to add to the cache.
      */
     private void cache(final E element) {
-        if (position >= elements.length) {
-            elements = Arrays.copyOf(elements, position*2);
+        if (numCached >= cachedElements.length) {
+            cachedElements = Arrays.copyOf(cachedElements, numCached << 1);
         }
-        elements[position++] = element;
+        cachedElements[numCached++] = element;
     }
 
     /**
@@ -176,7 +218,7 @@ public final class LazySet<E> extends Se
      * negative index and for skipped elements.</p>
      */
     final boolean exists(final int index) {
-        return (index < position) || hasNext();
+        return (index < numCached) || canPullMore();
     }
 
     /**
@@ -186,14 +228,14 @@ public final class LazySet<E> extends Se
      * @return The element at the requested index.
      */
     final E get(final int index) {
-        if (index >= position) {
-            if (hasNext()) {
-                cache(iterator.next());
+        if (index >= numCached) {
+            if (canPullMore()) {
+                cache(sourceIterator.next());
             } else {
                 throw new NoSuchElementException();
             }
         }
-        return elements[index];
+        return cachedElements[index];
     }
 
     /**
@@ -203,7 +245,7 @@ public final class LazySet<E> extends Se
      * @return An iterator over the elements in this set.
      */
     @Override
-    public Iterator<E> iterator() {
+    public final Iterator<E> iterator() {
         return new Iterator<E>() {
             private int cursor;
 

Modified: sis/branches/JDK8/ide-project/NetBeans/build.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/ide-project/NetBeans/build.xml?rev=1726714&r1=1726713&r2=1726714&view=diff
==============================================================================
--- sis/branches/JDK8/ide-project/NetBeans/build.xml (original)
+++ sis/branches/JDK8/ide-project/NetBeans/build.xml Tue Jan 26 00:02:35 2016
@@ -77,6 +77,13 @@
       </fileset>
     </concat>
 
+    <!-- CRSAuthorityFactory implementations to be loaded by ServiceLoader. -->
+    <concat destfile="${build.classes.dir}/META-INF/services/org.opengis.referencing.crs.CRSAuthorityFactory"
encoding="UTF-8" fixlastline="yes">
+      <fileset dir="${project.root}">
+        <include name="*/*/src/main/resources/META-INF/services/org.opengis.referencing.crs.CRSAuthorityFactory"/>
+      </fileset>
+    </concat>
+
     <!-- CRSFactory implementations to be loaded by ServiceLoader. -->
     <concat destfile="${build.classes.dir}/META-INF/services/org.opengis.referencing.crs.CRSFactory"
encoding="UTF-8" fixlastline="yes">
       <fileset dir="${project.root}">



Mime
View raw message