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 694c74c72d0ad94c107c2169708cb158be8f2c38 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Tue Jul 18 13:55:30 2023 +0200 Removal of unnecessary @SuppressWarnings("UnnecessaryBoxing") and cleaning of related documentation. --- .../main/java/org/apache/sis/xml/NilReason.java | 33 ++++++++++------------ .../org/apache/sis/geometry/CoordinateFormat.java | 2 +- .../factory/ConcurrentAuthorityFactory.java | 4 +-- .../main/java/org/apache/sis/util/Disposable.java | 4 +-- .../sis/internal/converter/AngleConverterTest.java | 1 - .../org/apache/sis/internal/util/NumericsTest.java | 1 - .../org/apache/sis/util/collection/CacheTest.java | 15 ++++++---- .../sis/util/collection/WeakHashSetTest.java | 1 - .../sis/util/collection/WeakValueHashMapTest.java | 2 -- 9 files changed, 29 insertions(+), 34 deletions(-) diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/NilReason.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/NilReason.java index 20fb04e72e..72cde921b4 100644 --- a/core/sis-metadata/src/main/java/org/apache/sis/xml/NilReason.java +++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/NilReason.java @@ -54,7 +54,7 @@ import org.apache.sis.internal.jaxb.PrimitiveTypeProperties; * This final class is immutable and thus inherently thread-safe. * * @author Martin Desruisseaux (Geomatys) - * @version 0.4 + * @version 1.4 * * @see NilObject * @@ -171,10 +171,9 @@ public final class NilReason implements Serializable { } /** - * Returns an array containing every instances of this type that have not yet been - * garbage collected. The first elements of the returned array are the constants - * defined in this class, in declaration order. All other elements are the instances - * created by the {@link #valueOf(String)} method, in no particular order. + * Returns an array containing every instances of this type that have not yet been garbage collected. + * The first elements of the returned array are the constants defined in this class, in declaration order. + * All other elements are the instances created by the {@link #valueOf(String)} method, in no particular order. * * @return an array containing the instances of {@code NilReason}. */ @@ -279,13 +278,11 @@ public final class NilReason implements Serializable { } /** - * If this {@code NilReason} is an enumeration of kind {@link #OTHER}, returns the explanation - * text. Otherwise returns {@code null}. If non-null, then the explanation is a string without - * whitespace. + * If this {@code NilReason} is an enumeration of kind {@link #OTHER}, returns the explanation text. + * Otherwise returns {@code null}. If non-null, then the explanation is a string without whitespace. * - * <p>Note that in the special case where {@code this} nil reason is the {@link #OTHER} - * instance itself, then this method returns an empty string. For all other cases, the - * string contains at least two characters.</p> + * <p>Note that in the special case where {@code this} nil reason is the {@link #OTHER} instance itself, + * then this method returns an empty string. For all other cases, the string contains at least two characters.</p> * * @return the explanation, or {@code null} if this {@code NilReason} is not of kind {@link #OTHER}. */ @@ -379,15 +376,15 @@ public final class NilReason implements Serializable { ArgumentChecks.ensureNonNull("type", type); /* * Check for existing instance in the cache before to create a new object. Returning a unique - * instance is mandatory for the types handled by 'createNilPrimitive(Class)'. Since we have + * instance is mandatory for the types handled by `createNilPrimitive(Class)`. Since we have * to cache those values anyway, we opportunistically extend the caching to other types too. * - * Implementation note: we have two synchronizations here: one lock on 'this' because of the - * 'synchronized' statement in this method signature, and another lock in WeakValueHashMap. - * The second lock may seem useless since we already hold a lock on 'this'. But it is actually + * Implementation note: we have two synchronizations here: one lock on `this` because of the + * `synchronized` statement in this method signature, and another lock in `WeakValueHashMap`. + * The second lock may seem useless since we already hold a lock on `this`. But it is actually * needed because the garbage-collected entries are removed from the map in a background thread * (see ReferenceQueueConsumer), which is synchronized on the map itself. It is better to keep - * the synchronization on the map shorter than the snychronization on 'this' because a single + * the synchronization on the map shorter than the snychronization on `this` because a single * ReferenceQueueConsumer thread is shared by all the SIS library. */ if (nilObjects == null) { @@ -465,7 +462,7 @@ public final class NilReason implements Serializable { * be sentinel values, in order to avoid the synchronization done by {@code PrimitiveTypeProperties}. */ private static boolean mayBeNil(final Object object) { - // 'instanceof' checks on instances of final classes are expected to be very fast. + // `instanceof` checks on instances of final classes are expected to be very fast. if (object instanceof String) return ((String) object).isEmpty(); if (object instanceof Boolean) return !((Boolean) object) && (object != Boolean.FALSE); if (object instanceof Number) { @@ -473,7 +470,7 @@ public final class NilReason implements Serializable { * Following test may return false positives for Long, Float and Double types, but this is okay * since the real check will be done by PrimitiveTypeProperties. The purpose of this method is * only to perform a cheap filtering. Note that this method relies on the fact that casting NaN - * to 'int' produces 0. + * to `int` produces 0. */ return ((Number) object).intValue() == 0; } diff --git a/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java b/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java index 556982b45f..4faaa2e526 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java @@ -1416,7 +1416,7 @@ abort: if (dimensions != 0 && groundAccuracy != null) try { * @throws ArithmeticException if a date value exceed the capacity of {@code long} type. */ @Override - @SuppressWarnings({"UnnecessaryBoxing", "null"}) + @SuppressWarnings("UnnecessaryBoxing") public void format(final DirectPosition position, final Appendable toAppendTo) throws IOException { ArgumentChecks.ensureNonNull("position", position); ArgumentChecks.ensureNonNull("toAppendTo", toAppendTo); diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java index 128302618d..f5a04b4c8b 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java @@ -2035,11 +2035,11 @@ public abstract class ConcurrentAuthorityFactory<DAO extends GeodeticAuthorityFa call(); } catch (Exception exception) { /* - * Pretend that the exception is logged by ConcurrentAuthorityFactory.finalize(). + * Pretend that the exception is logged by `ConcurrentAuthorityFactory.dispose()`. * This is not true, but carries the idea that the error occurred while cleaning * ConcurrentAuthorityFactory after garbage collection. */ - unexpectedException("finalize", exception); + unexpectedException("dispose", exception); } } diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/Disposable.java b/core/sis-utility/src/main/java/org/apache/sis/util/Disposable.java index 8ab8a046e0..0211969866 100644 --- a/core/sis-utility/src/main/java/org/apache/sis/util/Disposable.java +++ b/core/sis-utility/src/main/java/org/apache/sis/util/Disposable.java @@ -55,8 +55,8 @@ package org.apache.sis.util; */ public interface Disposable { /** - * Allows any resources held by this object to be released. The result of calling any other - * method (other than {@code finalize()}) subsequent to a call to this method is undefined. + * Allows any resources held by this object to be released. + * The result of calling any other method subsequent to a call to this method is undefined. */ void dispose(); } diff --git a/core/sis-utility/src/test/java/org/apache/sis/internal/converter/AngleConverterTest.java b/core/sis-utility/src/test/java/org/apache/sis/internal/converter/AngleConverterTest.java index a6edb3ffee..fb58bad365 100644 --- a/core/sis-utility/src/test/java/org/apache/sis/internal/converter/AngleConverterTest.java +++ b/core/sis-utility/src/test/java/org/apache/sis/internal/converter/AngleConverterTest.java @@ -43,7 +43,6 @@ public final class AngleConverterTest extends TestCase { * Tests conversions to {@link Double}. */ @Test - @SuppressWarnings("UnnecessaryBoxing") public void testDouble() { final ObjectConverter<Angle,Double> c1 = AngleConverter.INSTANCE; final ObjectConverter<Double,Angle> c2 = AngleConverter.Inverse.INSTANCE; diff --git a/core/sis-utility/src/test/java/org/apache/sis/internal/util/NumericsTest.java b/core/sis-utility/src/test/java/org/apache/sis/internal/util/NumericsTest.java index b532546c4e..0bb1b06208 100644 --- a/core/sis-utility/src/test/java/org/apache/sis/internal/util/NumericsTest.java +++ b/core/sis-utility/src/test/java/org/apache/sis/internal/util/NumericsTest.java @@ -38,7 +38,6 @@ import static org.junit.Assert.*; * @version 1.4 * @since 0.3 */ -@SuppressWarnings("UnnecessaryBoxing") public final class NumericsTest extends TestCase { /** * Creates a new test case. diff --git a/core/sis-utility/src/test/java/org/apache/sis/util/collection/CacheTest.java b/core/sis-utility/src/test/java/org/apache/sis/util/collection/CacheTest.java index 0555e620c9..c44a424fc1 100644 --- a/core/sis-utility/src/test/java/org/apache/sis/util/collection/CacheTest.java +++ b/core/sis-utility/src/test/java/org/apache/sis/util/collection/CacheTest.java @@ -16,6 +16,7 @@ */ package org.apache.sis.util.collection; +import java.util.Arrays; import java.util.Set; import java.util.Map; import java.util.HashMap; @@ -45,7 +46,7 @@ import static org.apache.sis.test.Assertions.assertMapEquals; * Tests the {@link Cache} with simple tests and a {@linkplain #stress() stress} test. * * @author Martin Desruisseaux (Geomatys) - * @version 1.2 + * @version 1.4 * @since 0.3 */ @DependsOn(WeakValueHashMapTest.class) @@ -235,11 +236,11 @@ public final class CacheTest extends TestCase { /** * Puts random values in the map. */ - @SuppressWarnings({"UnnecessaryBoxing", "CallToThreadYield", "NumberEquality"}) + @SuppressWarnings("CallToThreadYield") @Override public void run() { for (int i=0; i<count; i++) { final Integer key = i; - final IntObject expected = new IntObject(i * i); // We really want new instance. + final IntObject expected = new IntObject(i * i); // We really want new instance. final IntObject value; try { value = cache.getOrCreate(key, () -> expected); @@ -258,9 +259,11 @@ public final class CacheTest extends TestCase { } } final WriterThread[] threads = new WriterThread[50]; - for (int i=0; i<threads.length; i++) threads[i] = new WriterThread(i); - for (int i=0; i<threads.length; i++) threads[i].start(); - for (int i=0; i<threads.length; i++) threads[i].join(); + Arrays.setAll(threads, WriterThread::new); + Arrays.stream(threads).forEach(Thread::start); + for (WriterThread thread : threads) { + thread.join(); + } TestUtilities.rethrownIfNotNull(failures.get()); /* * Verifies the values. diff --git a/core/sis-utility/src/test/java/org/apache/sis/util/collection/WeakHashSetTest.java b/core/sis-utility/src/test/java/org/apache/sis/util/collection/WeakHashSetTest.java index 189f9f05fa..29841885c2 100644 --- a/core/sis-utility/src/test/java/org/apache/sis/util/collection/WeakHashSetTest.java +++ b/core/sis-utility/src/test/java/org/apache/sis/util/collection/WeakHashSetTest.java @@ -110,7 +110,6 @@ public final class WeakHashSetTest extends TestCase { final WeakHashSet<IntObject> weakSet = new WeakHashSet<>(IntObject.class); final HashSet<IntObject> strongSet = new HashSet<>(); for (int i=0; i<SAMPLE_SIZE; i++) { - @SuppressWarnings("UnnecessaryBoxing") final IntObject value = new IntObject(random.nextInt(SAMPLE_SIZE)); // Really need new instances. if (random.nextBoolean()) { /* diff --git a/core/sis-utility/src/test/java/org/apache/sis/util/collection/WeakValueHashMapTest.java b/core/sis-utility/src/test/java/org/apache/sis/util/collection/WeakValueHashMapTest.java index 08137e93df..27a23feebf 100644 --- a/core/sis-utility/src/test/java/org/apache/sis/util/collection/WeakValueHashMapTest.java +++ b/core/sis-utility/src/test/java/org/apache/sis/util/collection/WeakValueHashMapTest.java @@ -115,7 +115,6 @@ public final class WeakValueHashMapTest extends TestCase { * * @param weakMap the map implementation to test. */ - @SuppressWarnings("UnnecessaryBoxing") static void testWeakReferences(final Map<Integer,IntObject> weakMap) throws InterruptedException { final Random random = new Random(); for (int pass=0; pass<NUM_RETRY; pass++) { @@ -206,7 +205,6 @@ public final class WeakValueHashMapTest extends TestCase { */ @Test @DependsOnMethod("testStrongReferences") - @SuppressWarnings("UnnecessaryBoxing") public void testIdentityComparisons() { final WeakValueHashMap<IntObject,IntObject> weakMap = new WeakValueHashMap<>(IntObject.class, true); final IntObject k1 = new IntObject(10);