You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2022/12/10 22:37:50 UTC
[sis] branch geoapi-4.0 updated (ee6b293e6b -> d37c8ce013)
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a change to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
from ee6b293e6b Remove reference to JAXB internal implementation, which is not provided anymore.
new eaf8024708 Reduce the use of `CollectionsExt` when Java 11 methods can do the work.
new d37c8ce013 Use the safer Java 11 way to convert collection to array.
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../apache/sis/gui/coverage/CoverageStyling.java | 2 +-
.../gui/referencing/PositionableProjection.java | 2 +-
.../org/apache/sis/internal/gui/RecentChoices.java | 4 +-
.../org/apache/sis/coverage/SampleDimension.java | 2 +-
.../org/apache/sis/coverage/grid/GridCoverage.java | 2 +-
.../apache/sis/coverage/grid/ImageRenderer.java | 3 +-
.../org/apache/sis/feature/AbstractAttribute.java | 4 +-
.../org/apache/sis/feature/DefaultFeatureType.java | 2 +-
.../sis/feature/builder/FeatureTypeBuilder.java | 4 +-
.../org/apache/sis/filter/AssociationValue.java | 2 +-
.../java/org/apache/sis/filter/LogicalFilter.java | 2 +-
.../java/org/apache/sis/image/ComputedImage.java | 2 +-
.../sis/internal/feature/j2d/PathBuilder.java | 2 +-
.../sis/internal/filter/SortByComparator.java | 2 +-
.../sis/internal/filter/sqlmm/TwoGeometries.java | 2 +-
.../sis/internal/jaxb/NonMarshalledAuthority.java | 2 +-
.../apache/sis/internal/jaxb/TypeRegistration.java | 4 +-
.../internal/jaxb/metadata/replace/SensorType.java | 2 +-
.../sis/internal/metadata/legacy/MediumName.java | 2 +-
.../apache/sis/util/iso/DefaultNameFactory.java | 2 +-
.../src/main/java/org/apache/sis/xml/Pooled.java | 3 +-
.../main/java/org/apache/sis/xml/Transformer.java | 19 +-
.../org/apache/sis/xml/TransformingWriter.java | 2 +-
.../java/org/apache/sis/test/MetadataAssert.java | 3 +-
.../org/apache/sis/internal/map/SEPortrayer.java | 2 +-
.../coverage/MultiResolutionCoverageLoader.java | 3 +-
.../main/java/org/apache/sis/portrayal/Canvas.java | 2 +-
.../java/org/apache/sis/portrayal/MapLayers.java | 2 +-
.../referencing/gazetteer/FinalLocationType.java | 4 +-
.../referencing/gazetteer/LocationTypeTest.java | 4 +-
.../java/org/apache/sis/geometry/Envelopes.java | 2 +-
.../referencing/CC_GeneralOperationParameter.java | 5 +-
.../jaxb/referencing/CC_OperationMethod.java | 2 +-
.../referencing/CC_OperationParameterGroup.java | 2 +-
.../referencing/GeodeticObjectBuilder.java | 3 +-
.../internal/referencing/j2d/TileOrganizer.java | 2 +-
.../referencing/provider/DatumShiftGridFile.java | 2 +-
.../sis/internal/referencing/provider/NTv2.java | 2 +-
.../provider/PolarStereographicNorth.java | 3 +-
.../apache/sis/io/wkt/GeodeticObjectParser.java | 4 +-
.../parameter/DefaultParameterDescriptorGroup.java | 7 +-
.../sis/parameter/DefaultParameterValueGroup.java | 3 +-
.../org/apache/sis/parameter/ParameterFormat.java | 3 +-
.../java/org/apache/sis/referencing/Builder.java | 4 +-
.../main/java/org/apache/sis/referencing/CRS.java | 2 +-
.../sis/referencing/crs/DefaultCompoundCRS.java | 9 +-
.../sis/referencing/factory/CacheRecord.java | 2 +-
.../referencing/factory/GeodeticObjectFactory.java | 12 +-
.../referencing/factory/IdentifiedObjectSet.java | 2 +-
.../factory/MultiAuthoritiesFactory.java | 2 +-
.../referencing/factory/sql/EPSGDataAccess.java | 4 +-
.../operation/AbstractSingleOperation.java | 2 +-
.../operation/CoordinateOperationRegistry.java | 5 +-
.../operation/DefaultConcatenatedOperation.java | 7 +-
.../DefaultCoordinateOperationFactory.java | 12 +-
.../operation/DefaultOperationMethod.java | 3 +-
.../operation/InverseOperationMethod.java | 2 +-
.../operation/builder/LinearTransformBuilder.java | 2 +-
.../CC_OperationParameterGroupTest.java | 6 +-
.../parameter/DefaultParameterValueGroupTest.java | 4 +-
.../apache/sis/parameter/ParameterFormatTest.java | 2 +-
.../referencing/AbstractIdentifiedObjectTest.java | 2 +-
.../report/CoordinateReferenceSystems.java | 2 +-
.../apache/sis/internal/util/CollectionsExt.java | 207 ++++-----------------
.../apache/sis/internal/util/DefinitionURI.java | 2 +-
.../java/org/apache/sis/math/StatisticsFormat.java | 2 +-
.../java/org/apache/sis/measure/UnitDimension.java | 12 +-
.../src/main/java/org/apache/sis/util/Classes.java | 4 +-
.../sis/util/collection/DefaultTreeTable.java | 4 +-
.../sis/util/collection/FrequencySortedSet.java | 3 +-
.../sis/util/collection/TreeTableFormat.java | 4 +-
.../sis/internal/util/CollectionsExtTest.java | 18 +-
.../test/java/org/apache/sis/test/TestRunner.java | 3 +-
.../apache/sis/util/collection/LargeCodeList.java | 2 +-
.../org/apache/sis/storage/geotiff/CRSBuilder.java | 2 +-
.../apache/sis/storage/geotiff/Localization.java | 2 +-
.../sis/storage/geotiff/MultiResolutionImage.java | 2 +-
.../java/org/apache/sis/internal/netcdf/Axis.java | 2 +-
.../org/apache/sis/internal/netcdf/FeatureSet.java | 2 +-
.../apache/sis/internal/netcdf/RasterResource.java | 2 +-
.../org/apache/sis/internal/netcdf/Variable.java | 2 +-
.../sis/internal/netcdf/impl/ChannelDecoder.java | 4 +-
.../org/apache/sis/storage/netcdf/NetcdfStore.java | 2 +-
.../apache/sis/internal/sql/feature/Database.java | 4 +-
.../sis/internal/sql/feature/PrimaryKey.java | 2 +-
.../sis/internal/sql/feature/QueryAnalyzer.java | 2 +-
.../sis/internal/sql/feature/TableAnalyzer.java | 2 +-
.../org/apache/sis/internal/storage/csv/Store.java | 2 +-
.../apache/sis/internal/storage/folder/Store.java | 2 +-
.../storage/aggregate/AggregatedFeatureSet.java | 2 +-
.../aggregate/ConcatenatedGridResource.java | 3 +-
.../apache/sis/storage/event/StoreListeners.java | 3 +-
.../sis/test/storage/CoverageReadConsistency.java | 2 +-
.../apache/sis/internal/storage/gpx/Metadata.java | 2 +-
94 files changed, 168 insertions(+), 358 deletions(-)
[sis] 02/02: Use the safer Java 11 way to convert collection to array.
Posted by de...@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 d37c8ce0134771885e29be887e4ab37debbfebf6
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Sat Dec 10 23:36:11 2022 +0100
Use the safer Java 11 way to convert collection to array.
---
.../main/java/org/apache/sis/gui/coverage/CoverageStyling.java | 2 +-
.../org/apache/sis/gui/referencing/PositionableProjection.java | 2 +-
.../src/main/java/org/apache/sis/internal/gui/RecentChoices.java | 4 ++--
.../src/main/java/org/apache/sis/coverage/SampleDimension.java | 2 +-
.../src/main/java/org/apache/sis/coverage/grid/GridCoverage.java | 2 +-
.../src/main/java/org/apache/sis/feature/AbstractAttribute.java | 4 ++--
.../src/main/java/org/apache/sis/feature/DefaultFeatureType.java | 2 +-
.../java/org/apache/sis/feature/builder/FeatureTypeBuilder.java | 4 ++--
.../src/main/java/org/apache/sis/filter/AssociationValue.java | 2 +-
.../src/main/java/org/apache/sis/filter/LogicalFilter.java | 2 +-
.../src/main/java/org/apache/sis/image/ComputedImage.java | 2 +-
.../java/org/apache/sis/internal/feature/j2d/PathBuilder.java | 2 +-
.../java/org/apache/sis/internal/filter/SortByComparator.java | 2 +-
.../java/org/apache/sis/internal/filter/sqlmm/TwoGeometries.java | 2 +-
.../main/java/org/apache/sis/internal/jaxb/TypeRegistration.java | 4 ++--
.../apache/sis/internal/jaxb/metadata/replace/SensorType.java | 2 +-
.../java/org/apache/sis/internal/metadata/legacy/MediumName.java | 2 +-
.../main/java/org/apache/sis/util/iso/DefaultNameFactory.java | 2 +-
.../src/main/java/org/apache/sis/xml/Transformer.java | 2 +-
.../src/main/java/org/apache/sis/xml/TransformingWriter.java | 2 +-
.../src/main/java/org/apache/sis/internal/map/SEPortrayer.java | 2 +-
.../src/main/java/org/apache/sis/portrayal/Canvas.java | 2 +-
.../src/main/java/org/apache/sis/portrayal/MapLayers.java | 2 +-
.../org/apache/sis/referencing/gazetteer/FinalLocationType.java | 4 ++--
.../org/apache/sis/referencing/gazetteer/LocationTypeTest.java | 4 +---
.../src/main/java/org/apache/sis/geometry/Envelopes.java | 2 +-
.../internal/jaxb/referencing/CC_GeneralOperationParameter.java | 5 ++---
.../apache/sis/internal/jaxb/referencing/CC_OperationMethod.java | 2 +-
.../internal/jaxb/referencing/CC_OperationParameterGroup.java | 2 +-
.../org/apache/sis/internal/referencing/j2d/TileOrganizer.java | 2 +-
.../sis/internal/referencing/provider/DatumShiftGridFile.java | 2 +-
.../java/org/apache/sis/internal/referencing/provider/NTv2.java | 2 +-
.../internal/referencing/provider/PolarStereographicNorth.java | 3 +--
.../main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java | 4 ++--
.../apache/sis/parameter/DefaultParameterDescriptorGroup.java | 7 +++----
.../org/apache/sis/parameter/DefaultParameterValueGroup.java | 3 +--
.../src/main/java/org/apache/sis/parameter/ParameterFormat.java | 3 +--
.../src/main/java/org/apache/sis/referencing/Builder.java | 4 ++--
.../src/main/java/org/apache/sis/referencing/CRS.java | 2 +-
.../java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java | 9 ++++-----
.../java/org/apache/sis/referencing/factory/CacheRecord.java | 2 +-
.../org/apache/sis/referencing/factory/IdentifiedObjectSet.java | 2 +-
.../apache/sis/referencing/factory/MultiAuthoritiesFactory.java | 2 +-
.../org/apache/sis/referencing/factory/sql/EPSGDataAccess.java | 4 ++--
.../sis/referencing/operation/AbstractSingleOperation.java | 2 +-
.../sis/referencing/operation/CoordinateOperationRegistry.java | 5 ++---
.../sis/referencing/operation/DefaultConcatenatedOperation.java | 7 +++----
.../apache/sis/referencing/operation/DefaultOperationMethod.java | 3 +--
.../apache/sis/referencing/operation/InverseOperationMethod.java | 2 +-
.../referencing/operation/builder/LinearTransformBuilder.java | 2 +-
.../jaxb/referencing/CC_OperationParameterGroupTest.java | 6 +++---
.../org/apache/sis/parameter/DefaultParameterValueGroupTest.java | 4 ++--
.../test/java/org/apache/sis/parameter/ParameterFormatTest.java | 2 +-
.../org/apache/sis/referencing/AbstractIdentifiedObjectTest.java | 2 +-
.../sis/referencing/report/CoordinateReferenceSystems.java | 2 +-
.../main/java/org/apache/sis/internal/util/DefinitionURI.java | 2 +-
.../src/main/java/org/apache/sis/math/StatisticsFormat.java | 2 +-
core/sis-utility/src/main/java/org/apache/sis/util/Classes.java | 4 ++--
.../java/org/apache/sis/util/collection/DefaultTreeTable.java | 4 ++--
.../java/org/apache/sis/util/collection/FrequencySortedSet.java | 3 +--
.../java/org/apache/sis/util/collection/TreeTableFormat.java | 4 +---
.../src/test/java/org/apache/sis/test/TestRunner.java | 3 +--
.../test/java/org/apache/sis/util/collection/LargeCodeList.java | 2 +-
.../src/main/java/org/apache/sis/storage/geotiff/CRSBuilder.java | 2 +-
.../main/java/org/apache/sis/storage/geotiff/Localization.java | 2 +-
.../org/apache/sis/storage/geotiff/MultiResolutionImage.java | 2 +-
.../src/main/java/org/apache/sis/internal/netcdf/Axis.java | 2 +-
.../src/main/java/org/apache/sis/internal/netcdf/FeatureSet.java | 2 +-
.../main/java/org/apache/sis/internal/netcdf/RasterResource.java | 2 +-
.../src/main/java/org/apache/sis/internal/netcdf/Variable.java | 2 +-
.../java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java | 4 ++--
.../src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java | 2 +-
.../main/java/org/apache/sis/internal/sql/feature/Database.java | 4 ++--
.../java/org/apache/sis/internal/sql/feature/PrimaryKey.java | 2 +-
.../java/org/apache/sis/internal/sql/feature/QueryAnalyzer.java | 2 +-
.../java/org/apache/sis/internal/sql/feature/TableAnalyzer.java | 2 +-
.../src/main/java/org/apache/sis/internal/storage/csv/Store.java | 2 +-
.../main/java/org/apache/sis/internal/storage/folder/Store.java | 2 +-
.../org/apache/sis/storage/aggregate/AggregatedFeatureSet.java | 2 +-
.../org/apache/sis/test/storage/CoverageReadConsistency.java | 2 +-
.../main/java/org/apache/sis/internal/storage/gpx/Metadata.java | 2 +-
81 files changed, 105 insertions(+), 120 deletions(-)
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageStyling.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageStyling.java
index 5afcc38344..519a8b1804 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageStyling.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageStyling.java
@@ -99,7 +99,7 @@ final class CoverageStyling extends ColorColumnHandler<Category> implements Func
* @param items list of items of the table to clear.
*/
private void clear(final ObservableList<Category> items) {
- final Category[] content = items.toArray(new Category[items.size()]);
+ final Category[] content = items.toArray(Category[]::new);
items.clear(); // For forcing a repaint of the table.
customizedColors.clear();
items.setAll(content);
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/PositionableProjection.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/PositionableProjection.java
index ce1d591f13..e56b554afa 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/PositionableProjection.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/PositionableProjection.java
@@ -173,7 +173,7 @@ public abstract class PositionableProjection extends CodeList<PositionableProjec
*/
public static PositionableProjection[] values() {
synchronized (VALUES) {
- return VALUES.toArray(new PositionableProjection[VALUES.size()]);
+ return VALUES.toArray(PositionableProjection[]::new);
}
}
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/RecentChoices.java b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/RecentChoices.java
index 9e37d18a8a..8bb43a5370 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/RecentChoices.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/RecentChoices.java
@@ -183,7 +183,7 @@ public final class RecentChoices {
if (!CRS_THIS_RUN.add(code.trim())) {
return;
}
- codes = CRS_THIS_RUN.toArray(new String[CRS_THIS_RUN.size()]);
+ codes = CRS_THIS_RUN.toArray(String[]::new);
}
saveReferenceSystems(codes);
}
@@ -196,7 +196,7 @@ public final class RecentChoices {
public static void saveReferenceSystems() {
final String[] codes;
synchronized (CRS_THIS_RUN) {
- codes = CRS_THIS_RUN.toArray(new String[CRS_THIS_RUN.size()]);
+ codes = CRS_THIS_RUN.toArray(String[]::new);
}
saveReferenceSystems(codes);
}
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/SampleDimension.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/SampleDimension.java
index f53b080120..82b27f1df3 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/SampleDimension.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/SampleDimension.java
@@ -174,7 +174,7 @@ public class SampleDimension implements Serializable {
if (categories.isEmpty()) {
list = CategoryList.EMPTY;
} else {
- list = CategoryList.create(categories.toArray(new Category[categories.size()]), background);
+ list = CategoryList.create(categories.toArray(Category[]::new), background);
}
this.name = name;
this.background = background;
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
index 39ba19be94..5496915d40 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
@@ -110,7 +110,7 @@ public abstract class GridCoverage extends BandedCoverage {
ArgumentChecks.ensureNonNull ("domain", domain);
ArgumentChecks.ensureNonEmpty("ranges", ranges);
gridGeometry = domain;
- sampleDimensions = ranges.toArray(new SampleDimension[ranges.size()]);
+ sampleDimensions = ranges.toArray(SampleDimension[]::new);
ArgumentChecks.ensureNonEmpty("range", sampleDimensions);
for (int i=0; i<sampleDimensions.length; i++) {
ArgumentChecks.ensureNonNullElement("range", i, sampleDimensions[i]);
diff --git a/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractAttribute.java b/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractAttribute.java
index 90ffb9fc05..45742cebb2 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractAttribute.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractAttribute.java
@@ -158,7 +158,7 @@ public abstract class AbstractAttribute<V> extends Field<V> implements Attribute
out.defaultWriteObject();
final Attribute<?>[] characterizedBy;
if (characteristics instanceof CharacteristicMap) {
- characterizedBy = characteristics.values().toArray(new Attribute<?>[characteristics.size()]);
+ characterizedBy = characteristics.values().toArray(Attribute[]::new);
} else {
characterizedBy = null;
}
@@ -362,7 +362,7 @@ public abstract class AbstractAttribute<V> extends Field<V> implements Attribute
if (!map.isEmpty()) {
if (!(map instanceof CharacteristicTypeMap)) {
final Collection<AttributeType<?>> types = map.values();
- map = CharacteristicTypeMap.create(type, types.toArray(new AttributeType<?>[types.size()]));
+ map = CharacteristicTypeMap.create(type, types.toArray(AttributeType<?>[]::new));
}
return new CharacteristicMap(this, (CharacteristicTypeMap) map);
}
diff --git a/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java b/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
index 3ada174a79..193da7f434 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
@@ -353,7 +353,7 @@ public class DefaultFeatureType extends AbstractIdentifiedType implements Featur
assignableTo = new HashSet<>(4);
assignableTo.add(super.getName());
scanPropertiesFrom(this, properties);
- allProperties = UnmodifiableArrayList.wrap(byName.values().toArray(new PropertyType[byName.size()]));
+ allProperties = UnmodifiableArrayList.wrap(byName.values().toArray(PropertyType[]::new));
/*
* Now check if the feature is simple/complex or dense/sparse. We perform this check after we finished
* to create the list of all properties, because some properties may be overridden and we want to take
diff --git a/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java b/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
index d4ea848dcd..9b83bdac66 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
@@ -409,7 +409,7 @@ public class FeatureTypeBuilder extends TypeBuilder {
* @see DefaultFeatureType#getSuperTypes()
*/
public FeatureType[] getSuperTypes() {
- return superTypes.toArray(new FeatureType[superTypes.size()]);
+ return superTypes.toArray(FeatureType[]::new);
}
/**
@@ -992,7 +992,7 @@ public class FeatureTypeBuilder extends TypeBuilder {
}
}
feature = new DefaultFeatureType(identification(), isAbstract(),
- superTypes.toArray(new FeatureType[superTypes.size()]),
+ superTypes.toArray(FeatureType[]::new),
ArraysExt.resize(propertyTypes, propertyCursor));
}
return feature;
diff --git a/core/sis-feature/src/main/java/org/apache/sis/filter/AssociationValue.java b/core/sis-feature/src/main/java/org/apache/sis/filter/AssociationValue.java
index 67914b95d6..2718f19400 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/filter/AssociationValue.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/filter/AssociationValue.java
@@ -78,7 +78,7 @@ final class AssociationValue<V> extends LeafExpression<Feature, V>
* @param accessor expression to use for evaluating the property value after the last element of the path.
*/
AssociationValue(final List<String> path, final PropertyValue<V> accessor) {
- this.path = path.toArray(new String[path.size()]);
+ this.path = path.toArray(String[]::new);
this.accessor = accessor;
}
diff --git a/core/sis-feature/src/main/java/org/apache/sis/filter/LogicalFilter.java b/core/sis-feature/src/main/java/org/apache/sis/filter/LogicalFilter.java
index 71b7ffe60a..d17beffc58 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/filter/LogicalFilter.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/filter/LogicalFilter.java
@@ -64,7 +64,7 @@ abstract class LogicalFilter<R> extends FilterNode<R> implements LogicalOperator
@SuppressWarnings({"unchecked", "rawtypes"})
LogicalFilter(final Collection<? extends Filter<? super R>> op) {
ArgumentChecks.ensureNonEmpty("operands", op);
- operands = op.toArray(new Filter[op.size()]);
+ operands = op.toArray(Filter[]::new);
if (operands.length < 2) {
throw new IllegalArgumentException(Errors.format(Errors.Keys.TooFewArguments_2, 2, operands.length));
}
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/ComputedImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/ComputedImage.java
index 4b85bad9e9..baa8a35f32 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/ComputedImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/ComputedImage.java
@@ -655,7 +655,7 @@ public abstract class ComputedImage extends PlanarImage implements Disposable {
public Point[] getWritableTileIndices() {
final List<Point> indices = new ArrayList<>();
if (reference.getWritableTileIndices(indices)) {
- return indices.toArray(new Point[indices.size()]);
+ return indices.toArray(Point[]::new);
}
return null;
}
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/j2d/PathBuilder.java b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/j2d/PathBuilder.java
index 2eb48ed63f..6141f4984b 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/j2d/PathBuilder.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/j2d/PathBuilder.java
@@ -228,7 +228,7 @@ public class PathBuilder {
switch (polylines.size()) {
case 0: return null;
case 1: return polylines.get(0);
- default: return new MultiPolylines(polylines.toArray(new Polyline[polylines.size()]));
+ default: return new MultiPolylines(polylines.toArray(Polyline[]::new));
}
}
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/SortByComparator.java b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/SortByComparator.java
index 3727386d42..5487a2ebd5 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/SortByComparator.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/SortByComparator.java
@@ -74,7 +74,7 @@ public final class SortByComparator<R> implements SortBy<R>, Serializable {
*/
@SuppressWarnings({"unchecked","rawtypes"}) // Generic array creation.
private SortByComparator(final Map<?, SortProperty<R>> merged) {
- properties = merged.values().toArray(new SortProperty[merged.size()]);
+ properties = merged.values().toArray(SortProperty[]::new);
}
/**
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/TwoGeometries.java b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/TwoGeometries.java
index b4575408b3..ccb6e1b983 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/TwoGeometries.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/TwoGeometries.java
@@ -95,7 +95,7 @@ class TwoGeometries<R,G> extends SpatialFunction<R> {
final GeometryWrapper<G> tr = literal.transform(targetCRS);
if (tr != literal) {
@SuppressWarnings({"unchecked","rawtypes"})
- final Expression<? super R, ?>[] effective = getParameters().toArray(new Expression[0]); // TODO: use generator in JDK9.
+ final Expression<? super R, ?>[] effective = getParameters().toArray(Expression[]::new);
effective[1] = Optimization.literal(tr);
return recreate(effective);
}
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
index 0d1389e5f0..a672be9215 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
@@ -196,8 +196,8 @@ public abstract class TypeRegistration {
final UnaryOperator<Object> c = t.beforeMarshal();
if (c != null) toImpl.add(c);
}
- converters = toImpl.toArray(new UnaryOperator[toImpl.size()]);
- return types.toArray(new Class<?>[types.size()]);
+ converters = toImpl.toArray(UnaryOperator[]::new);
+ return types.toArray(Class<?>[]::new);
}
/**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/SensorType.java b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/SensorType.java
index 94d7cc1408..12a4751275 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/SensorType.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/SensorType.java
@@ -69,7 +69,7 @@ public final class SensorType extends CodeList<SensorType> {
*/
public static SensorType[] values() {
synchronized (VALUES) {
- return VALUES.toArray(new SensorType[VALUES.size()]);
+ return VALUES.toArray(SensorType[]::new);
}
}
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/legacy/MediumName.java b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/legacy/MediumName.java
index 937059eede..fa31ef7a83 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/legacy/MediumName.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/legacy/MediumName.java
@@ -134,7 +134,7 @@ public final class MediumName extends CodeList<MediumName> implements Citation {
*/
public static MediumName[] values() {
synchronized (VALUES) {
- return VALUES.toArray(new MediumName[VALUES.size()]);
+ return VALUES.toArray(MediumName[]::new);
}
}
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 f7a20de0e8..eaf9fdfca6 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
@@ -341,7 +341,7 @@ public class DefaultNameFactory extends AbstractFactory implements NameFactory {
*/
return createLocalName(scope, name);
}
- return createGenericName(scope, names.toArray(new String[names.size()]));
+ return createGenericName(scope, names.toArray(String[]::new));
}
/**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/Transformer.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/Transformer.java
index dff0fcbeeb..290a365d1c 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/xml/Transformer.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/Transformer.java
@@ -385,7 +385,7 @@ abstract class Transformer {
switch (renamedAttributes.size()) {
case 0: attributes = List.of(); break; // Avoid object creation for this common case.
case 1: attributes = List.of(renamedAttributes.remove(0)); break;
- default: attributes = Arrays.asList(renamedAttributes.toArray(new Attribute[renamedAttributes.size()]));
+ default: attributes = Arrays.asList(renamedAttributes.toArray(Attribute[]::new));
renamedAttributes.clear();
break;
}
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingWriter.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingWriter.java
index cd78248d80..e87e51913c 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingWriter.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingWriter.java
@@ -321,7 +321,7 @@ final class TransformingWriter extends Transformer implements XMLEventWriter {
} while (namespaces.hasNext());
if (changed) {
assert !uniqueNamespaces.isEmpty();
- final Namespace[] exported = uniqueNamespaces.values().toArray(new Namespace[uniqueNamespaces.size()]);
+ final var exported = uniqueNamespaces.values().toArray(Namespace[]::new);
uniqueNamespaces.clear();
return Arrays.asList(exported);
} else {
diff --git a/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/SEPortrayer.java b/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/SEPortrayer.java
index 1ecb19ab55..960c1327d7 100644
--- a/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/SEPortrayer.java
+++ b/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/SEPortrayer.java
@@ -513,7 +513,7 @@ public final class SEPortrayer {
for (String propName : copy) {
columns.add(new FeatureQuery.NamedExpression(filterFactory.property(propName), propName));
}
- query.setProjection(columns.toArray(new FeatureQuery.NamedExpression[columns.size()]));
+ query.setProjection(columns.toArray(FeatureQuery.NamedExpression[]::new));
}
//TODO optimize filter
//TODO add linear resolution
diff --git a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/Canvas.java b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/Canvas.java
index 1f25957381..b582a72f19 100644
--- a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/Canvas.java
+++ b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/Canvas.java
@@ -972,7 +972,7 @@ public class Canvas extends Observable implements Localized {
*/
supplementalDimensions = CanvasExtent.findSupplementalDimensions(crs,
multidimToObjective.derivative(pointOfInterest), components);
- augmentedObjectiveCRS = CRS.compound(components.toArray(new CoordinateReferenceSystem[components.size()]));
+ augmentedObjectiveCRS = CRS.compound(components.toArray(CoordinateReferenceSystem[]::new));
if (Utilities.equalsIgnoreMetadata(augmentedObjectiveCRS, crs)) {
augmentedObjectiveCRS = crs;
}
diff --git a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/MapLayers.java b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/MapLayers.java
index 0ead548e0b..044f446bfc 100644
--- a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/MapLayers.java
+++ b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/MapLayers.java
@@ -182,7 +182,7 @@ public class MapLayers extends MapItem {
case 1 : return Optional.of(envelopes.get(0));
default : {
try {
- return Optional.ofNullable(Envelopes.union(envelopes.toArray(new Envelope[envelopes.size()])));
+ return Optional.ofNullable(Envelopes.union(envelopes.toArray(Envelope[]::new)));
} catch (TransformException ex) {
throw new DataStoreException(ex.getMessage(), ex);
}
diff --git a/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/FinalLocationType.java b/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/FinalLocationType.java
index 704d59b8d9..c37c69745c 100644
--- a/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/FinalLocationType.java
+++ b/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/FinalLocationType.java
@@ -166,7 +166,7 @@ final class FinalLocationType extends AbstractLocationType implements Serializab
static List<LocationType> snapshot(final Collection<? extends LocationType> types,
final ReferenceSystemUsingIdentifiers rs, final Map<LocationType, FinalLocationType> existing)
{
- final LocationType[] array = types.toArray(new LocationType[types.size()]);
+ final LocationType[] array = types.toArray(LocationType[]::new);
for (int i=0; i < array.length; i++) {
final LocationType source = array[i];
ArgumentChecks.ensureNonNullElement("types", i, source);
@@ -191,7 +191,7 @@ final class FinalLocationType extends AbstractLocationType implements Serializab
if (c instanceof UnmodifiableArrayList<?>) {
return (List<InternationalString>) c; // Unsafe cast okay because we allow only read operations.
} else {
- return UnmodifiableArrayList.wrap(c.toArray(new InternationalString[c.size()]));
+ return UnmodifiableArrayList.wrap(c.toArray(InternationalString[]::new));
}
}
diff --git a/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/LocationTypeTest.java b/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/LocationTypeTest.java
index 34a39716ff..e0c1bbe950 100644
--- a/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/LocationTypeTest.java
+++ b/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/LocationTypeTest.java
@@ -16,7 +16,6 @@
*/
package org.apache.sis.referencing.gazetteer;
-import java.util.List;
import org.opengis.metadata.extent.GeographicDescription;
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.TestUtilities;
@@ -183,8 +182,7 @@ public final strictfp class LocationTypeTest extends TestCase {
@Test
@DependsOnMethod("testInheritance")
public void testSnapshot() {
- final List<LocationType> snapshot = ModifiableLocationType.snapshot(null, create(true));
- verify(snapshot.toArray(new LocationType[snapshot.size()]));
+ verify(ModifiableLocationType.snapshot(null, create(true)).toArray(LocationType[]::new));
}
/**
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java b/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
index b4379cf924..a0c584a66c 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
@@ -1006,7 +1006,7 @@ poles: for (int i=0; i<dimension; i++) {
if (results.isEmpty() && transformed != null) {
return new GeneralEnvelope[] {transformed};
}
- return results.toArray(new GeneralEnvelope[results.size()]);
+ return results.toArray(GeneralEnvelope[]::new);
}
/**
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java
index 2d176c9407..e46526a812 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java
@@ -23,7 +23,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Collection;
import java.util.LinkedHashMap;
-import java.lang.reflect.Array;
import javax.xml.bind.annotation.XmlElementRef;
import org.opengis.util.GenericName;
import org.opengis.metadata.Identifier;
@@ -292,7 +291,7 @@ public final class CC_GeneralOperationParameter extends PropertyType<CC_GeneralO
if (isGroup) {
final List<GeneralParameterDescriptor> descriptors = ((ParameterDescriptorGroup) provided).descriptors();
return merge(DefaultParameterValueGroup.class, merged, merged, minimumOccurs, maximumOccurs,
- descriptors.toArray(new GeneralParameterDescriptor[descriptors.size()]),
+ descriptors.toArray(GeneralParameterDescriptor[]::new),
(ParameterDescriptorGroup) complete, canSubstitute);
} else {
return create(merged, (ParameterDescriptor<?>) provided, (ParameterDescriptor<?>) complete);
@@ -465,7 +464,7 @@ public final class CC_GeneralOperationParameter extends PropertyType<CC_GeneralO
c.remove(toNamedIdentifier(remove));
provided = c.values();
}
- complete = provided.toArray((T[]) Array.newInstance(componentType, provided.size()));
+ complete = CollectionsExt.toArray(provided, componentType);
merged.put(key, complete);
}
}
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java
index b419bc78eb..4c85779a3d 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java
@@ -233,7 +233,7 @@ public final class CC_OperationMethod extends PropertyType<CC_OperationMethod, O
final ParameterValueGroup source = (ParameterValueGroup) p;
final ParameterValueGroup target = new DefaultParameterValueGroup((ParameterDescriptorGroup) replacement);
final Collection<GeneralParameterValue> values = source.values();
- store(values.toArray(new GeneralParameterValue[values.size()]), target.values(), replacements);
+ store(values.toArray(GeneralParameterValue[]::new), target.values(), replacements);
p = target;
}
}
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroup.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroup.java
index 15b225cf69..a6429361f1 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroup.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroup.java
@@ -206,7 +206,7 @@ public final class CC_OperationParameterGroup extends PropertyType<CC_OperationP
}
}
}
- return union.values().toArray(new GeneralParameterDescriptor[union.size()]);
+ return union.values().toArray(GeneralParameterDescriptor[]::new);
}
/**
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/TileOrganizer.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/TileOrganizer.java
index b19af5f604..ca13dadb93 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/TileOrganizer.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/TileOrganizer.java
@@ -365,7 +365,7 @@ public class TileOrganizer {
* First, compute the pyramid levels along the X axis. Transforms that we were unable
* to classify will be discarded from the first run and put in a subsequent run.
*/
- AffineTransform[] transforms = gridToCRS.toArray(new AffineTransform[gridToCRS.size()]);
+ AffineTransform[] transforms = gridToCRS.toArray(AffineTransform[]::new);
Arrays.sort(transforms, X_COMPARATOR);
int length = transforms.length;
while (length != 0) {
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridFile.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridFile.java
index f200d8dd1a..3cb4607a68 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridFile.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridFile.java
@@ -251,7 +251,7 @@ abstract class DatumShiftGridFile<C extends Quantity<C>, T extends Quantity<T>>
@SuppressWarnings({"rawtypes", "unchecked"})
final void setSubGrids(final Collection<DatumShiftGridFile<C,T>> children) {
if (subgrids != null) throw new IllegalStateException();
- subgrids = children.toArray(new DatumShiftGridFile[children.size()]);
+ subgrids = children.toArray(DatumShiftGridFile[]::new);
}
/**
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/NTv2.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/NTv2.java
index 39e33b5c3c..53004be904 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/NTv2.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/NTv2.java
@@ -367,7 +367,7 @@ public final class NTv2 extends AbstractProvider {
} else {
numGrids = 1;
}
- overviewKeys = header.keySet().toArray(new String[header.size()]);
+ overviewKeys = header.keySet().toArray(String[]::new);
}
/**
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PolarStereographicNorth.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PolarStereographicNorth.java
index ccadf50dcf..00664d8746 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PolarStereographicNorth.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PolarStereographicNorth.java
@@ -50,8 +50,7 @@ public final class PolarStereographicNorth extends AbstractStereographic {
static {
List<GeneralParameterDescriptor> sp = PolarStereographicSouth.PARAMETERS.descriptors();
sp = sp.subList(2, sp.size()); // Skip the "semi-major" and "semi-minor" parameters.
- @SuppressWarnings("SuspiciousToArrayCall") // We know PolarStereographicSouth content.
- ParameterDescriptor<?>[] parameters = sp.toArray(new ParameterDescriptor<?>[sp.size()]);
+ ParameterDescriptor<?>[] parameters = sp.toArray(ParameterDescriptor<?>[]::new);
// Replace the "Standard Parallel" parameter from [-90 … 0]° domain to [0 … 90]° domain.
final ParameterBuilder builder = builder();
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java b/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
index 4ae099d821..5e7d134fb7 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
@@ -753,7 +753,7 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo
axis = parseAxis(list.size() < dimension ? MANDATORY : OPTIONAL, parent, type, defaultUnit);
} while (axis != null);
if (!isWKT1 || !ignoreAxes) {
- axes = list.toArray(new CoordinateSystemAxis[list.size()]);
+ axes = list.toArray(CoordinateSystemAxis[]::new);
Arrays.sort(axes, this); // Take ORDER[n] elements in account.
}
}
@@ -2199,7 +2199,7 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo
try {
return new EllipsoidalHeightCombiner(factories).createCompoundCRS(
parseMetadataAndClose(element, name, null),
- components.toArray(new CoordinateReferenceSystem[components.size()]));
+ components.toArray(CoordinateReferenceSystem[]::new));
} catch (FactoryException exception) {
throw element.parseFailed(exception);
}
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java b/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
index 33cc59e093..e1ee9b984e 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
@@ -190,7 +190,7 @@ public class DefaultParameterDescriptorGroup extends AbstractParameterDescriptor
|| ((DefaultParameterDescriptorGroup) parameters).descriptors != descriptors)
{
// Note sure where the list come from, we are better to copy its content.
- final GeneralParameterDescriptor[] p = descriptors.toArray(new GeneralParameterDescriptor[descriptors.size()]);
+ final GeneralParameterDescriptor[] p = descriptors.toArray(GeneralParameterDescriptor[]::new);
verifyNames(properties, p);
descriptors = asList(p);
}
@@ -245,7 +245,7 @@ public class DefaultParameterDescriptorGroup extends AbstractParameterDescriptor
{
descriptors = c; // Share the immutable instance (no need to clone).
} else {
- descriptors = asList(c.toArray(new GeneralParameterDescriptor[c.size()]));
+ descriptors = asList(c.toArray(GeneralParameterDescriptor[]::new));
}
}
@@ -471,8 +471,7 @@ public class DefaultParameterDescriptorGroup extends AbstractParameterDescriptor
*/
@XmlElement(name = "parameter", required = true)
private GeneralParameterDescriptor[] getDescriptors() {
- final List<GeneralParameterDescriptor> descriptors = descriptors(); // Give to user a chance to override.
- return descriptors.toArray(new GeneralParameterDescriptor[descriptors.size()]);
+ return descriptors().toArray(GeneralParameterDescriptor[]::new);
}
/**
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java b/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
index 4d7c64be86..908ab5c746 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
@@ -577,8 +577,7 @@ scan: for (final GeneralParameterValue param : actual.values()) {
*/
@XmlElement(name = "parameterValue", required = true)
private GeneralParameterValue[] getValues() {
- final List<GeneralParameterValue> values = values(); // Gives to user a chance to override.
- return values.toArray(new GeneralParameterValue[values.size()]);
+ return values().toArray(GeneralParameterValue[]::new);
}
/**
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterFormat.java b/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterFormat.java
index 2200a2a20a..deb1eef873 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterFormat.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterFormat.java
@@ -438,8 +438,7 @@ public class ParameterFormat extends TabularFormat<Object> {
.getString(Errors.Keys.UnsupportedType_1, object.getClass()));
}
if (isSummary) {
- final List<GeneralParameterDescriptor> parameters = descriptor.descriptors();
- formatSummary(parameters.toArray(new IdentifiedObject[parameters.size()]), toAppendTo);
+ formatSummary(descriptor.descriptors().toArray(IdentifiedObject[]::new), toAppendTo);
} else {
format(name.getCode(), descriptor, values, toAppendTo);
}
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
index 2c6f38ff1d..da9f292aa5 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
@@ -1048,8 +1048,8 @@ public abstract class Builder<B extends Builder<B>> {
valueAlias = null;
valueIds = null;
} else {
- valueAlias = aliases .toArray(new GenericName[aliases .size()]);
- valueIds = identifiers.toArray(new Identifier [identifiers.size()]);
+ valueAlias = aliases .toArray(GenericName[]::new);
+ valueIds = identifiers.toArray(Identifier[]::new);
}
properties.put(IdentifiedObject.ALIAS_KEY, valueAlias);
properties.put(IdentifiedObject.IDENTIFIERS_KEY, valueIds);
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 b576e8d34a..193212f7fc 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
@@ -985,7 +985,7 @@ public final class CRS extends Static {
}
final List<CoordinateReferenceSystem> components = new ArrayList<>(Long.bitCount(selected));
reduce(0, crs, dimension, selected, components);
- return compound(components.toArray(new CoordinateReferenceSystem[components.size()]));
+ return compound(components.toArray(CoordinateReferenceSystem[]::new));
}
/**
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java
index b7f572b173..2bfeba2f4a 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java
@@ -202,7 +202,7 @@ public class DefaultCompoundCRS extends AbstractCRS implements CompoundCRS {
* Note that this is already be done if the given array does not contain nested CompoundCRS.
*/
if (singles != this.components) {
- verify(properties, singles.toArray(new SingleCRS[singles.size()]));
+ verify(properties, singles.toArray(SingleCRS[]::new));
}
}
@@ -350,7 +350,7 @@ public class DefaultCompoundCRS extends AbstractCRS implements CompoundCRS {
if (setSingleComponents(crs)) {
components = singles; // Shares the same list.
} else {
- components = UnmodifiableArrayList.wrap(crs.toArray(new CoordinateReferenceSystem[crs.size()]));
+ components = UnmodifiableArrayList.wrap(crs.toArray(CoordinateReferenceSystem[]::new));
}
}
@@ -380,7 +380,7 @@ public class DefaultCompoundCRS extends AbstractCRS implements CompoundCRS {
private boolean setSingleComponents(final List<? extends CoordinateReferenceSystem> crs) {
final List<SingleCRS> flattened = new ArrayList<>(crs.size());
final boolean identical = ReferencingUtilities.getSingleComponents(crs, flattened);
- singles = UnmodifiableArrayList.wrap(flattened.toArray(new SingleCRS[flattened.size()]));
+ singles = UnmodifiableArrayList.wrap(flattened.toArray(SingleCRS[]::new));
return identical;
}
@@ -649,8 +649,7 @@ public class DefaultCompoundCRS extends AbstractCRS implements CompoundCRS {
@XmlJavaTypeAdapter(SC_CRS.class)
@XmlElement(name = "componentReferenceSystem", required = true)
private CoordinateReferenceSystem[] getXMLComponents() {
- final List<SingleCRS> crs = getSingleComponents();
- return crs.toArray(new CoordinateReferenceSystem[crs.size()]);
+ return getSingleComponents().toArray(CoordinateReferenceSystem[]::new);
}
/**
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CacheRecord.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CacheRecord.java
index 86e5726b71..254bf101f6 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CacheRecord.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CacheRecord.java
@@ -120,7 +120,7 @@ final class CacheRecord implements Comparable<CacheRecord> {
}
codeLength += 2;
identityLength += 2;
- final CacheRecord[] records = list.toArray(new CacheRecord[list.size()]);
+ final CacheRecord[] records = list.toArray(CacheRecord[]::new);
Arrays.sort(records);
if (out == null) {
final Console c = System.console();
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/IdentifiedObjectSet.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/IdentifiedObjectSet.java
index c8f6794fc4..1ec563eb4c 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/IdentifiedObjectSet.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/IdentifiedObjectSet.java
@@ -200,7 +200,7 @@ public class IdentifiedObjectSet<T extends IdentifiedObject> extends AbstractSet
synchronized (objects) {
if (codes == null) {
final Set<String> keys = objects.keySet();
- codes = keys.toArray(new String[keys.size()]);
+ codes = keys.toArray(String[]::new);
}
return codes;
}
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
index 5128c2ad48..32f4666d1d 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
@@ -1813,7 +1813,7 @@ public class MultiAuthoritiesFactory extends GeodeticAuthorityFactory implements
}
}
}
- finders = list.toArray(new IdentifiedObjectFinder[list.size()]);
+ finders = list.toArray(IdentifiedObjectFinder[]::new);
} catch (BackingStoreException e) {
throw e.unwrapOrRethrow(FactoryException.class);
}
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
index f4a9c48357..b19617cede 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
@@ -1177,7 +1177,7 @@ codes: for (int i=0; i<codes.length; i++) {
properties.put(IdentifiedObject.NAME_KEY, id);
}
if (!aliases.isEmpty()) {
- properties.put(IdentifiedObject.ALIAS_KEY, aliases.toArray(new GenericName[aliases.size()]));
+ properties.put(IdentifiedObject.ALIAS_KEY, aliases.toArray(GenericName[]::new));
}
if (code != null) {
final String codeString = code.toString();
@@ -2675,7 +2675,7 @@ next: while (r.next()) {
descriptors.add(owner.createParameterDescriptor(getString(method, result, 1)));
}
}
- return descriptors.toArray(new ParameterDescriptor<?>[descriptors.size()]);
+ return descriptors.toArray(ParameterDescriptor<?>[]::new);
}
/**
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
index 850def6aa2..ae1bbb40c5 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
@@ -393,7 +393,7 @@ class AbstractSingleOperation extends AbstractCoordinateOperation implements Sin
if (parameters != null) {
final List<GeneralParameterValue> values = parameters.values();
if (values != null) { // Paranoiac check (should not be allowed).
- return CC_OperationMethod.filterImplicit(values.toArray(new GeneralParameterValue[values.size()]));
+ return CC_OperationMethod.filterImplicit(values.toArray(GeneralParameterValue[]::new));
}
}
return null;
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationRegistry.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationRegistry.java
index 03c3eec299..dbd3cf6989 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationRegistry.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationRegistry.java
@@ -865,7 +865,7 @@ class CoordinateOperationRegistry {
*/
if (operation instanceof ConcatenatedOperation) {
final List<? extends CoordinateOperation> c = ((ConcatenatedOperation) operation).getOperations();
- final CoordinateOperation[] op = c.toArray(new CoordinateOperation[c.size()]);
+ final CoordinateOperation[] op = c.toArray(CoordinateOperation[]::new);
switch (op.length) {
case 0: break; // Illegal, but we are paranoiac.
case 1: operation = op[0]; break; // Useless ConcatenatedOperation.
@@ -1040,8 +1040,7 @@ class CoordinateOperationRegistry {
case 0: return null;
case 1: return operations.get(0);
default: return factory.createConcatenatedOperation(derivedFrom(operation),
- operations.toArray(new CoordinateOperation[operations.size()]));
-
+ operations.toArray(CoordinateOperation[]::new));
}
}
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConcatenatedOperation.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConcatenatedOperation.java
index f3ec6afb34..a63547a52a 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConcatenatedOperation.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConcatenatedOperation.java
@@ -145,7 +145,7 @@ final class DefaultConcatenatedOperation extends AbstractCoordinateOperation imp
* At this point we should have flattened.size() >= 2, except if some operations
* were omitted because their associated math transform were identity operation.
*/
- this.operations = UnmodifiableArrayList.wrap(flattened.toArray(new CoordinateOperation[flattened.size()]));
+ this.operations = UnmodifiableArrayList.wrap(flattened.toArray(CoordinateOperation[]::new));
}
/**
@@ -236,8 +236,7 @@ final class DefaultConcatenatedOperation extends AbstractCoordinateOperation imp
}
if (op instanceof ConcatenatedOperation) {
final List<? extends CoordinateOperation> children = ((ConcatenatedOperation) op).getOperations();
- @SuppressWarnings("SuspiciousToArrayCall")
- final CoordinateOperation[] asArray = children.toArray(new CoordinateOperation[children.size()]);
+ final CoordinateOperation[] asArray = children.toArray(CoordinateOperation[]::new);
initialize(properties, asArray, flattened, (step == null) ? mtFactory : null, false, setAccuracy, setDomain);
} else if (!step.isIdentity()) {
flattened.add(op);
@@ -423,7 +422,7 @@ final class DefaultConcatenatedOperation extends AbstractCoordinateOperation imp
@XmlElement(name = "coordOperation", required = true)
private CoordinateOperation[] getSteps() {
final List<? extends CoordinateOperation> operations = getOperations();
- return (operations != null) ? operations.toArray(new CoordinateOperation[operations.size()]) : null;
+ return (operations != null) ? operations.toArray(CoordinateOperation[]::new) : null;
}
/**
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java
index 7801da0439..97ccaf727a 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java
@@ -932,8 +932,7 @@ public class DefaultOperationMethod extends AbstractIdentifiedObject implements
if (parameters != null) {
final List<GeneralParameterDescriptor> descriptors = parameters.descriptors();
if (descriptors != null) { // Paranoiac check (should not be allowed).
- return CC_OperationMethod.filterImplicit(descriptors.toArray(
- new GeneralParameterDescriptor[descriptors.size()]));
+ return CC_OperationMethod.filterImplicit(descriptors.toArray(GeneralParameterDescriptor[]::new));
}
}
return null;
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/InverseOperationMethod.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/InverseOperationMethod.java
index 41c50daba7..533333a95c 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/InverseOperationMethod.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/InverseOperationMethod.java
@@ -143,7 +143,7 @@ final class InverseOperationMethod extends DefaultOperationMethod {
final Collection<PositionalAccuracy> accuracy = source.getCoordinateOperationAccuracy();
if (!Containers.isNullOrEmpty(accuracy)) {
target.put(SingleOperation.COORDINATE_OPERATION_ACCURACY_KEY,
- accuracy.toArray(new PositionalAccuracy[accuracy.size()]));
+ accuracy.toArray(PositionalAccuracy[]::new));
}
/*
* If the inverse of the given operation can be represented by inverting the sign of all numerical
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
index b17eba9dc5..d4e804c289 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
@@ -1697,7 +1697,7 @@ search: for (int j=domain(); --j >= 0;) {
* └────────────┴─────────────┘
*/
if (linearizers != null) {
- final ProjectedTransformTry[] alternatives = linearizers.toArray(new ProjectedTransformTry[linearizers.size()]);
+ final var alternatives = linearizers.toArray(ProjectedTransformTry[]::new);
Arrays.sort(alternatives);
buffer.append(Strings.CONTINUATION_ITEM);
vocabulary.appendLabel(Vocabulary.Keys.Preprocessing, buffer);
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java b/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java
index cec3e888c1..c4622ecd5a 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java
@@ -116,8 +116,8 @@ public final strictfp class CC_OperationParameterGroupTest extends TestCase {
final List<GeneralParameterDescriptor> fromXML = unmarshal().descriptors();
final List<GeneralParameterDescriptor> fromValues = UnmodifiableArrayList.wrap(expected);
final Map<GeneralParameterDescriptor,GeneralParameterDescriptor> replacements = new IdentityHashMap<>(4);
- final GeneralParameterDescriptor[] merged = CC_OperationParameterGroup.merge(fromXML,
- fromValues.toArray(new GeneralParameterDescriptor[fromValues.size()]), replacements);
+ final var merged = CC_OperationParameterGroup.merge(fromXML,
+ fromValues.toArray(GeneralParameterDescriptor[]::new), replacements);
assertTrue("Expected no replacement.", replacements.isEmpty());
assertEquals("Number of parameters", 2, merged.length);
@@ -179,7 +179,7 @@ public final strictfp class CC_OperationParameterGroupTest extends TestCase {
List<GeneralParameterDescriptor> descriptors = group.descriptors();
// Merge with the parameters defined in Mercator1SP class
- group = CC_OperationMethod.group(group.getName(), descriptors.toArray(new GeneralParameterDescriptor[descriptors.size()]));
+ group = CC_OperationMethod.group(group.getName(), descriptors.toArray(GeneralParameterDescriptor[]::new));
descriptors = group.descriptors();
assertSame("name", group.getName(), group.getName());
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueGroupTest.java b/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueGroupTest.java
index 98dbebb8fb..45b145258e 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueGroupTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueGroupTest.java
@@ -240,10 +240,10 @@ public final strictfp class DefaultParameterValueGroupTest extends TestCase {
final DefaultParameterDescriptorGroup group, subGroup;
final List<GeneralParameterDescriptor> descriptors = new ArrayList<>(descriptor.descriptors());
subGroup = new DefaultParameterDescriptorGroup(singletonMap(NAME_KEY, "theSubGroup"),
- 2, 4, descriptors.toArray(new GeneralParameterDescriptor[descriptors.size()]));
+ 2, 4, descriptors.toArray(GeneralParameterDescriptor[]::new));
descriptors.add(subGroup);
group = new DefaultParameterDescriptorGroup(singletonMap(NAME_KEY, "theGroup"),
- descriptors.toArray(new GeneralParameterDescriptor[descriptors.size()]));
+ descriptors.toArray(GeneralParameterDescriptor[]::new));
/*
* Prepare the GeneralParameterValue instances that we are going to add in the above group.
* We assign arbitrary integer values to each instance if order to be able to differentiate
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterFormatTest.java b/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterFormatTest.java
index 40b081fdd8..9c2897c3db 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterFormatTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterFormatTest.java
@@ -274,7 +274,7 @@ public final strictfp class ParameterFormatTest extends TestCase {
"│ EPSG:9804 │ Mercator (variant A) │ Mercator_1SP │\n" +
"└────────────┴──────────────────────┴──────────────┘\n", text);
- text = format.format(parameters.toArray(new IdentifiedObject[parameters.size()]));
+ text = format.format(parameters.toArray(IdentifiedObject[]::new));
assertMultilinesEquals(
"┌────────────┬────────────────────────────────┬────────────────────┐\n" +
"│ Identifier │ EPSG │ OGC │\n" +
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
index ad448a43dd..eb5fa53043 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
@@ -59,7 +59,7 @@ public final strictfp class AbstractIdentifiedObjectTest extends TestCase {
private static Map<String,Object> properties(final Set<Identifier> identifiers) {
final Map<String,Object> properties = new HashMap<>(8);
assertNull(properties.put("name", "GRS 1980"));
- assertNull(properties.put("identifiers", identifiers.toArray(new Identifier[identifiers.size()])));
+ assertNull(properties.put("identifiers", identifiers.toArray(Identifier[]::new)));
assertNull(properties.put("codespace", "EPSG"));
assertNull(properties.put("version", "8.3"));
assertNull(properties.put("alias", "International 1979"));
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateReferenceSystems.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateReferenceSystems.java
index 4ffbcc9362..ed8436a185 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateReferenceSystems.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateReferenceSystems.java
@@ -774,7 +774,7 @@ public final strictfp class CoordinateReferenceSystems extends AuthorityCodesRep
protected void sortRows() {
super.sortRows();
@SuppressWarnings("SuspiciousToArrayCall")
- final ByName[] data = rows.toArray(new ByName[rows.size()]);
+ final ByName[] data = rows.toArray(ByName[]::new);
final Map<String,String> sections = new TreeMap<>();
for (final ByName row : data) {
final String section = row.section;
diff --git a/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java b/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
index 40f4a821f3..c8e40dc6ff 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
@@ -424,7 +424,7 @@ public final class DefinitionURI {
orderedComponents.put(sequenceNumber, parse(uri, isURN, splitAt, next));
splitAt = next;
} while (hasMore);
- result.components = orderedComponents.values().toArray(new DefinitionURI[orderedComponents.size()]);
+ result.components = orderedComponents.values().toArray(DefinitionURI[]::new);
}
// Fall through
}
diff --git a/core/sis-utility/src/main/java/org/apache/sis/math/StatisticsFormat.java b/core/sis-utility/src/main/java/org/apache/sis/math/StatisticsFormat.java
index 26211f98e0..d691628148 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/math/StatisticsFormat.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/math/StatisticsFormat.java
@@ -272,7 +272,7 @@ public class StatisticsFormat extends TabularFormat<Statistics> {
list.add(stats);
stats = stats.differences();
}
- format(list.toArray(new Statistics[list.size()]), toAppendTo);
+ format(list.toArray(Statistics[]::new), toAppendTo);
}
/**
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/Classes.java b/core/sis-utility/src/main/java/org/apache/sis/util/Classes.java
index a06899ab97..e41f8bec63 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/Classes.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/Classes.java
@@ -412,10 +412,10 @@ public final class Classes extends Static {
*
* @see Class#getInterfaces()
*/
- @SuppressWarnings({"unchecked","rawtypes"}) // Generic array creation.
+ @SuppressWarnings({"unchecked","rawtypes"})
public static <T> Class<? super T>[] getAllInterfaces(final Class<T> type) {
final Set<Class<?>> interfaces = getInterfaceSet(type);
- return (interfaces != null) ? interfaces.toArray(new Class[interfaces.size()]) : EMPTY_ARRAY;
+ return (interfaces != null) ? interfaces.toArray(Class[]::new) : EMPTY_ARRAY;
}
/**
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java b/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java
index ed0e0f9cbf..4075275b12 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java
@@ -180,7 +180,7 @@ public class DefaultTreeTable implements TreeTable, Cloneable, Serializable {
* {@link UnmodifiableArrayList#wrap(Object[])}.
*/
static TableColumn<?>[] getColumns(final Map<TableColumn<?>,Integer> columnIndices) {
- return columnIndices.keySet().toArray(new TableColumn<?>[columnIndices.size()]);
+ return columnIndices.keySet().toArray(TableColumn<?>[]::new);
}
/**
@@ -433,7 +433,7 @@ public class DefaultTreeTable implements TreeTable, Cloneable, Serializable {
columnIndices = ((DefaultTreeTable) table).columnIndices;
} else {
final List<TableColumn<?>> columns = table.getColumns();
- columnIndices = createColumnIndices(columns.toArray(new TableColumn<?>[columns.size()]));
+ columnIndices = createColumnIndices(columns.toArray(TableColumn<?>[]::new));
}
}
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/collection/FrequencySortedSet.java b/core/sis-utility/src/main/java/org/apache/sis/util/collection/FrequencySortedSet.java
index 187872bf5c..4777b12d5d 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/collection/FrequencySortedSet.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/collection/FrequencySortedSet.java
@@ -554,8 +554,7 @@ public class FrequencySortedSet<E> extends AbstractSet<E> implements SortedSet<E
@SuppressWarnings("unchecked")
private void ensureSorted() {
if (sorted == null) {
- @SuppressWarnings("rawtypes") // Generic array creation.
- final Map.Entry<E,Integer>[] entries = count.entrySet().toArray(new Map.Entry[count.size()]);
+ final Map.Entry<E,Integer>[] entries = count.entrySet().toArray(Map.Entry[]::new);
Arrays.sort(entries, COMPARATOR);
final int length = entries.length;
sorted = (E[]) new Object[length];
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java b/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
index 129b793b31..8995ce2ba1 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
@@ -21,7 +21,6 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
-import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import java.util.ConcurrentModificationException;
@@ -881,8 +880,7 @@ public class TreeTableFormat extends TabularFormat<TreeTable> {
if (columnIndices != null) {
columns = DefaultTreeTable.getColumns(columnIndices);
} else {
- final List<TableColumn<?>> c = tree.getColumns();
- columns = c.toArray(new TableColumn<?>[c.size()]);
+ columns = tree.getColumns().toArray(TableColumn<?>[]::new);
}
if (recursivityGuard == null) {
recursivityGuard = new HashSet<>();
diff --git a/core/sis-utility/src/test/java/org/apache/sis/test/TestRunner.java b/core/sis-utility/src/test/java/org/apache/sis/test/TestRunner.java
index 515691284c..4c9086f90b 100644
--- a/core/sis-utility/src/test/java/org/apache/sis/test/TestRunner.java
+++ b/core/sis-utility/src/test/java/org/apache/sis/test/TestRunner.java
@@ -232,8 +232,7 @@ public final class TestRunner extends BlockJUnit4ClassRunner {
@SuppressWarnings("ReturnOfCollectionOrArrayField")
private FrameworkMethod[] getFilteredChildren() {
if (filteredChildren == null) {
- final List<FrameworkMethod> children = super.getChildren();
- filteredChildren = children.toArray(new FrameworkMethod[children.size()]);
+ filteredChildren = super.getChildren().toArray(FrameworkMethod[]::new);
sortDependantTestsLast(filteredChildren);
}
return filteredChildren;
diff --git a/core/sis-utility/src/test/java/org/apache/sis/util/collection/LargeCodeList.java b/core/sis-utility/src/test/java/org/apache/sis/util/collection/LargeCodeList.java
index d092729328..e4ed49b7c2 100644
--- a/core/sis-utility/src/test/java/org/apache/sis/util/collection/LargeCodeList.java
+++ b/core/sis-utility/src/test/java/org/apache/sis/util/collection/LargeCodeList.java
@@ -63,7 +63,7 @@ public final strictfp class LargeCodeList extends CodeList<LargeCodeList> {
*/
public static LargeCodeList[] values() {
synchronized (VALUES) {
- return VALUES.toArray(new LargeCodeList[VALUES.size()]);
+ return VALUES.toArray(LargeCodeList[]::new);
}
}
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 2cec0e68f7..51ff4268ce 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
@@ -535,7 +535,7 @@ final class CRSBuilder extends ReferencingFactoryContainer {
* Returns all remaining keys, sorted in increasing order.
*/
private Short[] remainingKeys() {
- final Short[] keys = geoKeys.keySet().toArray(new Short[geoKeys.size()]);
+ final Short[] keys = geoKeys.keySet().toArray(Short[]::new);
Arrays.sort(keys);
return keys;
}
diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Localization.java b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Localization.java
index 7f4374d755..239e83e1d7 100644
--- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Localization.java
+++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Localization.java
@@ -210,7 +210,7 @@ final class Localization {
for (int i=0; i<n; i++) {
uniques.add(values.doubleValue(i));
}
- final Double[] array = uniques.toArray(new Double[uniques.size()]);
+ final Double[] array = uniques.toArray(Double[]::new);
uniques.clear();
int i = array.length;
if (i >= 3) {
diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/MultiResolutionImage.java b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/MultiResolutionImage.java
index 68e5d906f2..282cabd041 100644
--- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/MultiResolutionImage.java
+++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/MultiResolutionImage.java
@@ -85,7 +85,7 @@ final class MultiResolutionImage extends GridResourceWrapper implements Resource
* from finest resolution to coarsest resolution. The full-resolution image shall be at index 0.
*/
MultiResolutionImage(final List<ImageFileDirectory> overviews) {
- levels = overviews.toArray(new ImageFileDirectory[overviews.size()]);
+ levels = overviews.toArray(ImageFileDirectory[]::new);
resolutions = new double[levels.length][];
}
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
index 0cc57c072e..a8502ffc91 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
@@ -589,7 +589,7 @@ public final class Axis extends NamedElement {
}
}
if (!aliases.isEmpty()) {
- properties.put(CoordinateSystemAxis.ALIAS_KEY, aliases.toArray(new GenericName[aliases.size()]));
+ properties.put(CoordinateSystemAxis.ALIAS_KEY, aliases.toArray(GenericName[]::new));
}
/*
* Axis abbreviation, direction and unit of measurement are mandatory. If any of them is null,
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/FeatureSet.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/FeatureSet.java
index ab457dade6..3e44370e91 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/FeatureSet.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/FeatureSet.java
@@ -355,7 +355,7 @@ final class FeatureSet extends DiscreteSampling {
addFeatureSet(features, decoder, null, dimension, dimension, lock);
}
}
- return features.toArray(new FeatureSet[features.size()]);
+ return features.toArray(FeatureSet[]::new);
}
/**
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/RasterResource.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/RasterResource.java
index 5aeec3d323..e470c9cb8c 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/RasterResource.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/RasterResource.java
@@ -199,7 +199,7 @@ public final class RasterResource extends AbstractGridCoverageResource implement
identifier = decoder.nameFactory.createLocalName(decoder.namespace, name);
visibleBand = decoder.convention().getVisibleBand();
sampleDimensions = new SampleDimension[numBands];
- data = bands.toArray(new Variable[bands.size()]);
+ data = bands.toArray(Variable[]::new);
assert data.length == (bandDimension >= 0 ? 1 : sampleDimensions.length);
}
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
index 2c8b707160..e6806fd169 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
@@ -599,7 +599,7 @@ public abstract class Variable extends Node {
*/
boolean isIncomplete = false;
final List<Dimension> fromVariable = getGridDimensions();
- final Dimension[] dimensions = fromVariable.toArray(new Dimension[fromVariable.size()]);
+ final Dimension[] dimensions = fromVariable.toArray(Dimension[]::new);
for (int i=0; i<dimensions.length; i++) {
isIncomplete |= ((dimensions[i] = domain.remove(dimensions[i])) == null);
}
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
index bd59558dfb..ab2c94e325 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
@@ -1033,14 +1033,14 @@ nextVar: for (final VariableInfo variable : variables) {
* from the "coordinates" attribute and axes inferred from variable names matching dimension names, we
* use axes from "coordinates" attribute first followed by other axes.
*/
- GridInfo grid = new GridInfo(variable.dimensions, axes.toArray(new VariableInfo[axes.size()]));
+ GridInfo grid = new GridInfo(variable.dimensions, axes.toArray(VariableInfo[]::new));
GridInfo existing = shared.putIfAbsent(grid, grid);
if (existing != null) {
grid = existing;
}
variable.grid = grid;
}
- gridGeometries = shared.values().toArray(new Grid[shared.size()]);
+ gridGeometries = shared.values().toArray(Grid[]::new);
}
return gridGeometries;
}
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
index aa9b596238..872a3891f1 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
@@ -238,7 +238,7 @@ public class NetcdfStore extends DataStore implements Aggregate {
final List<Resource> grids = RasterResource.create(decoder, this);
if (!grids.isEmpty()) {
grids.addAll(UnmodifiableArrayList.wrap(resources));
- resources = grids.toArray(new Resource[grids.size()]);
+ resources = grids.toArray(Resource[]::new);
}
components = UnmodifiableArrayList.wrap(resources);
} catch (IOException e) {
diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Database.java b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Database.java
index 22f31c226a..81f388edd0 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Database.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Database.java
@@ -379,7 +379,7 @@ public class Database<G> extends Syntax {
hasGeometry |= table.hasGeometry;
hasRaster |= table.hasRaster;
}
- tables = tableList.toArray(new Table[tableList.size()]);
+ tables = tableList.toArray(Table[]::new);
}
/**
@@ -398,7 +398,7 @@ public class Database<G> extends Syntax {
}
}
}
- return types.toArray(new String[types.size()]);
+ return types.toArray(String[]::new);
}
/**
diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/PrimaryKey.java b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/PrimaryKey.java
index 49c58c3d0b..c722f377ae 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/PrimaryKey.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/PrimaryKey.java
@@ -99,7 +99,7 @@ abstract class PrimaryKey {
/** Creates a new primary key composed of the given columns. */
Composite(final Class<?> valueClass, final Collection<String> columns) {
super(valueClass);
- this.columns = UnmodifiableArrayList.wrap(columns.toArray(new String[columns.size()]));
+ this.columns = UnmodifiableArrayList.wrap(columns.toArray(String[]::new));
}
/** Returns all columns composing this primary key. */
diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/QueryAnalyzer.java b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/QueryAnalyzer.java
index d149a0bf8f..1b14582358 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/QueryAnalyzer.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/QueryAnalyzer.java
@@ -181,6 +181,6 @@ final class QueryAnalyzer extends FeatureAnalyzer {
attributes.add(column);
}
}
- return attributes.toArray(new Column[attributes.size()]);
+ return attributes.toArray(Column[]::new);
}
}
diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/TableAnalyzer.java b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/TableAnalyzer.java
index b8b4387edc..5d7f8a0e65 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/TableAnalyzer.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/TableAnalyzer.java
@@ -179,7 +179,7 @@ final class TableAnalyzer extends FeatureAnalyzer {
attributes.add(column);
}
}
- return attributes.toArray(new Column[attributes.size()]);
+ return attributes.toArray(Column[]::new);
}
/**
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
index 27f9685fb7..2754466ad2 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
@@ -580,7 +580,7 @@ final class Store extends URIDataStore implements FeatureSet {
}
final String name = IOUtilities.filenameWithoutExtension(super.getDisplayName());
return new DefaultFeatureType(Collections.singletonMap(DefaultFeatureType.NAME_KEY, name),
- false, null, properties.toArray(new PropertyType[properties.size()]));
+ false, null, properties.toArray(PropertyType[]::new));
}
/**
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/Store.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/Store.java
index c666058311..5e3be6dc13 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/Store.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/Store.java
@@ -378,7 +378,7 @@ class Store extends DataStore implements StoreResource, UnstructuredAggregate, D
} catch (BackingStoreException ex) {
throw ex.unwrapOrRethrow(DataStoreException.class);
}
- components = UnmodifiableArrayList.wrap(resources.toArray(new Resource[resources.size()]));
+ components = UnmodifiableArrayList.wrap(resources.toArray(Resource[]::new));
}
return components; // Safe because unmodifiable list.
}
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/AggregatedFeatureSet.java b/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/AggregatedFeatureSet.java
index 856c6512c4..b05db5c0f3 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/AggregatedFeatureSet.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/AggregatedFeatureSet.java
@@ -125,7 +125,7 @@ abstract class AggregatedFeatureSet extends AbstractFeatureSet {
if (!isEnvelopeComputed) {
final List<Envelope> envelopes = new ArrayList<>();
if (getEnvelopes(envelopes)) try {
- envelope = ImmutableEnvelope.castOrCopy(Envelopes.union(envelopes.toArray(new Envelope[envelopes.size()])));
+ envelope = ImmutableEnvelope.castOrCopy(Envelopes.union(envelopes.toArray(Envelope[]::new)));
} catch (TransformException e) {
listeners.warning(e);
}
diff --git a/storage/sis-storage/src/test/java/org/apache/sis/test/storage/CoverageReadConsistency.java b/storage/sis-storage/src/test/java/org/apache/sis/test/storage/CoverageReadConsistency.java
index 3c278e1050..0fab1ed840 100644
--- a/storage/sis-storage/src/test/java/org/apache/sis/test/storage/CoverageReadConsistency.java
+++ b/storage/sis-storage/src/test/java/org/apache/sis/test/storage/CoverageReadConsistency.java
@@ -449,7 +449,7 @@ nextSlice: for (;;) {
public static void printDurations() {
if (statistics != null) {
// It is too late for using `TestCase.out`.
- System.out.print(StatisticsFormat.getInstance().format(statistics.toArray(new Statistics[statistics.size()])));
+ System.out.print(StatisticsFormat.getInstance().format(statistics.toArray(Statistics[]::new)));
statistics = null;
}
}
diff --git a/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Metadata.java b/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Metadata.java
index 63f1a5f9f6..6d081c0108 100644
--- a/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Metadata.java
+++ b/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Metadata.java
@@ -306,7 +306,7 @@ public final class Metadata extends SimpleMetadata {
@Override
public Collection<Keywords> getDescriptiveKeywords() {
if (keywords != null) {
- return Collections.singletonList(new DefaultKeywords(keywords.toArray(new String[keywords.size()])));
+ return Collections.singletonList(new DefaultKeywords(keywords.toArray(String[]::new)));
}
return Collections.emptyList();
}
[sis] 01/02: Reduce the use of `CollectionsExt` when Java 11 methods can do the work.
Posted by de...@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 eaf802470811a6639488361f789764e9fb10f4df
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Sat Dec 10 22:50:03 2022 +0100
Reduce the use of `CollectionsExt` when Java 11 methods can do the work.
---
.../apache/sis/coverage/grid/ImageRenderer.java | 3 +-
.../sis/internal/jaxb/NonMarshalledAuthority.java | 2 +-
.../src/main/java/org/apache/sis/xml/Pooled.java | 3 +-
.../main/java/org/apache/sis/xml/Transformer.java | 17 +-
.../java/org/apache/sis/test/MetadataAssert.java | 3 +-
.../coverage/MultiResolutionCoverageLoader.java | 3 +-
.../referencing/GeodeticObjectBuilder.java | 3 +-
.../referencing/factory/GeodeticObjectFactory.java | 12 +-
.../DefaultCoordinateOperationFactory.java | 12 +-
.../apache/sis/internal/util/CollectionsExt.java | 207 ++++-----------------
.../java/org/apache/sis/measure/UnitDimension.java | 12 +-
.../sis/internal/util/CollectionsExtTest.java | 18 +-
.../aggregate/ConcatenatedGridResource.java | 3 +-
.../apache/sis/storage/event/StoreListeners.java | 3 +-
14 files changed, 63 insertions(+), 238 deletions(-)
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ImageRenderer.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ImageRenderer.java
index 4b2073b4cf..337facc853 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ImageRenderer.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ImageRenderer.java
@@ -46,7 +46,6 @@ import org.apache.sis.internal.coverage.j2d.RasterFactory;
import org.apache.sis.internal.coverage.j2d.TiledImage;
import org.apache.sis.internal.coverage.j2d.WritableTiledImage;
import org.apache.sis.internal.feature.Resources;
-import org.apache.sis.internal.util.CollectionsExt;
import org.apache.sis.util.NullArgumentException;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.ArgumentChecks;
@@ -303,7 +302,7 @@ public class ImageRenderer {
*/
public ImageRenderer(final GridCoverage coverage, GridExtent sliceExtent) {
ArgumentChecks.ensureNonNull("coverage", coverage);
- bands = CollectionsExt.toArray(coverage.getSampleDimensions(), SampleDimension.class);
+ bands = coverage.getSampleDimensions().toArray(SampleDimension[]::new);
geometry = coverage.getGridGeometry();
final GridExtent source = geometry.getExtent();
final int dimension = source.getDimension();
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java
index 5633da9724..c7707e22e9 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java
@@ -269,7 +269,7 @@ public final class NonMarshalledAuthority<T> extends CitationConstant.Authority<
switch (merged.size()) {
case 0: return Collections.emptyList();
case 1: return Collections.singletonList(merged.get(0));
- default: return Containers.unmodifiableList(CollectionsExt.toArray(merged, Identifier.class));
+ default: return Containers.unmodifiableList(merged.toArray(Identifier[]::new));
}
}
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/Pooled.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/Pooled.java
index 53927dcf9b..cc112fc728 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/xml/Pooled.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/Pooled.java
@@ -36,7 +36,6 @@ import org.apache.sis.util.Version;
import org.apache.sis.util.ArraysExt;
import org.apache.sis.util.CharSequences;
import org.apache.sis.util.resources.Errors;
-import org.apache.sis.internal.util.CollectionsExt;
import org.apache.sis.internal.util.Strings;
import org.apache.sis.internal.jaxb.Context;
import org.apache.sis.internal.xml.LegacyNamespaces;
@@ -312,7 +311,7 @@ abstract class Pooled {
copy.put(key, (String) schema);
}
}
- copy = CollectionsExt.unmodifiableOrCopy(copy);
+ copy = Map.copyOf(copy);
}
schemas = copy;
return;
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/Transformer.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/Transformer.java
index 2c38fef814..dff0fcbeeb 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/xml/Transformer.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/Transformer.java
@@ -23,7 +23,6 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.InvalidPropertiesFormatException;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -35,7 +34,6 @@ import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.Namespace;
import org.apache.sis.util.CharSequences;
import org.apache.sis.util.resources.Errors;
-import org.apache.sis.internal.util.CollectionsExt;
import org.apache.sis.internal.jaxb.TypeRegistration;
@@ -185,7 +183,7 @@ abstract class Transformer {
namespaces = new HashMap<>();
outerElements = new ArrayList<>();
renamedAttributes = new ArrayList<>();
- outerElementProperties = Collections.emptyMap();
+ outerElementProperties = Map.of();
}
/**
@@ -365,9 +363,8 @@ abstract class Transformer {
}
/*
* At this point we finished computing the map values. Many values are maps with only 1 entry.
- * Save a little bit of space by replacing maps of 1 element by Collections.singletonMap(…).
*/
- m.replaceAll((k, v) -> CollectionsExt.compact(v));
+ m.replaceAll((k, v) -> Map.copyOf(v));
return m;
}
@@ -386,8 +383,8 @@ abstract class Transformer {
final List<Attribute> attributes() {
final List<Attribute> attributes;
switch (renamedAttributes.size()) {
- case 0: attributes = Collections.emptyList(); break; // Avoid object creation for this common case.
- case 1: attributes = Collections.singletonList(renamedAttributes.remove(0)); break;
+ case 0: attributes = List.of(); break; // Avoid object creation for this common case.
+ case 1: attributes = List.of(renamedAttributes.remove(0)); break;
default: attributes = Arrays.asList(renamedAttributes.toArray(new Attribute[renamedAttributes.size()]));
renamedAttributes.clear();
break;
@@ -422,7 +419,7 @@ abstract class Transformer {
String localPart = value.substring(s+1).trim();
QName name = new QName(namespace, localPart, prefix);
final Map<String,String> currentMap = outerElementProperties;
- outerElementProperties = renamingMap(namespace).getOrDefault(localPart, Collections.emptyMap());
+ outerElementProperties = renamingMap(namespace).getOrDefault(localPart, Map.of());
final boolean changed = (name != (name = convert(name)));
outerElementProperties = currentMap;
if (changed) {
@@ -493,7 +490,7 @@ abstract class Transformer {
final String localPart = name.getLocalPart();
if (isTypeElement(localPart)) {
outerElements.add(name);
- outerElementProperties = renamingMap(name.getNamespaceURI()).getOrDefault(localPart, Collections.emptyMap());
+ outerElementProperties = renamingMap(name.getNamespaceURI()).getOrDefault(localPart, Map.of());
}
}
@@ -519,7 +516,7 @@ abstract class Transformer {
namespace = XMLConstants.NULL_NS_URI;
localPart = null;
}
- outerElementProperties = renamingMap(namespace).getOrDefault(localPart, Collections.emptyMap());
+ outerElementProperties = renamingMap(namespace).getOrDefault(localPart, Map.of());
break;
}
}
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/test/MetadataAssert.java b/core/sis-metadata/src/test/java/org/apache/sis/test/MetadataAssert.java
index 0081be869e..04269a6334 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/test/MetadataAssert.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/test/MetadataAssert.java
@@ -30,7 +30,6 @@ import org.opengis.metadata.content.FeatureCatalogueDescription;
import org.apache.sis.xml.Namespaces;
import org.apache.sis.test.xml.DocumentComparator;
import org.apache.sis.internal.xml.LegacyNamespaces;
-import org.apache.sis.internal.util.CollectionsExt;
import static org.apache.sis.test.TestUtilities.getSingleton;
@@ -121,7 +120,7 @@ public strictfp class MetadataAssert extends Assert {
final Scope scope = source.getScope();
assertNotNull("metadata.lineage.source.scope", scope);
assertEquals("metadata.lineage.source.scope.level", ScopeCode.FEATURE_TYPE, scope.getLevel());
- final CharSequence[] actual = CollectionsExt.toArray(getSingleton(scope.getLevelDescription()).getFeatures(), CharSequence.class);
+ final var actual = getSingleton(scope.getLevelDescription()).getFeatures().toArray(CharSequence[]::new);
for (int i=0; i<actual.length; i++) {
actual[i] = actual[i].toString();
}
diff --git a/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/coverage/MultiResolutionCoverageLoader.java b/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/coverage/MultiResolutionCoverageLoader.java
index 997ebdb70b..bb54bff5e7 100644
--- a/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/coverage/MultiResolutionCoverageLoader.java
+++ b/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/coverage/MultiResolutionCoverageLoader.java
@@ -34,7 +34,6 @@ import org.apache.sis.storage.DataStoreException;
import org.apache.sis.coverage.grid.GridGeometry;
import org.apache.sis.coverage.grid.GridCoverage;
import org.apache.sis.coverage.grid.GridRoundingMode;
-import org.apache.sis.internal.util.CollectionsExt;
import org.apache.sis.math.DecimalFunctions;
import org.apache.sis.io.TableAppender;
@@ -125,7 +124,7 @@ public class MultiResolutionCoverageLoader {
this.resource = resource;
areaOfInterest = domain;
readRanges = range;
- double[][] resolutions = CollectionsExt.toArray(resource.getResolutions(), double[].class);
+ double[][] resolutions = resource.getResolutions().toArray(double[][]::new);
if (resolutions.length <= 1) {
final GridGeometry gg = resource.getGridGeometry();
if (resolutions.length != 0) {
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 b1ca5ec52f..afec836244 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
@@ -49,7 +49,6 @@ 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.util.CollectionsExt;
import org.apache.sis.internal.referencing.provider.TransverseMercator;
import org.apache.sis.internal.referencing.provider.PolarStereographicA;
import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
@@ -641,7 +640,7 @@ public class GeodeticObjectBuilder extends Builder<GeodeticObjectBuilder> {
}
ArgumentChecks.ensureValidIndex(srcDim - repDim, firstDimension);
if (source instanceof CompoundCRS) {
- final CoordinateReferenceSystem[] components = CollectionsExt.toArray(((CompoundCRS) source).getComponents(), CoordinateReferenceSystem.class);
+ final var components = ((CompoundCRS) source).getComponents().toArray(CoordinateReferenceSystem[]::new);
int lower = 0;
for (int i=0; i<components.length; i++) {
final CoordinateReferenceSystem c = components[i];
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
index cdd7cb9ddd..130abbc8ec 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
@@ -19,8 +19,6 @@ package org.apache.sis.referencing.factory;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
-import java.util.HashMap;
-import java.util.Collections;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.LogRecord;
@@ -53,7 +51,6 @@ import org.apache.sis.internal.referencing.MergedProperties;
import org.apache.sis.internal.system.DefaultFactories;
import org.apache.sis.internal.system.Loggers;
import org.apache.sis.internal.system.Semaphores;
-import org.apache.sis.internal.util.CollectionsExt;
import org.apache.sis.util.collection.WeakHashSet;
import org.apache.sis.util.iso.AbstractFactory;
import org.apache.sis.util.resources.Messages;
@@ -249,13 +246,8 @@ public class GeodeticObjectFactory extends AbstractFactory implements CRSFactory
*
* @param properties the default properties, or {@code null} if none.
*/
- public GeodeticObjectFactory(Map<String,?> properties) {
- if (properties == null || properties.isEmpty()) {
- properties = Collections.emptyMap();
- } else {
- properties = CollectionsExt.compact(new HashMap<>(properties));
- }
- defaultProperties = properties;
+ public GeodeticObjectFactory(final Map<String,?> properties) {
+ defaultProperties = (properties != null) ? Map.copyOf(properties) : Map.of();
pool = new WeakHashSet<>(AbstractIdentifiedObject.class);
parser = new AtomicReference<>();
}
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
index c0988e6453..3f8a768c9b 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
@@ -18,7 +18,6 @@ package org.apache.sis.referencing.operation;
import java.util.Map;
import java.util.HashMap;
-import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.opengis.util.FactoryException;
@@ -41,7 +40,6 @@ import org.apache.sis.internal.referencing.CoordinateOperations;
import org.apache.sis.internal.referencing.ReferencingFactoryContainer;
import org.apache.sis.internal.referencing.ReferencingUtilities;
import org.apache.sis.internal.system.DefaultFactories;
-import org.apache.sis.internal.util.CollectionsExt;
import org.apache.sis.internal.util.Constants;
import org.apache.sis.internal.util.URLs;
import org.apache.sis.referencing.CRS;
@@ -97,10 +95,8 @@ public class DefaultCoordinateOperationFactory extends AbstractFactory implement
static final boolean USE_EPSG_FACTORY = true;
/**
- * The default properties, or an empty map if none. This map shall not change after construction in
- * order to allow usage without synchronization in multi-thread context. But we do not need to wrap
- * in a unmodifiable map since {@code DefaultCoordinateOperationFactory} does not provide public
- * access to it.
+ * The default properties, or an empty map if none. This map shall be immutable
+ * in order to allow usage without synchronization in multi-thread context.
*/
private final Map<String,?> defaultProperties;
@@ -163,7 +159,7 @@ public class DefaultCoordinateOperationFactory extends AbstractFactory implement
@SuppressWarnings("ResultOfMethodCallIgnored")
public DefaultCoordinateOperationFactory(Map<String,?> properties, final MathTransformFactory factory) {
if (properties == null || properties.isEmpty()) {
- properties = Collections.emptyMap();
+ properties = Map.of();
} else {
String key = null;
Object value = null;
@@ -181,7 +177,7 @@ public class DefaultCoordinateOperationFactory extends AbstractFactory implement
.getString(Errors.Keys.IllegalPropertyValueClass_2, key, Classes.getClass(value)));
}
properties.remove(ReferencingFactoryContainer.DATUM_FACTORY);
- properties = CollectionsExt.compact(properties);
+ properties = Map.copyOf(properties);
}
defaultProperties = properties;
if (factory != null) {
diff --git a/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java b/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
index 566185a50d..0803fdeb29 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
@@ -18,7 +18,6 @@ package org.apache.sis.internal.util;
import java.util.*;
import java.lang.reflect.Array;
-import java.util.function.Predicate;
import org.opengis.util.CodeList;
import org.apache.sis.util.Static;
import org.apache.sis.util.Numbers;
@@ -48,6 +47,11 @@ import static org.apache.sis.util.collection.Containers.hashMapCapacity;
* purpose of a geospatial library and may change at any time. Some method contracts are a little
* bit tedious to explain, which is another indication that they should not be in public API.
*
+ * <h2>Null values</h2>
+ * All methods in this class accepts null values. The collections created by this class also accept null.
+ * This class prefers {@link Collections} methods instead of the new static {@code of(…)} method in interfaces
+ * because the former accept null values while the latter throws {@link NullPointerException}.
+ *
* @author Martin Desruisseaux (IRD, Geomatys)
* @version 1.4
* @since 0.3
@@ -335,7 +339,8 @@ public final class CollectionsExt extends Static {
* sense of {@link Object#equals(Object)}, then only the last instance of the duplicated
* values will be included in the returned set.
*
- * <p>This method differs from {@link Set#of(Object...)} in that it preserves element order.</p>
+ * <p>This method differs from {@link Set#of(Object...)} in that it preserves element order
+ * and optionally accepts null elements.</p>
*
* @param <E> the type of array elements.
* @param excludeNull {@code true} for excluding the {@code null} element from the returned set.
@@ -383,30 +388,24 @@ public final class CollectionsExt extends Static {
* <strong>not</strong> be modified after this method call. In case of doubt, use the
* standard {@link Collections#unmodifiableSet(Set)} method instead.</p>
*
+ * <p>This method differs from {@link Set#copyOf(Collection)} in that it may avoid copy,
+ * preserves element order and optionally null elements.</p>
+ *
* @param <E> the type of elements in the set.
* @param set the set to make unmodifiable, or {@code null}.
* @return a unmodifiable version of the given set, or {@code null} if the given set was null.
*
* @see #compact(Set)
*/
- public static <E> Set<E> unmodifiableOrCopy(Set<E> set) {
- if (set != null) {
- switch (set.size()) {
- case 0: {
- set = Collections.emptySet();
- break;
- }
- case 1: {
- set = Collections.singleton(set.iterator().next());
- break;
- }
- default: {
- set = Collections.unmodifiableSet(set);
- break;
- }
- }
+ public static <E> Set<E> unmodifiableOrCopy(final Set<E> set) {
+ if (set == null) {
+ return null;
+ }
+ switch (set.size()) {
+ case 0: return Collections.emptySet();
+ case 1: return Collections.singleton(set.iterator().next());
+ default: return Collections.unmodifiableSet(set);
}
- return set;
}
/**
@@ -420,34 +419,28 @@ public final class CollectionsExt extends Static {
* <strong>not</strong> be modified after this method call. In case of doubt, use the
* standard {@link Collections#unmodifiableMap(Map)} method instead.</p>
*
+ * <p>This method differs from {@link Map#copyOf(Map)} in that it may avoid copy,
+ * preserves element order and optionally null elements.</p>
+ *
* @param <K> the type of keys in the map.
* @param <V> the type of values in the map.
* @param map the map to make unmodifiable, or {@code null}.
* @return a unmodifiable version of the given map, or {@code null} if the given map was null.
*
* @see #compact(Map)
- *
- * @todo Replace by {@code Map.copyOf(Map)} on JDK10, except when order matter ({@link LinkedHashMap}).
*/
- public static <K,V> Map<K,V> unmodifiableOrCopy(Map<K,V> map) {
- if (map != null) {
- switch (map.size()) {
- case 0: {
- map = Collections.emptyMap();
- break;
- }
- case 1: {
- final Map.Entry<K,V> entry = map.entrySet().iterator().next();
- map = Collections.singletonMap(entry.getKey(), entry.getValue());
- break;
- }
- default: {
- map = Collections.unmodifiableMap(map);
- break;
- }
+ public static <K,V> Map<K,V> unmodifiableOrCopy(final Map<K,V> map) {
+ if (map == null) {
+ return null;
+ }
+ switch (map.size()) {
+ case 0: return Collections.emptyMap();
+ case 1: {
+ final Map.Entry<K,V> entry = map.entrySet().iterator().next();
+ return Collections.singletonMap(entry.getKey(), entry.getValue());
}
+ default: return Collections.unmodifiableMap(map);
}
- return map;
}
/**
@@ -626,55 +619,13 @@ public final class CollectionsExt extends Static {
return map;
}
- /**
- * Returns a more compact representation of the given set. This method is similar to
- * {@link #unmodifiableOrCopy(Set)} except that it does not wrap the set in an unmodifiable
- * view. The intent is to avoid one level of indirection for performance and memory reasons.
- * This is okay only if the set is kept in a private field and never escape outside that class.
- *
- * @param <E> the type of elements in the set.
- * @param set the set to compact, or {@code null}.
- * @return a unmodifiable version of the given set, or {@code null} if the given set was null.
- *
- * @see #unmodifiableOrCopy(Set)
- */
- public static <E> Set<E> compact(final Set<E> set) {
- if (set != null) {
- switch (set.size()) {
- case 0: return Collections.emptySet();
- case 1: return Collections.singleton(set.iterator().next());
- }
- }
- return set;
- }
-
- /**
- * Returns a more compact representation of the given list. This method is similar to
- * {@link #unmodifiableOrCopy(List)} except that it does not wrap the list in an unmodifiable view.
- * The intent is to avoid one level of indirection for performance and memory reasons.
- * This is okay only if the list is kept in a private field and never escape outside that class.
- *
- * @param <E> the type of elements in the list.
- * @param list the list to compact, or {@code null}.
- * @return a unmodifiable version of the given list, or {@code null} if the given list was null.
- *
- * @see #unmodifiableOrCopy(List)
- */
- public static <E> List<E> compact(final List<E> list) {
- if (list != null) {
- switch (list.size()) {
- case 0: return Collections.emptyList();
- case 1: return Collections.singletonList(list.get(0));
- }
- }
- return list;
- }
-
/**
* Returns a snapshot of the given list. The returned list will not be affected by changes
* in the given list after this method call. This method makes no guaranteed about whether
* the returned list is modifiable or not.
*
+ * <p>This method differs from {@link List#copyOf(Collection)} in that it accepts null elements.</p>
+ *
* @param <E> the type of elements in the list.
* @param list the list for which to take a snapshot, or {@code null} if none.
* @return a snapshot of the given list, or {@code list} itself if null or unmodifiable.
@@ -736,13 +687,6 @@ public final class CollectionsExt extends Static {
* <p>Note that in the {@link Iterator} and {@link Enumeration} cases, the given value object
* is not valid anymore after this method call since it has been used for the iteration.</p>
*
- * <p>If the returned object needs to be a list, then this method can be chained
- * with {@link #toList(Collection)} as below:</p>
- *
- * {@preformat java
- * List<?> list = toList(toCollection(object));
- * }
- *
* @param value the value to return as a collection, or {@code null}.
* @return the value as a collection, or wrapped in a collection (never {@code null}).
*/
@@ -799,36 +743,8 @@ public final class CollectionsExt extends Static {
}
/**
- * Casts or copies the given collection to a list. Special cases:
- *
- * <ul>
- * <li>If the given collection is {@code null}, then this method returns {@code null}.</li>
- * <li>If the given collection is already a list, then it is returned unchanged.</li>
- * <li>Otherwise the elements are copied in a new list, which is returned.</li>
- * </ul>
- *
- * This method can be chained with {@link #toCollection(Object)}
- * for handling a wider range of types:
- *
- * {@preformat java
- * List<?> list = toList(toCollection(object));
- * }
- *
- * @param <T> the type of elements in the given collection.
- * @param collection the collection to cast or copy to a list.
- * @return the given collection as a list, or a copy of the given collection.
- */
- public static <T> List<T> toList(final Collection<T> collection) {
- if (collection instanceof List<?>) {
- return (List<T>) collection;
- }
- return new ArrayList<>(collection);
- }
-
- /**
- * Returns the elements of the given collection as an array. This method can be used when the {@code valueClass}
- * argument is not known at compile-time. If the {@code valueClass} is known at compile-time, then callers should
- * use {@link Collection#toArray(Object[])} instead.
+ * Returns the elements of the given collection as an array.
+ * This method can be used when the {@code valueClass} argument is not known at compile-time.
*
* @param <T> the compile-time value of {@code valueClass}.
* @param collection the collection from which to get the elements.
@@ -836,8 +752,6 @@ public final class CollectionsExt extends Static {
* @return the collection elements as an array, or {@code null} if {@code collection} is null.
*
* @since 0.6
- *
- * @todo Remove after migration to JDK11.
*/
@SuppressWarnings("unchecked")
public static <T> T[] toArray(final Collection<? extends T> collection, final Class<T> valueClass) {
@@ -964,57 +878,6 @@ public final class CollectionsExt extends Static {
return map;
}
- /**
- * Returns an iterator over the elements of the given iterator where the predicate returns {@code true}.
- * The iterator may return {@code null} elements.
- *
- * @param <E> type of elements in the iterator to return.
- * @param it the iterator to filter.
- * @param filter the predicate to use for filtering elements.
- * @return an iterator over filtered elements.
- */
- public static <E> Iterator<E> filter(final Iterator<E> it, final Predicate<? super E> filter) {
- return new Iterator<E>() {
- /** Whether the {@code next} element has been verified as valid. */
- private boolean valid;
-
- /** The next element to return. */
- private E next;
-
- /** Tests whether there is more elements to return. */
- @Override public boolean hasNext() {
- if (!valid) {
- do {
- if (!it.hasNext()) {
- return false;
- }
- next = it.next();
- } while (!filter.test(next));
- valid = true;
- }
- return true;
- }
-
- /**
- * Returns the next element. If there are no more elements,
- * the exception will be thrown by the wrapped iterator.
- */
- @Override public E next() {
- if (!valid) {
- do next = it.next();
- while (!filter.test(next));
- }
- valid = false;
- return next;
- }
-
- /** Remove the last element returned by the iterator. */
- @Override public void remove() {
- it.remove();
- }
- };
- }
-
/**
* Returns {@code true} if the next elements returned by the given iterators are the same.
* This method compares using the identity operation ({@code ==}), not {@code equals(Object)}.
diff --git a/core/sis-utility/src/main/java/org/apache/sis/measure/UnitDimension.java b/core/sis-utility/src/main/java/org/apache/sis/measure/UnitDimension.java
index 7767533ae7..d8a425e80d 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/measure/UnitDimension.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/measure/UnitDimension.java
@@ -130,7 +130,7 @@ final class UnitDimension implements Dimension, Serializable {
}
/*
* Implementation note: following code duplicates the functionality of Map.computeIfAbsent(…),
- * but we had to do it because we compute not only the value, but also the 'components' key.
+ * but we had to do it because we compute not only the value, but also the `components` key.
*/
UnitDimension dim = (UnitDimension) UnitRegistry.get(components);
if (dim == null) {
@@ -239,7 +239,7 @@ final class UnitDimension implements Dimension, Serializable {
}
/*
* Fallback for non-SIS implementations. The cast from <? extends Dimension> to <Dimension>
- * is safe if we use the 'components' map as a read-only map (no put operation allowed).
+ * is safe if we use the `components` map as a read-only map (no put operation allowed).
*/
@SuppressWarnings("unchecked")
Map<Dimension,Integer> components = (Map<Dimension,Integer>) dimension.getBaseDimensions();
@@ -352,8 +352,8 @@ final class UnitDimension implements Dimension, Serializable {
final UnitDimension that = (UnitDimension) other;
if (symbol == that.symbol) {
/*
- * Do not compare 'components' if 'symbols' is non-zero because in such case
- * the components map contains 'this', which would cause an infinite loop.
+ * Do not compare `components` if `symbols` is non-zero because in such case
+ * the components map contains `this`, which would cause an infinite loop.
*/
return (symbol != 0) || components.equals(that.components);
}
@@ -367,8 +367,8 @@ final class UnitDimension implements Dimension, Serializable {
@Override
public int hashCode() {
/*
- * Do not use 'components' in hash code calculation if 'symbols' is non-zero
- * beause in such case the map contains 'this', which would cause an infinite loop.
+ * Do not use `components` in hash code calculation if `symbols` is non-zero
+ * beause in such case the map contains `this`, which would cause an infinite loop.
*/
return (symbol != 0) ? symbol ^ (int) serialVersionUID : components.hashCode();
}
diff --git a/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java b/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java
index d8dcb5aeb0..7b8fb254f1 100644
--- a/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java
+++ b/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java
@@ -30,7 +30,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Locale;
-import java.util.function.Predicate;
import org.apache.sis.util.collection.CodeListSet;
import org.apache.sis.test.TestCase;
import org.junit.Test;
@@ -42,7 +41,7 @@ import static org.apache.sis.test.Assert.*;
* Tests the {@link CollectionsExt} class.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.4
* @since 0.3
* @module
*/
@@ -151,21 +150,6 @@ public final strictfp class CollectionsExtTest extends TestCase {
}
}
- /**
- * Tests {@link CollectionsExt#filter(Iterator, Predicate)}.
- */
- @Test
- public void testFilter() {
- final Iterator<Integer> it = CollectionsExt.filter(Arrays.asList(2, 5, 7, 4, 8).iterator(), (Integer n) -> (n & 1) == 0);
- assertTrue ( it.hasNext());
- assertEquals(2, it.next().intValue());
- assertEquals(4, it.next().intValue());
- assertTrue ( it.hasNext());
- assertTrue ( it.hasNext());
- assertEquals(8, it.next().intValue());
- assertFalse ( it.hasNext());
- }
-
/**
* Tests {@link CollectionsExt#identityEquals(Iterator, Iterator)}.
*/
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/ConcatenatedGridResource.java b/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/ConcatenatedGridResource.java
index 7e266da25a..dd83644e2d 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/ConcatenatedGridResource.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/ConcatenatedGridResource.java
@@ -40,7 +40,6 @@ import org.apache.sis.internal.storage.MemoryGridResource;
import org.apache.sis.internal.storage.MetadataBuilder;
import org.apache.sis.internal.storage.RangeArgument;
import org.apache.sis.internal.util.UnmodifiableArrayList;
-import org.apache.sis.internal.util.CollectionsExt;
import org.apache.sis.internal.util.Numerics;
import org.apache.sis.util.ArraysExt;
@@ -276,7 +275,7 @@ final class ConcatenatedGridResource extends AbstractGridCoverageResource implem
if (common == null) {
int count = 0;
for (final GridCoverageResource slice : slices) {
- final double[][] sr = CollectionsExt.toArray(slice.getResolutions(), double[].class);
+ final double[][] sr = slice.getResolutions().toArray(double[][]::new);
if (sr != null) { // Should never be null, but we are paranoiac.
if (common == null) {
common = sr;
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/storage/event/StoreListeners.java b/storage/sis-storage/src/main/java/org/apache/sis/storage/event/StoreListeners.java
index ab90b1c4b7..804badd303 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/storage/event/StoreListeners.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/storage/event/StoreListeners.java
@@ -40,7 +40,6 @@ import org.apache.sis.internal.system.Modules;
import org.apache.sis.internal.storage.Resources;
import org.apache.sis.internal.storage.StoreResource;
import org.apache.sis.internal.storage.StoreUtilities;
-import org.apache.sis.internal.util.CollectionsExt;
import org.apache.sis.internal.util.Strings;
import org.apache.sis.storage.DataStoreProvider;
import org.apache.sis.storage.DataStore;
@@ -899,7 +898,7 @@ public class StoreListeners implements Localized {
throw illegalEventType(type);
}
}
- permittedEventTypes = READ_EVENT_TYPES.equals(types) ? READ_EVENT_TYPES : CollectionsExt.compact(types);
+ permittedEventTypes = READ_EVENT_TYPES.equals(types) ? READ_EVENT_TYPES : Set.copyOf(types);
ForType.removeUnreachables(listeners, types);
}