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 eba0a4bea2b29072de400fa1742eb90a9535ea56 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Tue Sep 20 16:07:25 2022 +0200 Replace `c.addAll(Arrays.asList(…))` pattern by the simpler `Collections.addAll(c, …)` pattern when the number of elements is small. --- .../src/main/java/org/apache/sis/feature/AbstractAttribute.java | 3 +-- .../main/java/org/apache/sis/metadata/iso/MetadataScopeAdapter.java | 6 +++--- .../java/org/apache/sis/metadata/iso/citation/DefaultContact.java | 4 ++-- .../test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java | 3 ++- .../java/org/apache/sis/parameter/DefaultParameterValueGroup.java | 4 ++-- .../src/main/java/org/apache/sis/referencing/Builder.java | 6 +++--- .../sis/referencing/operation/builder/ProjectedTransformTry.java | 4 ++-- .../org/apache/sis/parameter/DefaultParameterValueGroupTest.java | 5 ++--- .../java/org/apache/sis/internal/util/CheckedArrayListTest.java | 3 ++- core/sis-utility/src/test/java/org/apache/sis/test/TestRunner.java | 3 ++- .../java/org/apache/sis/util/collection/FrequencySortedSetTest.java | 3 +-- .../src/main/java/org/apache/sis/storage/landsat/BandGroup.java | 4 ++-- .../java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java | 3 +-- .../main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java | 2 +- 14 files changed, 26 insertions(+), 27 deletions(-) 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 83f1007149..e897bb4829 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 @@ -17,7 +17,6 @@ package org.apache.sis.feature; import java.util.Map; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.io.Serializable; @@ -178,7 +177,7 @@ public abstract class AbstractAttribute<V> extends Field<V> implements Attribute final Attribute<?>[] characterizedBy = (Attribute<?>[]) in.readObject(); if (characterizedBy != null) { characteristics = newCharacteristicsMap(); - characteristics.values().addAll(Arrays.asList(characterizedBy)); + Collections.addAll(characteristics.values(), characterizedBy); } } catch (RuntimeException e) { // At least ClassCastException, NullPointerException, IllegalArgumentException and IllegalStateException. diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/MetadataScopeAdapter.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/MetadataScopeAdapter.java index 4e498fa81d..a3decc1e6c 100644 --- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/MetadataScopeAdapter.java +++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/MetadataScopeAdapter.java @@ -16,10 +16,10 @@ */ package org.apache.sis.metadata.iso; -import java.util.Arrays; import java.util.List; import java.util.Iterator; import java.util.Collection; +import java.util.Collections; import java.util.ConcurrentModificationException; import org.opengis.metadata.MetadataScope; import org.apache.sis.internal.metadata.legacy.LegacyPropertyAdapter; @@ -83,10 +83,10 @@ abstract class MetadataScopeAdapter<L> extends LegacyPropertyAdapter<L,MetadataS remaining[n++] = it.next(); it.remove(); } - if (n != remaining.length) { // Paranoiac check. + if (n != remaining.length) { // Paranoiac check. throw new ConcurrentModificationException(); } - elements.addAll(Arrays.asList(remaining)); + Collections.addAll(elements, remaining); } } return update(scope, newValue); diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java index 5e8b19e195..491b983296 100644 --- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java +++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java @@ -16,9 +16,9 @@ */ package org.apache.sis.metadata.iso.citation; -import java.util.Arrays; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; @@ -217,7 +217,7 @@ public class DefaultContact extends ISOMetadata implements Contact { } if (modified) { phones.clear(); - phones.addAll(Arrays.asList(p)); + Collections.addAll(phones, p); } } } diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java index 214ef0ff2b..23ebde8350 100644 --- a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java +++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java @@ -21,6 +21,7 @@ import java.util.Locale; import java.util.Arrays; import java.util.Iterator; import java.util.Collection; +import java.util.Collections; import java.net.URISyntaxException; import javax.xml.bind.JAXBException; import org.opengis.metadata.MetadataScope; @@ -113,7 +114,7 @@ public final strictfp class DefaultMetadataTest extends TestCase { * Add other languages. They should appear as additional entries after the first one. * The "language" property shall be unmodified by changes in the "other locales" one. */ - metadata.getLocales().addAll(Arrays.asList(Locale.FRENCH, Locale.ENGLISH)); + Collections.addAll(metadata.getLocales(), Locale.FRENCH, Locale.ENGLISH); assertLanguagesEquals(metadata, Locale.JAPANESE, Locale.FRENCH, Locale.ENGLISH); /* * Ensure that the "locales" list is modifiable, since JAXB writes directly in it. 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 96b5b103b9..fe091065c6 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 @@ -88,9 +88,9 @@ import org.apache.sis.util.Utilities; * * <div class="note"><b>Example:</b> * {@preformat java - * ParameterValue<?>[] parameter = ...; // Defined elsewhere. + * ParameterValue<?>[] parameter = ...; // Defined elsewhere. * ParameterValueGroup mercator = Mercator.PARAMETERS.createValue(); - * mercator.values().addAll(Arrays.asList(parameters)); + * Collections.addAll(mercator.values(), parameters); * } * </div> * 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 50eb32159a..b64626ca33 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 @@ -20,7 +20,7 @@ import java.util.Map; import java.util.List; import java.util.HashMap; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; import java.lang.reflect.Type; import java.lang.reflect.ParameterizedType; import org.opengis.util.NameSpace; @@ -273,8 +273,8 @@ public abstract class Builder<B extends Builder<B>> { properties.putAll(IdentifiedObjects.getProperties(object)); final GenericName[] valueAlias = (GenericName[]) properties.remove(IdentifiedObject.ALIAS_KEY); final Identifier[] valueIds = (Identifier[]) properties.remove(IdentifiedObject.IDENTIFIERS_KEY); - if (valueAlias != null) aliases.addAll(Arrays.asList(valueAlias)); - if (valueIds != null) identifiers.addAll(Arrays.asList(valueIds)); + if (valueAlias != null) Collections.addAll(aliases, valueAlias); + if (valueIds != null) Collections.addAll(identifiers, valueIds); } } diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/ProjectedTransformTry.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/ProjectedTransformTry.java index 547fb73672..cd867e6a5f 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/ProjectedTransformTry.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/ProjectedTransformTry.java @@ -19,8 +19,8 @@ package org.apache.sis.referencing.operation.builder; import java.util.Map; import java.util.List; import java.util.Queue; -import java.util.Arrays; import java.util.Locale; +import java.util.Collections; import java.text.NumberFormat; import org.opengis.geometry.MismatchedDimensionException; import org.opengis.referencing.operation.MathTransform; @@ -287,7 +287,7 @@ final class ProjectedTransformTry implements Comparable<ProjectedTransformTry>, */ static void recycle(final double[][] arrays, final Queue<double[]> pool) { if (arrays != null) { - pool.addAll(Arrays.asList(arrays)); + Collections.addAll(pool, arrays); } } 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 02baa497e1..93a09d9916 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 @@ -17,7 +17,6 @@ package org.apache.sis.parameter; import java.util.List; -import java.util.Arrays; import java.util.ArrayList; import java.util.Collections; import org.opengis.parameter.GeneralParameterDescriptor; @@ -89,7 +88,7 @@ public final strictfp class DefaultParameterValueGroupTest extends TestCase { */ private DefaultParameterValueGroup createGroup(final int step) { final DefaultParameterValueGroup group = new DefaultParameterValueGroup(descriptor); - group.values().addAll(Arrays.asList(createValues(step))); + Collections.addAll(group.values(), createValues(step)); return group; } @@ -223,7 +222,7 @@ public final strictfp class DefaultParameterValueGroupTest extends TestCase { assertEquals("Initial size", 2, values.size()); final DefaultParameterValue<?>[] parameters = createValues(10); - assertTrue(values.addAll(Arrays.asList(parameters))); + assertTrue(Collections.addAll(values, parameters)); assertEquals("Final size", parameters.length, values.size()); for (int i=0; i<parameters.length; i++) { assertSame(parameters[i], values.get(i)); diff --git a/core/sis-utility/src/test/java/org/apache/sis/internal/util/CheckedArrayListTest.java b/core/sis-utility/src/test/java/org/apache/sis/internal/util/CheckedArrayListTest.java index 139b7d2e40..7bce1d5a98 100644 --- a/core/sis-utility/src/test/java/org/apache/sis/internal/util/CheckedArrayListTest.java +++ b/core/sis-utility/src/test/java/org/apache/sis/internal/util/CheckedArrayListTest.java @@ -19,6 +19,7 @@ package org.apache.sis.internal.util; import java.util.List; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import org.apache.sis.util.NullArgumentException; import org.apache.sis.test.DependsOnMethod; import org.apache.sis.test.TestCase; @@ -55,7 +56,7 @@ public final strictfp class CheckedArrayListTest extends TestCase { public void testAddAll() { final CheckedArrayList<String> list = new CheckedArrayList<>(String.class); assertTrue(list.add("One")); - assertTrue(list.addAll(Arrays.asList("Two", "Three"))); + assertTrue(Collections.addAll(list, "Two", "Three")); assertEquals(Arrays.asList("One", "Two", "Three"), list); } 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 452af950fa..515691284c 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 @@ -20,6 +20,7 @@ import java.util.Set; import java.util.List; import java.util.HashSet; import java.util.Arrays; +import java.util.Collections; import java.io.PrintWriter; import org.junit.Test; @@ -268,7 +269,7 @@ public final class TestRunner extends BlockJUnit4ClassRunner { final FrameworkMethod method = methods[i]; final DependsOnMethod depend = method.getAnnotation(DependsOnMethod.class); if (depend != null) { - dependencies.addAll(Arrays.asList(depend.value())); + Collections.addAll(dependencies, depend.value()); for (int j=methods.length; --j>i;) { if (dependencies.contains(methods[j].getName())) { /* diff --git a/core/sis-utility/src/test/java/org/apache/sis/util/collection/FrequencySortedSetTest.java b/core/sis-utility/src/test/java/org/apache/sis/util/collection/FrequencySortedSetTest.java index 0c666c0e32..4eb9ee7694 100644 --- a/core/sis-utility/src/test/java/org/apache/sis/util/collection/FrequencySortedSetTest.java +++ b/core/sis-utility/src/test/java/org/apache/sis/util/collection/FrequencySortedSetTest.java @@ -16,7 +16,6 @@ */ package org.apache.sis.util.collection; -import java.util.Arrays; import java.util.Collections; import org.apache.sis.test.DependsOnMethod; import org.apache.sis.test.TestCase; @@ -75,7 +74,7 @@ public final strictfp class FrequencySortedSetTest extends TestCase { @DependsOnMethod("testTwoElements") public void testSubSet() { final FrequencySortedSet<Integer> set = new FrequencySortedSet<>(); - set.addAll(Arrays.asList(2, 5, 3, 2, 4, 2, 3, 6, 2)); + Collections.addAll(set, 2, 5, 3, 2, 4, 2, 3, 6, 2); assertArrayEquals(new Integer[] {5, 4, 6, 3, 2}, set.toArray()); assertArrayEquals(new int[] {1, 1, 1, 2, 4}, set.frequencies()); diff --git a/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/landsat/BandGroup.java b/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/landsat/BandGroup.java index d161908052..4b3fadada4 100644 --- a/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/landsat/BandGroup.java +++ b/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/landsat/BandGroup.java @@ -17,9 +17,9 @@ package org.apache.sis.storage.landsat; import java.util.List; -import java.util.Arrays; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Optional; import org.opengis.util.GenericName; import org.opengis.metadata.Metadata; @@ -143,7 +143,7 @@ final class BandGroup extends AbstractResource implements Aggregate, StoreResour final List<Band> bands = new ArrayList<>(); if (components != null) { for (final BandGroup c : components) { - bands.addAll(Arrays.asList(c.components)); + Collections.addAll(bands, c.components); } } return bands; 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 6b82e8e78a..0d3d376cd3 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 @@ -18,7 +18,6 @@ package org.apache.sis.internal.netcdf.impl; import java.util.Set; import java.util.Map; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.AbstractMap; @@ -950,7 +949,7 @@ public final class ChannelDecoder extends Decoder { break; } axes.add(axis); - dimensions.addAll(Arrays.asList(axis.dimensions)); + Collections.addAll(dimensions, axis.dimensions); } return true; } diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java index fcc5f72a15..3dc462680b 100644 --- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java +++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java @@ -322,7 +322,7 @@ final class VariableInfo extends Variable implements Comparable<VariableInfo> { boolean isUnknown = false; // True if `total` is actually unknown. for (final VariableInfo variable : variables) { // Opportunistically store names of all axes listed in "coordinates" attributes of all variables. - referencedAsAxis.addAll(Arrays.asList(variable.getCoordinateVariables())); + Collections.addAll(referencedAsAxis, variable.getCoordinateVariables()); if (variable.isUnlimited()) { final long paddedSize = variable.paddedSize(); unlimited[count++] = variable;