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
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new 49c68b4 Leverage ArgumentChecks.ensureNonEmpty(…) where appropriate.
Restore some import statements to their original order for reducing the risk of
conflicts when we will merge to master (we will need to choose later a more
general approach for managing import statements).
49c68b4 is described below
commit 49c68b45b7bac16acb36bd3d4f4a5383c23ee6f2
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Thu Jan 9 11:42:42 2020 +0100
Leverage ArgumentChecks.ensureNonEmpty(…) where appropriate.
Restore some import statements to their original order for reducing the
risk of conflicts when we will merge to master
(we will need to choose later a more general approach for managing import
statements).
---
.../org/apache/sis/feature/FeatureOperations.java | 19 ++---
.../apache/sis/util/iso/DefaultNameFactory.java | 15 ++--
.../org/apache/sis/util/iso/DefaultScopedName.java | 9 +--
.../main/java/org/apache/sis/referencing/CRS.java | 88 ++++++++++------------
.../java/org/apache/sis/util/ArgumentChecks.java | 24 +++---
.../java/org/apache/sis/util/package-info.java | 5 +-
6 files changed, 73 insertions(+), 87 deletions(-)
diff --git
a/core/sis-feature/src/main/java/org/apache/sis/feature/FeatureOperations.java
b/core/sis-feature/src/main/java/org/apache/sis/feature/FeatureOperations.java
index b75c880..ad190ec 100644
---
a/core/sis-feature/src/main/java/org/apache/sis/feature/FeatureOperations.java
+++
b/core/sis-feature/src/main/java/org/apache/sis/feature/FeatureOperations.java
@@ -210,20 +210,13 @@ public final class FeatureOperations extends Static {
throw new
IllegalArgumentException(Errors.getResources(identification).getString(
Errors.Keys.IllegalCharacter_2, "delimiter",
StringJoinOperation.ESCAPE));
}
- ArgumentChecks.ensureNonNull("singleAttributes", singleAttributes);
- switch (singleAttributes.length) {
- case 0: {
- throw new
IllegalArgumentException(Errors.getResources(identification)
- .getString(Errors.Keys.EmptyArgument_1,
"singleAttributes"));
- }
- case 1: {
- if ((prefix == null || prefix.isEmpty()) && (suffix == null ||
suffix.isEmpty())) {
- final PropertyType at = singleAttributes[0];
- if (!(at instanceof FeatureAssociationRole)) {
- return link(identification, at);
- }
+ ArgumentChecks.ensureNonEmpty("singleAttributes", singleAttributes);
+ if (singleAttributes.length == 1) {
+ if ((prefix == null || prefix.isEmpty()) && (suffix == null ||
suffix.isEmpty())) {
+ final PropertyType at = singleAttributes[0];
+ if (!(at instanceof FeatureAssociationRole)) {
+ return link(identification, at);
}
- break;
}
}
return POOL.unique(new StringJoinOperation(identification, delimiter,
prefix, suffix, singleAttributes));
diff --git
a/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java
b/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java
index 1fb3f6c..3883fc6 100644
---
a/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java
+++
b/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java
@@ -30,11 +30,11 @@ import org.opengis.util.MemberName;
import org.opengis.util.GenericName;
import org.opengis.util.NameFactory;
import org.opengis.util.InternationalString;
+import org.apache.sis.util.ArgumentChecks;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.collection.WeakHashSet;
import org.apache.sis.internal.util.Strings;
-import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
import static
org.apache.sis.util.iso.DefaultNameSpace.DEFAULT_SEPARATOR_STRING;
@@ -120,7 +120,7 @@ public class DefaultNameFactory extends AbstractFactory
implements NameFactory {
*/
@Override
public InternationalString createInternationalString(final
Map<Locale,String> strings) {
- ensureNonNull("strings", strings);
+ ArgumentChecks.ensureNonNull("strings", strings);
switch (strings.size()) {
case 0: throw new
IllegalArgumentException(Errors.format(Errors.Keys.EmptyDictionary));
case 1: return new
SimpleInternationalString(strings.values().iterator().next());
@@ -180,7 +180,7 @@ public class DefaultNameFactory extends AbstractFactory
implements NameFactory {
*/
@Override
public NameSpace createNameSpace(final GenericName name, final
Map<String,?> properties) {
- ensureNonNull("name", name);
+ ArgumentChecks.ensureNonNull("name", name);
String separator = getString(properties, SEPARATOR_KEY);
if (separator == null) {
separator = DefaultNameSpace.DEFAULT_SEPARATOR_STRING;
@@ -271,12 +271,11 @@ public class DefaultNameFactory extends AbstractFactory
implements NameFactory {
*/
@Override
public GenericName createGenericName(final NameSpace scope, final
CharSequence... parsedNames) {
- ensureNonNull("parsedNames", parsedNames);
- switch (parsedNames.length) {
- default: return pool.unique(new DefaultScopedName(scope,
Arrays.asList(parsedNames)));
- case 1: return createLocalName(scope, parsedNames[0]); // User
may override.
- case 0: throw new
IllegalArgumentException(Errors.format(Errors.Keys.EmptyArgument_1,
"parsedNames"));
+ ArgumentChecks.ensureNonEmpty("parsedNames", parsedNames);
+ if (parsedNames.length == 1) {
+ return createLocalName(scope, parsedNames[0]); //
User may override.
}
+ return pool.unique(new DefaultScopedName(scope,
Arrays.asList(parsedNames)));
}
/**
diff --git
a/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java
b/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java
index a01e038..6ca4f1b 100644
---
a/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java
+++
b/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java
@@ -87,12 +87,11 @@ public class DefaultScopedName extends AbstractName
implements ScopedName {
* @param names the names to gives to the new scoped name.
*/
static AbstractName create(final UnmodifiableArrayList<? extends
DefaultLocalName> names) {
- ArgumentChecks.ensureNonNull("names", names);
- switch (names.size()) {
- default: return new DefaultScopedName(names);
- case 1: return names.get(0);
- case 0: throw new
IllegalArgumentException(Errors.format(Errors.Keys.EmptyArgument_1, "names"));
+ ArgumentChecks.ensureNonEmpty("names", names);
+ if (names.size() == 1) {
+ return names.get(0);
}
+ return new DefaultScopedName(names);
}
/**
diff --git
a/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
index fe67a0e..fb38484 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
@@ -16,84 +16,82 @@
*/
package org.apache.sis.referencing;
+import java.util.Map;
+import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.List;
-import java.util.Map;
import java.util.logging.Filter;
import java.util.logging.LogRecord;
-
+import org.opengis.util.FactoryException;
import org.opengis.geometry.Envelope;
-import org.opengis.geometry.Geometry;
-import org.opengis.metadata.citation.Citation;
-import org.opengis.metadata.extent.BoundingPolygon;
-import org.opengis.metadata.extent.Extent;
-import org.opengis.metadata.extent.GeographicBoundingBox;
-import org.opengis.metadata.extent.GeographicExtent;
-import org.opengis.referencing.IdentifiedObject;
import org.opengis.referencing.NoSuchAuthorityCodeException;
-import org.opengis.referencing.crs.CRSAuthorityFactory;
+import org.opengis.referencing.IdentifiedObject;
+import org.opengis.referencing.cs.CartesianCS;
+import org.opengis.referencing.cs.EllipsoidalCS;
+import org.opengis.referencing.cs.AxisDirection;
+import org.opengis.referencing.cs.CoordinateSystem;
+import org.opengis.referencing.cs.CoordinateSystemAxis;
import org.opengis.referencing.crs.CRSFactory;
+import org.opengis.referencing.crs.SingleCRS;
import org.opengis.referencing.crs.CompoundCRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
-import org.opengis.referencing.crs.EngineeringCRS;
-import org.opengis.referencing.crs.GeneralDerivedCRS;
+import org.opengis.referencing.crs.CRSAuthorityFactory;
import org.opengis.referencing.crs.GeodeticCRS;
import org.opengis.referencing.crs.GeographicCRS;
+import org.opengis.referencing.crs.GeneralDerivedCRS;
import org.opengis.referencing.crs.ProjectedCRS;
-import org.opengis.referencing.crs.SingleCRS;
import org.opengis.referencing.crs.TemporalCRS;
import org.opengis.referencing.crs.VerticalCRS;
-import org.opengis.referencing.cs.AxisDirection;
-import org.opengis.referencing.cs.CartesianCS;
-import org.opengis.referencing.cs.CoordinateSystem;
-import org.opengis.referencing.cs.CoordinateSystemAxis;
-import org.opengis.referencing.cs.EllipsoidalCS;
+import org.opengis.referencing.crs.EngineeringCRS;
import org.opengis.referencing.datum.Datum;
import org.opengis.referencing.datum.GeodeticDatum;
import org.opengis.referencing.operation.Conversion;
-import org.opengis.referencing.operation.CoordinateOperation;
import org.opengis.referencing.operation.OperationNotFoundException;
+import org.opengis.metadata.citation.Citation;
+import org.opengis.metadata.extent.Extent;
+import org.opengis.metadata.extent.BoundingPolygon;
+import org.opengis.metadata.extent.GeographicBoundingBox;
+import org.opengis.metadata.extent.GeographicExtent;
+import org.opengis.referencing.operation.CoordinateOperation;
import org.opengis.referencing.operation.TransformException;
-import org.opengis.util.FactoryException;
-
+import org.apache.sis.measure.Units;
import org.apache.sis.geometry.Envelopes;
import org.apache.sis.geometry.GeneralEnvelope;
import org.apache.sis.internal.referencing.AxisDirections;
-import org.apache.sis.internal.referencing.CoordinateOperations;
-import org.apache.sis.internal.referencing.DefinitionVerifier;
import org.apache.sis.internal.referencing.EllipsoidalHeightCombiner;
import org.apache.sis.internal.referencing.PositionalAccuracyConstant;
+import org.apache.sis.internal.referencing.CoordinateOperations;
import org.apache.sis.internal.referencing.ReferencingUtilities;
+import org.apache.sis.internal.referencing.DefinitionVerifier;
import org.apache.sis.internal.referencing.Resources;
import org.apache.sis.internal.system.DefaultFactories;
-import org.apache.sis.internal.system.Loggers;
import org.apache.sis.internal.system.Modules;
+import org.apache.sis.internal.system.Loggers;
import org.apache.sis.internal.util.Numerics;
-import org.apache.sis.measure.Units;
-import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
-import org.apache.sis.metadata.iso.extent.Extents;
-import org.apache.sis.referencing.crs.DefaultCompoundCRS;
-import org.apache.sis.referencing.crs.DefaultEngineeringCRS;
-import org.apache.sis.referencing.crs.DefaultGeographicCRS;
-import org.apache.sis.referencing.crs.DefaultProjectedCRS;
-import org.apache.sis.referencing.crs.DefaultVerticalCRS;
import org.apache.sis.referencing.cs.AxisFilter;
import org.apache.sis.referencing.cs.CoordinateSystems;
import org.apache.sis.referencing.cs.DefaultVerticalCS;
-import org.apache.sis.referencing.factory.GeodeticObjectFactory;
-import org.apache.sis.referencing.factory.UnavailableFactoryException;
+import org.apache.sis.referencing.crs.DefaultGeographicCRS;
+import org.apache.sis.referencing.crs.DefaultProjectedCRS;
+import org.apache.sis.referencing.crs.DefaultVerticalCRS;
+import org.apache.sis.referencing.crs.DefaultCompoundCRS;
+import org.apache.sis.referencing.crs.DefaultEngineeringCRS;
import org.apache.sis.referencing.operation.AbstractCoordinateOperation;
import org.apache.sis.referencing.operation.CoordinateOperationContext;
-import org.apache.sis.referencing.operation.DefaultConversion;
import org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory;
+import org.apache.sis.referencing.operation.DefaultConversion;
+import org.apache.sis.referencing.factory.GeodeticObjectFactory;
+import org.apache.sis.referencing.factory.UnavailableFactoryException;
+import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
+import org.apache.sis.metadata.iso.extent.Extents;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.logging.Logging;
import org.apache.sis.util.ArgumentChecks;
-import org.apache.sis.util.Static;
import org.apache.sis.util.Utilities;
+import org.apache.sis.util.Static;
// Branch-dependent imports
+import org.opengis.geometry.Geometry;
/**
@@ -524,7 +522,7 @@ public final class CRS extends Static {
* - Otherwise (i.e. if the region of interest is likely to be wider
than the projected CRS
* domain of validity), then the geographic CRS will be returned.
*/
- final double roiArea = Extents.area(regionOfInterest); // NaN if
'regionOfInterest' is null.
+ final double roiArea = Extents.area(regionOfInterest); // NaN if
`regionOfInterest` is null.
double maxInsideArea = 0;
double minOutsideArea = Double.POSITIVE_INFINITY;
boolean tryDerivedCRS = false;
@@ -908,16 +906,10 @@ public final class CRS extends Static {
* @see
org.apache.sis.referencing.operation.transform.MathTransforms#compound(MathTransform...)
*/
public static CoordinateReferenceSystem compound(final
CoordinateReferenceSystem... components) throws FactoryException {
- ArgumentChecks.ensureNonNull("components", components);
- switch (components.length) {
- case 0: {
- throw new
IllegalArgumentException(Errors.format(Errors.Keys.EmptyArgument_1,
"components"));
- }
- case 1: {
- final CoordinateReferenceSystem crs = components[0];
- if (crs != null) return crs;
- break;
- }
+ ArgumentChecks.ensureNonEmpty("components", components);
+ if (components.length == 1) {
+ final CoordinateReferenceSystem crs = components[0];
+ if (crs != null) return crs;
}
return new EllipsoidalHeightCombiner().createCompoundCRS(components);
}
diff --git
a/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
b/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
index a8318e9..7e75aad 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
@@ -16,16 +16,14 @@
*/
package org.apache.sis.util;
+import java.util.Map;
import java.util.BitSet;
import java.util.Collection;
-import java.util.Map;
-
-import org.opengis.geometry.DirectPosition;
+import org.opengis.referencing.cs.CoordinateSystem;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.geometry.Envelope;
+import org.opengis.geometry.DirectPosition;
import org.opengis.geometry.MismatchedDimensionException;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
-import org.opengis.referencing.cs.CoordinateSystem;
-
import org.apache.sis.internal.util.Strings;
import org.apache.sis.util.resources.Errors;
@@ -84,7 +82,8 @@ import org.apache.sis.util.resources.Errors;
* in the {@linkplain java.util.Locale#getDefault() default locale} if the
check failed.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @author Alexis Manin (Geomatys)
+ * @version 1.1
* @since 0.3
* @module
*/
@@ -192,13 +191,16 @@ public final class ArgumentChecks extends Static {
}
/**
- * Makes sure that given collection is non-null and non-empty. If it is
null, then a {@link NullArgumentException}
- * is thrown. Otherwise if it {@link Collection#isEmpty() is empty}, then
an {@link IllegalArgumentException} is thrown.
+ * Makes sure that given collection is non-null and non-empty.
+ * If it is null, then a {@link NullArgumentException} is thrown.
+ * Otherwise if it {@linkplain Collection#isEmpty() is empty}, then an
{@link IllegalArgumentException} is thrown.
*
- * @param name the name of the argument to be checked. Used only if an
exception is thrown.
- * @param toCheck the user argument to check against null value and empty
collection.
+ * @param name the name of the argument to be checked. Used only if
an exception is thrown.
+ * @param toCheck the user argument to check against null value and
empty collection.
* @throws NullArgumentException if {@code toCheck} is null.
* @throws IllegalArgumentException if {@code toCheck} is empty.
+ *
+ * @since 1.1
*/
public static void ensureNonEmpty(final String name, final Collection<?>
toCheck) {
if (toCheck == null) {
diff --git
a/core/sis-utility/src/main/java/org/apache/sis/util/package-info.java
b/core/sis-utility/src/main/java/org/apache/sis/util/package-info.java
index c957633..e7ef5f6 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/package-info.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/package-info.java
@@ -37,8 +37,9 @@
* {@link org.apache.sis.util.LenientComparable} interface, for
comparing objects in various ways.</li>
* </ul>
*
- * @author Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @author Martin Desruisseaux (Geomatys)
+ * @author Alexis Manin (Geomatys)
+ * @version 1.1
* @since 0.3
* @module
*/