From commits-return-11436-apmail-sis-commits-archive=sis.apache.org@sis.apache.org Tue Nov 13 18:17:07 2018 Return-Path: X-Original-To: apmail-sis-commits-archive@www.apache.org Delivered-To: apmail-sis-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B0CB818023 for ; Tue, 13 Nov 2018 18:17:07 +0000 (UTC) Received: (qmail 61966 invoked by uid 500); 13 Nov 2018 18:17:07 -0000 Delivered-To: apmail-sis-commits-archive@sis.apache.org Received: (qmail 61933 invoked by uid 500); 13 Nov 2018 18:17:07 -0000 Mailing-List: contact commits-help@sis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sis-dev@sis.apache.org Delivered-To: mailing list commits@sis.apache.org Received: (qmail 61892 invoked by uid 99); 13 Nov 2018 18:17:07 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Nov 2018 18:17:07 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id ED25881E06; Tue, 13 Nov 2018 18:17:06 +0000 (UTC) Date: Tue, 13 Nov 2018 18:17:07 +0000 To: "commits@sis.apache.org" Subject: [sis] 01/02: Rename methods in ReferencingFactoryContainer and use them in GeodeticObjectBuilder. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: desruisseaux@apache.org In-Reply-To: <154213302687.3758.6270315034681940033@gitbox.apache.org> References: <154213302687.3758.6270315034681940033@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: sis X-Git-Refname: refs/heads/geoapi-4.0 X-Git-Reftype: branch X-Git-Rev: 1c8d11dfc96d0e2213be02bafd9269a28b3ef00e X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20181113181706.ED25881E06@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git commit 1c8d11dfc96d0e2213be02bafd9269a28b3ef00e Author: Martin Desruisseaux AuthorDate: Tue Nov 13 14:45:34 2018 +0100 Rename methods in ReferencingFactoryContainer and use them in GeodeticObjectBuilder. --- .../referencing/GeodeticObjectBuilder.java | 84 ++++------------------ .../referencing/ReferencingFactoryContainer.java | 10 +-- .../org/apache/sis/storage/geotiff/CRSBuilder.java | 24 +++---- 3 files changed, 30 insertions(+), 88 deletions(-) diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/GeodeticObjectBuilder.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/GeodeticObjectBuilder.java index 8803da4..ae4d358 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/GeodeticObjectBuilder.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/GeodeticObjectBuilder.java @@ -26,7 +26,6 @@ import org.opengis.parameter.ParameterValueGroup; import org.opengis.parameter.ParameterNotFoundException; import org.opengis.parameter.InvalidParameterValueException; import org.opengis.referencing.IdentifiedObject; -import org.opengis.referencing.crs.CRSFactory; import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.opengis.referencing.crs.GeographicCRS; import org.opengis.referencing.crs.ProjectedCRS; @@ -35,14 +34,11 @@ import org.opengis.referencing.cs.AxisDirection; import org.opengis.referencing.cs.CSFactory; import org.opengis.referencing.cs.CartesianCS; import org.opengis.referencing.cs.TimeCS; -import org.opengis.referencing.datum.DatumFactory; import org.opengis.referencing.datum.TemporalDatum; -import org.opengis.referencing.operation.CoordinateOperationFactory; import org.opengis.referencing.operation.OperationMethod; import org.opengis.referencing.operation.Conversion; import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.resources.Errors; -import org.apache.sis.internal.system.DefaultFactories; import org.apache.sis.internal.metadata.EllipsoidalHeightCombiner; import org.apache.sis.internal.referencing.provider.TransverseMercator; import org.apache.sis.internal.referencing.provider.PolarStereographicA; @@ -58,7 +54,7 @@ import org.apache.sis.referencing.CommonCRS; * However this class may move in a public package later if we feel confident that its API is mature enough.

* * @author Martin Desruisseaux (Geomatys) - * @version 0.8 + * @version 1.0 * @since 0.6 * @module */ @@ -84,69 +80,15 @@ public class GeodeticObjectBuilder extends Builder { private ParameterValueGroup parameters; /** - * The factory for Coordinate Reference System objects, fetched when first needed. + * Group of factories used by this builder. */ - private CRSFactory crsFactory; - - /** - * The factory for Coordinate System objects, fetched when first needed. - */ - private CSFactory csFactory; - - /** - * The factory for Datum objects, fetched when first needed. - */ - private DatumFactory datumFactory; - - /** - * The factory for Coordinate Operation objects, fetched when first needed. - */ - private CoordinateOperationFactory copFactory; + private final ReferencingFactoryContainer factories; /** * Creates a new builder. */ public GeodeticObjectBuilder() { - } - - /** - * Returns the factory for Coordinate Reference System objects. This method fetches the factory when first needed. - */ - private CRSFactory getCRSFactory() { - if (crsFactory == null) { - crsFactory = DefaultFactories.forBuildin(CRSFactory.class); - } - return crsFactory; - } - - /** - * Returns the factory for Coordinate System objects. This method fetches the factory when first needed. - */ - private CSFactory getCSFactory() { - if (csFactory == null) { - csFactory = DefaultFactories.forBuildin(CSFactory.class); - } - return csFactory; - } - - /** - * Returns the factory for Datum objects. This method fetches the factory when first needed. - */ - private DatumFactory getDatumFactory() { - if (datumFactory == null) { - datumFactory = DefaultFactories.forBuildin(DatumFactory.class); - } - return datumFactory; - } - - /** - * Returns the factory for Coordinate Operation objects. This method fetches the factory when first needed. - */ - private CoordinateOperationFactory getCoordinateOperationFactory() { - if (copFactory == null) { - copFactory = CoordinateOperations.factory(); - } - return copFactory; + factories = new ReferencingFactoryContainer(); } /** @@ -172,7 +114,7 @@ public class GeodeticObjectBuilder extends Builder { if (method != null) { throw new IllegalStateException(Errors.format(Errors.Keys.ElementAlreadyPresent_1, "OperationMethod")); } - method = getCoordinateOperationFactory().getOperationMethod(name); + method = factories.getCoordinateOperationFactory().getOperationMethod(name); parameters = method.getParameters().createValue(); return this; } @@ -336,7 +278,7 @@ public class GeodeticObjectBuilder extends Builder { final Object name = (conversionName != null) ? properties.put(Conversion.NAME_KEY, conversionName) : null; final Object alias = properties.put(Conversion.ALIAS_KEY, null); final Object identifier = properties.put(Conversion.IDENTIFIERS_KEY, null); - final Conversion conversion = getCoordinateOperationFactory().createDefiningConversion(properties, method, parameters); + final Conversion conversion = factories.getCoordinateOperationFactory().createDefiningConversion(properties, method, parameters); /* * Restore the original properties and create the final ProjectedCRS. */ @@ -345,7 +287,7 @@ public class GeodeticObjectBuilder extends Builder { if (name != null) { properties.put(Conversion.NAME_KEY, name); } - return getCRSFactory().createProjectedCRS(properties, baseCRS, conversion, derivedCS); + return factories.getCRSFactory().createProjectedCRS(properties, baseCRS, conversion, derivedCS); } finally { onCreate(true); } @@ -393,7 +335,7 @@ public class GeodeticObjectBuilder extends Builder { onCreate(false); try { if (cs == null) { - final CSFactory csFactory = getCSFactory(); + final CSFactory csFactory = factories.getCSFactory(); cs = CommonCRS.Temporal.JAVA.crs().getCoordinateSystem(); // To be used as a template, except for units. cs = csFactory.createTimeCS(name(cs), csFactory.createCoordinateSystemAxis(name(cs.getAxis(0)), "t", AxisDirection.FUTURE, unit)); @@ -404,12 +346,12 @@ public class GeodeticObjectBuilder extends Builder { if (datum == null) { final Object remarks = properties.remove(TemporalCRS.REMARKS_KEY); final Object identifier = properties.remove(TemporalCRS.IDENTIFIERS_KEY); - datum = getDatumFactory().createTemporalDatum(properties, origin); + datum = factories.getDatumFactory().createTemporalDatum(properties, origin); properties.put(TemporalCRS.IDENTIFIERS_KEY, identifier); properties.put(TemporalCRS.REMARKS_KEY, remarks); properties.put(TemporalCRS.NAME_KEY, datum.getName()); // Share the Identifier instance. } - return getCRSFactory().createTemporalCRS(properties, datum, cs); + return factories.getCRSFactory().createTemporalCRS(properties, datum, cs); } finally { onCreate(true); } @@ -426,9 +368,9 @@ public class GeodeticObjectBuilder extends Builder { public CoordinateReferenceSystem createCompoundCRS(final CoordinateReferenceSystem... components) throws FactoryException { return new EllipsoidalHeightCombiner() { @Override public void initialize(final int factoryTypes) { - if ((factoryTypes & CRS) != 0) crsFactory = getCRSFactory(); - if ((factoryTypes & CS) != 0) csFactory = getCSFactory(); - if ((factoryTypes & OPERATION) != 0) opFactory = getCoordinateOperationFactory(); + if ((factoryTypes & CRS) != 0) crsFactory = factories.getCRSFactory(); + if ((factoryTypes & CS) != 0) csFactory = factories.getCSFactory(); + if ((factoryTypes & OPERATION) != 0) opFactory = factories.getCoordinateOperationFactory(); } }.createCompoundCRS(properties, components); } diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingFactoryContainer.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingFactoryContainer.java index 470af80..fc1e018 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingFactoryContainer.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingFactoryContainer.java @@ -78,7 +78,7 @@ public class ReferencingFactoryContainer { * * @return the Datum factory (never {@code null}). */ - public final DatumFactory datumFactory() { + public final DatumFactory getDatumFactory() { if (datumFactory == null) { datumFactory = DefaultFactories.forBuildin(DatumFactory.class); } @@ -90,7 +90,7 @@ public class ReferencingFactoryContainer { * * @return the Coordinate System factory (never {@code null}). */ - public final CSFactory csFactory() { + public final CSFactory getCSFactory() { if (csFactory == null) { csFactory = DefaultFactories.forBuildin(CSFactory.class); } @@ -102,7 +102,7 @@ public class ReferencingFactoryContainer { * * @return the Coordinate Reference System factory (never {@code null}). */ - public final CRSFactory crsFactory() { + public final CRSFactory getCRSFactory() { if (crsFactory == null) { crsFactory = DefaultFactories.forBuildin(CRSFactory.class); } @@ -116,7 +116,7 @@ public class ReferencingFactoryContainer { * * @return the Coordinate Operation factory (never {@code null}). */ - public final CoordinateOperationFactory operationFactory() { + public final CoordinateOperationFactory getCoordinateOperationFactory() { if (operationFactory == null) { operationFactory = CoordinateOperations.factory(); } @@ -128,7 +128,7 @@ public class ReferencingFactoryContainer { * * @return the Math Transform factory (never {@code null}). */ - public final MathTransformFactory mtFactory() { + public final MathTransformFactory getMathTransformFactory() { if (mtFactory == null) { mtFactory = DefaultFactories.forBuildin(MathTransformFactory.class); } diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/CRSBuilder.java b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/CRSBuilder.java index a54a54d..d148336 100644 --- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/CRSBuilder.java +++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/CRSBuilder.java @@ -279,7 +279,7 @@ final class CRSBuilder extends ReferencingFactoryContainer { /** * Returns a map with the given name associated to {@value org.opengis.referencing.IdentifiedObject#NAME_KEY}. * The given name shall be either an instance of {@link String} or {@link Identifier}. - * This is an helper method for creating geodetic objects with {@link #crsFactory()}. + * This is an helper method for creating geodetic objects with {@link #getCRSFactory()}. */ private Map properties(Object name) { if (name == null) { @@ -700,7 +700,7 @@ final class CRSBuilder extends ReferencingFactoryContainer { if (crs == null) { missingValue(GeoKeys.GeographicType); } else { - crs = crsFactory().createCompoundCRS(Collections.singletonMap(IdentifiedObject.NAME_KEY, crs.getName()), crs, vertical); + crs = getCRSFactory().createCompoundCRS(Collections.singletonMap(IdentifiedObject.NAME_KEY, crs.getName()), crs, vertical); } } } @@ -867,7 +867,7 @@ final class CRSBuilder extends ReferencingFactoryContainer { * This is because the citation value is for the CRS (e.g. "WGS84") while the prime * meridian names are very different (e.g. "Paris", "Madrid", etc). */ - return datumFactory().createPrimeMeridian(properties(names[PRIMEM]), longitude, unit); + return getDatumFactory().createPrimeMeridian(properties(names[PRIMEM]), longitude, unit); } break; // Default to Greenwich. } @@ -937,14 +937,14 @@ final class CRSBuilder extends ReferencingFactoryContainer { double inverseFlattening = getAsDouble(GeoKeys.InvFlattening); final Ellipsoid ellipsoid; if (!Double.isNaN(inverseFlattening)) { - ellipsoid = datumFactory().createFlattenedSphere(properties, semiMajor, inverseFlattening, unit); + ellipsoid = getDatumFactory().createFlattenedSphere(properties, semiMajor, inverseFlattening, unit); } else { /* * If the inverse flattening factory was not defined, fallback on semi-major axis length. * This is a less common way to define ellipsoid (the most common way uses flattening). */ final double semiMinor = getMandatoryDouble(GeoKeys.SemiMinorAxis); - ellipsoid = datumFactory().createEllipsoid(properties, semiMajor, semiMinor, unit); + ellipsoid = getDatumFactory().createEllipsoid(properties, semiMajor, semiMinor, unit); } lastName = ellipsoid.getName(); return ellipsoid; @@ -1023,7 +1023,7 @@ final class CRSBuilder extends ReferencingFactoryContainer { String name = getOrDefault(names, DATUM); final Ellipsoid ellipsoid = createEllipsoid(names, linearUnit); final PrimeMeridian meridian = createPrimeMeridian(names, angularUnit); - final GeodeticDatum datum = datumFactory().createGeodeticDatum(properties(name), ellipsoid, meridian); + final GeodeticDatum datum = getDatumFactory().createGeodeticDatum(properties(name), ellipsoid, meridian); name = Utilities.toUpperCase(name, Characters.Filter.LETTERS_AND_DIGITS); lastName = datum.getName(); try { @@ -1196,7 +1196,7 @@ final class CRSBuilder extends ReferencingFactoryContainer { if (!Units.DEGREE.equals(angularUnit)) { cs = replaceAngularUnit(cs, angularUnit); } - final GeographicCRS crs = crsFactory().createGeographicCRS(properties(getOrDefault(names, GCRS)), datum, cs); + final GeographicCRS crs = getCRSFactory().createGeographicCRS(properties(getOrDefault(names, GCRS)), datum, cs); lastName = crs.getName(); return crs; } @@ -1266,7 +1266,7 @@ final class CRSBuilder extends ReferencingFactoryContainer { if (!Units.METRE.equals(linearUnit)) { cs = replaceLinearUnit(cs, linearUnit); } - final GeocentricCRS crs = crsFactory().createGeocentricCRS(properties(getOrDefault(names, GCRS)), datum, cs); + final GeocentricCRS crs = getCRSFactory().createGeocentricCRS(properties(getOrDefault(names, GCRS)), datum, cs); lastName = crs.getName(); return crs; } @@ -1405,7 +1405,7 @@ final class CRSBuilder extends ReferencingFactoryContainer { if (!Units.METRE.equals(linearUnit)) { cs = replaceLinearUnit(cs, linearUnit); } - final ProjectedCRS crs = crsFactory().createProjectedCRS(properties(name), baseCRS, projection, cs); + final ProjectedCRS crs = getCRSFactory().createProjectedCRS(properties(name), baseCRS, projection, cs); lastName = crs.getName(); return crs; } @@ -1463,7 +1463,7 @@ final class CRSBuilder extends ReferencingFactoryContainer { case GeoCodes.userDefined: { final Unit azimuthUnit = createUnit(GeoKeys.AzimuthUnits, (short) 0, Angle.class, Units.DEGREE); final String type = getMandatoryString(GeoKeys.CoordTrans); - final OperationMethod method = operationFactory().getOperationMethod(Constants.GEOTIFF + ':' + type); + final OperationMethod method = getCoordinateOperationFactory().getOperationMethod(Constants.GEOTIFF + ':' + type); final ParameterValueGroup parameters = method.getParameters().createValue(); final Map toNames = ReferencingUtilities.identifierToName(parameters.getDescriptor(), Citations.GEOTIFF); final Map paramValues = new HashMap<>(); // Keys: [String|Short] instances for [known|unknown] parameters. @@ -1516,7 +1516,7 @@ final class CRSBuilder extends ReferencingFactoryContainer { } } } - final Conversion c = operationFactory().createDefiningConversion(properties(name), method, parameters); + final Conversion c = getCoordinateOperationFactory().createDefiningConversion(properties(name), method, parameters); lastName = c.getName(); return c; } @@ -1640,7 +1640,7 @@ final class CRSBuilder extends ReferencingFactoryContainer { if (!Units.METRE.equals(unit)) { cs = (VerticalCS) CoordinateSystems.replaceLinearUnit(cs, unit); } - return crsFactory().createVerticalCRS(properties(name), datum, cs); + return getCRSFactory().createVerticalCRS(properties(name), datum, cs); } default: { return epsgFactory().createVerticalCRS(String.valueOf(epsg));