This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/geoapi-4.0 by this push: new 9c72d89383 Post-merge cleanup: edit documentation, remove unnecessary `@SuppressWarnings`. 9c72d89383 is described below commit 9c72d893836cfa4586fdc5bb4358bf80911fd82f Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Tue Apr 9 15:56:25 2024 +0200 Post-merge cleanup: edit documentation, remove unnecessary `@SuppressWarnings`. --- .../sis/buildtools/coding/ReorganizeImports.java | 11 +++----- .../apache/sis/metadata/ModifiableMetadata.java | 11 ++++++-- .../apache/sis/metadata/iso/extent/Extents.java | 6 ++--- .../iso/quality/AbstractTemporalQuality.java | 1 - ...DefaultNonQuantitativeAttributeCorrectness.java | 1 - .../metadata/simple/SimpleIdentifiedObject.java | 6 +++-- .../org/apache/sis/xml/PooledUnmarshaller.java | 2 +- .../sis/util/iso/DefaultRecordSchemaTest.java | 2 +- .../apache/sis/util/iso/DefaultRecordTypeTest.java | 1 + .../sis/referencing/crs/DefaultEngineeringCRS.java | 1 - .../sis/referencing/datum/AbstractDatum.java | 1 - .../org/apache/sis/referencing/datum/SubTypes.java | 1 - .../referencing/privy/ReferencingUtilities.java | 1 + .../sis/referencing/GeodeticObjectVerifier.java | 2 +- .../sis/referencing/crs/DefaultImageCRSTest.java | 2 +- .../apache/sis/referencing/crs/HardCodedCRS.java | 4 ++- .../sis/referencing/datum/HardCodedDatum.java | 3 ++- .../apache/sis/storage/netcdf/base/CRSBuilder.java | 3 ++- .../sis/util/DefaultInternationalString.java | 30 ++++++++-------------- .../main/org/apache/sis/util/Locales.java | 17 ++++++------ .../test/org/apache/sis/test/LoggingWatcher.java | 8 ++++-- .../org/apache/sis/gui/referencing/CRSChooser.java | 9 ++++--- 22 files changed, 63 insertions(+), 60 deletions(-) diff --git a/buildSrc/src/main/java/org/apache/sis/buildtools/coding/ReorganizeImports.java b/buildSrc/src/main/java/org/apache/sis/buildtools/coding/ReorganizeImports.java index 33a9d79113..c7e46b9cbd 100644 --- a/buildSrc/src/main/java/org/apache/sis/buildtools/coding/ReorganizeImports.java +++ b/buildSrc/src/main/java/org/apache/sis/buildtools/coding/ReorganizeImports.java @@ -59,28 +59,25 @@ import java.util.Set; * * {@snippet lang="shell" : * cd geoapi-4.0 + * git diff * git add --update - * git diff --staged * gradle test * git diff * git add --update - * git commit + * git commit --message "Post-merge automatic reorganization of imports order." * } * * Then temporarily stash the changes in {@code geoapi-3.1}, merge, pop the stashed changes, test and commit: * * {@snippet lang="shell" : * cd ../geoapi-3.1 + * git diff * git add --update - * git diff --staged - * git stash --message "Import reordering" * git merge geoapi-4.0 -s ours --no-commit - * git stash pop - * git add --update * gradle test * git diff * git add --update - * git commit + * git commit --message "Merge of automatic reorganization of imports order." * } * * Finally apply the same pattern on the {@code main} branch. diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/ModifiableMetadata.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/ModifiableMetadata.java index 6be665b756..c04139e60f 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/ModifiableMetadata.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/ModifiableMetadata.java @@ -923,8 +923,15 @@ public abstract class ModifiableMetadata extends AbstractMetadata { * is assignable to {@link CodeList}, {@link Enum}, {@link String}, {@link Charset}, * {@link Locale} or {@link Currency}, and <code>{@linkplain List}.class</code> otherwise. * Subclasses can override this method for choosing different kind of collections. - * <em>Note however that {@link Set} should be used only with immutable element types</em>, - * for {@linkplain Object#hashCode() hash code} stability.</p> + * + * <h4>Constraints</h4> + * Implementations should comply to the following constraints: + * <ul> + * <li><em>This method may be invoked (indirectly) at construction time.</em> + * Therefor, the implementation should not depend on the object state.</li> + * <li><em>The {@link Set} type should be returned only when the set elements are immutable.</em> + * This is needed for {@linkplain Object#hashCode() hash code} stability.</li> + * </ul> * * @param <E> the type of elements in the collection to be created. * @param elementType the type of elements in the collection to be created. diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/extent/Extents.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/extent/Extents.java index 6bc11b1919..81cb4cbb9e 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/extent/Extents.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/extent/Extents.java @@ -214,14 +214,14 @@ public final class Extents extends Static { * * <p>This is a convenience method for fetching the domain of validity of * {@link org.opengis.referencing.datum.Datum}, - * {@link org.opengis.referencing.crs.CoordinateReferenceSystem} or - * {@link org.opengis.referencing.operation.CoordinateOperation} objects.</p> + * {@link CoordinateReferenceSystem} or + * {@link CoordinateOperation} objects.</p> * * @param extents the extents for which to get a single geographic bounding box. * @return the union of all geographic bounding boxes found in all extents. * @throws InvalidMetadataException if an envelope cannot be transformed to a geographic bounding box. * - * @see org.opengis.referencing.crs.CoordinateReferenceSystem#getDomains() + * @see CoordinateReferenceSystem#getDomains() * @see org.apache.sis.referencing.CRS#getDomainOfValidity(CoordinateReferenceSystem) * * @since 1.4 diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/quality/AbstractTemporalQuality.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/quality/AbstractTemporalQuality.java index 7650b12022..72846865a5 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/quality/AbstractTemporalQuality.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/quality/AbstractTemporalQuality.java @@ -106,7 +106,6 @@ public class AbstractTemporalQuality extends AbstractElement implements Temporal * @return a SIS implementation containing the values of the given object (may be the * given object itself), or {@code null} if the argument was null. */ - @SuppressWarnings("deprecation") public static AbstractTemporalQuality castOrCopy(final TemporalQuality object) { if (object instanceof AccuracyOfATimeMeasurement) { return DefaultAccuracyOfATimeMeasurement.castOrCopy((AccuracyOfATimeMeasurement) object); diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/quality/DefaultNonQuantitativeAttributeCorrectness.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/quality/DefaultNonQuantitativeAttributeCorrectness.java index 29f0309373..0e880847f1 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/quality/DefaultNonQuantitativeAttributeCorrectness.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/quality/DefaultNonQuantitativeAttributeCorrectness.java @@ -98,7 +98,6 @@ public class DefaultNonQuantitativeAttributeCorrectness extends AbstractThematic * @return a SIS implementation containing the values of the given object (may be the * given object itself), or {@code null} if the argument was null. */ - @SuppressWarnings("deprecation") public static DefaultNonQuantitativeAttributeCorrectness castOrCopy(final NonQuantitativeAttributeCorrectness object) { if (object instanceof NonQuantitativeAttributeAccuracy) { return DefaultNonQuantitativeAttributeAccuracy.castOrCopy((NonQuantitativeAttributeAccuracy) object); diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/simple/SimpleIdentifiedObject.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/simple/SimpleIdentifiedObject.java index 09e22bcf63..5063035c46 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/simple/SimpleIdentifiedObject.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/simple/SimpleIdentifiedObject.java @@ -101,8 +101,9 @@ public class SimpleIdentifiedObject implements IdentifiedObject, LenientComparab */ @Override public int hashCode() { + @SuppressWarnings("LocalVariableHidesMemberVariable") + final Identifier name = this.name; int code = (int) serialVersionUID; - final Identifier name = getName(); if (name != null) { code ^= name.hashCode(); } @@ -155,9 +156,10 @@ public class SimpleIdentifiedObject implements IdentifiedObject, LenientComparab */ @Override public String toString() { + @SuppressWarnings("LocalVariableHidesMemberVariable") + final Identifier name = this.name; final String code, codespace; final Citation authority; - final Identifier name = this.name; if (name != null) { code = name.getCode(); codespace = name.getCodeSpace(); diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/PooledUnmarshaller.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/PooledUnmarshaller.java index 4e9b54a445..2aef14b4fa 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/PooledUnmarshaller.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/PooledUnmarshaller.java @@ -92,7 +92,7 @@ final class PooledUnmarshaller extends Pooled implements Unmarshaller { * @throws JAXBException if an error occurred while restoring a property. */ @Override - @SuppressWarnings({"unchecked","rawtypes","deprecation"}) + @SuppressWarnings({"unchecked","rawtypes"}) protected void reset(final Object key, final Object value) throws JAXBException { if (key instanceof String) { unmarshaller.setProperty((String) key, value); diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/util/iso/DefaultRecordSchemaTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/util/iso/DefaultRecordSchemaTest.java index 70f8f03fbe..0a61396e4d 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/util/iso/DefaultRecordSchemaTest.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/util/iso/DefaultRecordSchemaTest.java @@ -45,7 +45,7 @@ public final class DefaultRecordSchemaTest extends TestCase { * Tests {@link DefaultRecordSchema#createRecordType(CharSequence, Map)}. */ @Test - @SuppressWarnings("deprecation") + @SuppressWarnings({"deprecation", "removal"}) public void testCreateRecordType() { final var schema = new DefaultRecordSchema(null, null, "MySchema"); final var fields = new LinkedHashMap<CharSequence,Class<?>>(8); diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/util/iso/DefaultRecordTypeTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/util/iso/DefaultRecordTypeTest.java index bd08d2fa56..caeb353a2c 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/util/iso/DefaultRecordTypeTest.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/util/iso/DefaultRecordTypeTest.java @@ -62,6 +62,7 @@ public final class DefaultRecordTypeTest extends TestCase { /** * Creates a new record type from the current values of private fields. */ + @SuppressWarnings("removal") private DefaultRecordType create() throws IllegalArgumentException { final Type fieldType = new SimpleAttributeType<>(fieldTypeName, Integer.class); return new DefaultRecordType(recordTypeName, container, Map.of(fieldName, fieldType)); diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java index 5a62c3e211..284144cf2f 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java @@ -346,7 +346,6 @@ public class DefaultEngineeringCRS extends AbstractCRS implements EngineeringCRS * The types for which a specialized method exists. * Not including {@link CartesianCS}, because this case is already covered by {@link AffineCS}. */ - @SuppressWarnings("deprecation") private static final Class<?>[] SPECIALIZED_TYPES = { AffineCS.class, SphericalCS.class, CylindricalCS.class, PolarCS.class, LinearCS.class, DefaultUserDefinedCS.class }; diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/AbstractDatum.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/AbstractDatum.java index ace9227994..28cba21999 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/AbstractDatum.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/AbstractDatum.java @@ -171,7 +171,6 @@ public class AbstractDatum extends AbstractIdentifiedObject implements Datum { * * @param properties the properties to be given to the identified object. */ - @SuppressWarnings("deprecation") public AbstractDatum(final Map<String,?> properties) { super(properties); anchorDefinition = Types.toInternationalString(properties, ANCHOR_DEFINITION_KEY); diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/SubTypes.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/SubTypes.java index e5a7af5fcc..dfb9e3bde8 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/SubTypes.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/SubTypes.java @@ -47,7 +47,6 @@ final class SubTypes { * * @see AbstractDatum#castOrCopy(Datum) */ - @SuppressWarnings("deprecation") static AbstractDatum castOrCopy(final Datum object) { if (object instanceof GeodeticDatum) { return DefaultGeodeticDatum.castOrCopy((GeodeticDatum) object); diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/ReferencingUtilities.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/ReferencingUtilities.java index f2c829b281..5230a4ce64 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/ReferencingUtilities.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/ReferencingUtilities.java @@ -218,6 +218,7 @@ public final class ReferencingUtilities extends Static { * * @see org.apache.sis.referencing.internal.VerticalDatumTypes#ELLIPSOIDAL */ + @SuppressWarnings("deprecation") public static boolean isEllipsoidalHeight(final VerticalDatum datum) { if (datum != null) { final VerticalDatumType type = datum.getVerticalDatumType(); diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/GeodeticObjectVerifier.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/GeodeticObjectVerifier.java index b3c38e3346..dec5d99570 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/GeodeticObjectVerifier.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/GeodeticObjectVerifier.java @@ -218,7 +218,7 @@ public final class GeodeticObjectVerifier { * @param isExtentMandatory {@code true} if the domain of validity is required to contain an * {@code Extent} element for the world, or {@code false} if optional. */ - public static void assertIsWGS84(final GeodeticDatum datum, boolean isExtentMandatory) { + public static void assertIsWGS84(final GeodeticDatum datum, final boolean isExtentMandatory) { assertEquals("World Geodetic System 1984", datum.getName().getCode(), "name"); assertIsWorld (datum, isExtentMandatory); assertIsGreenwich(datum.getPrimeMeridian()); diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/DefaultImageCRSTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/DefaultImageCRSTest.java index 72ef335fd4..a1cbedb837 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/DefaultImageCRSTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/DefaultImageCRSTest.java @@ -46,7 +46,7 @@ import static org.opengis.test.Assertions.assertAxisDirectionsEqual; * * @author Martin Desruisseaux (Geomatys) */ -@SuppressWarnings("deprecation") +@SuppressWarnings("removal") public final class DefaultImageCRSTest extends TestCase { /** * Creates a new test case. diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/HardCodedCRS.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/HardCodedCRS.java index a0739e7e8b..9e9b11e690 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/HardCodedCRS.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/HardCodedCRS.java @@ -201,6 +201,7 @@ public final class HardCodedCRS { * A geocentric CRS with a spherical coordinate system. * Prime meridian is Greenwich, geodetic datum is WGS84 and linear units are metres. */ + @SuppressWarnings("deprecation") public static final DefaultGeocentricCRS SPHERICAL = new DefaultGeocentricCRS( getProperties(HardCodedCS.SPHERICAL), HardCodedDatum.WGS84, HardCodedCS.SPHERICAL); @@ -211,6 +212,7 @@ public final class HardCodedCRS { * The <var>Y</var> axis points East. * The <var>Z</var> axis points North. */ + @SuppressWarnings("deprecation") public static final DefaultGeocentricCRS GEOCENTRIC = new DefaultGeocentricCRS( getProperties(HardCodedCS.GEOCENTRIC), HardCodedDatum.WGS84, HardCodedCS.GEOCENTRIC); @@ -321,7 +323,7 @@ public final class HardCodedCRS { * <p>The {@code PixelInCell} attribute of the associated {@code ImageDatum} * is set to {@link PixelInCell#CELL_CENTER}.</p> */ - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") public static final DefaultImageCRS IMAGE = new DefaultImageCRS( getProperties(HardCodedDatum.IMAGE), HardCodedDatum.IMAGE, HardCodedCS.GRID); diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/HardCodedDatum.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/HardCodedDatum.java index a675f73064..349a4016cf 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/HardCodedDatum.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/HardCodedDatum.java @@ -118,6 +118,7 @@ public final class HardCodedDatum { * Ellipsoid for measurements of height above the ellipsoid. * This is not a valid datum according ISO 19111, but is used by Apache SIS for internal calculation. */ + @SuppressWarnings("deprecation") public static final DefaultVerticalDatum ELLIPSOID = new DefaultVerticalDatum( properties("Ellipsoid", null, getScope(SPHERE)), VerticalDatumTypes.ELLIPSOIDAL); @@ -153,7 +154,7 @@ public final class HardCodedDatum { /** * Image with {@link PixelInCell#CELL_CENTER}. */ - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") public static final DefaultImageDatum IMAGE = new DefaultImageDatum( properties("Image", null, null), PixelInCell.CELL_CENTER); diff --git a/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/CRSBuilder.java b/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/CRSBuilder.java index b1ba04504f..29a1c9b0cb 100644 --- a/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/CRSBuilder.java +++ b/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/CRSBuilder.java @@ -662,10 +662,10 @@ previous: for (int i=components.size(); --i >= 0;) { * Possibly sets {@link #datum} and {@link #coordinateSystem} to predefined objects * matching the axes defined in the netCDF file. */ + @SuppressWarnings("deprecation") @Override void setPredefinedComponents(final Decoder decoder) throws FactoryException { super.setPredefinedComponents(decoder); if (isPredefinedCS(Units.DEGREE)) { - @SuppressWarnings("deprecation") GeocentricCRS crs = defaultCRS.spherical(); if (isLongitudeFirst) { crs = DefaultGeocentricCRS.castOrCopy(crs).forConvention(AxesConvention.RIGHT_HANDED); @@ -892,6 +892,7 @@ previous: for (int i=components.size(); --i >= 0;) { /** * Creates a {@link VerticalDatum} for <q>Unknown datum based on Mean Sea Level</q>. */ + @SuppressWarnings("deprecation") @Override void createDatum(DatumFactory factory, Map<String,?> properties) throws FactoryException { datum = factory.createVerticalDatum(properties, VerticalDatumType.GEOIDAL); } diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/DefaultInternationalString.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/DefaultInternationalString.java index ae2dd47a9d..e71dea3b1a 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/DefaultInternationalString.java +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/DefaultInternationalString.java @@ -44,7 +44,7 @@ import org.apache.sis.util.collection.Containers; * SIS typically references them as if they were immutable because of their <i>add-only</i> behavior. * * @author Martin Desruisseaux (IRD, Geomatys) - * @version 1.4 + * @version 1.5 * * @see org.apache.sis.util.iso.Types#toInternationalString(Map, String) * @@ -180,35 +180,27 @@ public class DefaultInternationalString extends AbstractInternationalString impl /** * Returns a string in the specified locale. If there is no string for that {@code locale}, - * then this method search for a locale without the {@linkplain Locale#getVariant() variant} - * part. If no string are found, then this method search for a locale without the - * {@linkplain Locale#getCountry() country} part. If none are found, then this method returns - * {@code null}. + * then this method searches for a locale without the {@linkplain Locale#getVariant() variant} part. + * If no string are found, then searches for a locale without {@linkplain Locale#getCountry() country}. + * If none are found, then this method returns {@code null}. * * @param locale the locale to look for, or {@code null}. * @return the string in the specified locale, or {@code null} if none was found. */ - @SuppressWarnings("deprecation") private String getString(Locale locale) { + Locale.Builder builder = null; while (locale != null) { final String text = localeMap.get(locale); if (text != null) { return text; } - final String language = locale.getLanguage(); - final String country = locale.getCountry (); - final String variant = locale.getVariant (); - if (!variant.isEmpty()) { - // TODO: replace by Locale.of(…) with JDK19. - locale = new Locale(language, country); - continue; - } - if (!country.isEmpty()) { - // TODO: replace by Locale.of(…) with JDK19. - locale = new Locale(language); - continue; + if (builder == null) { + builder = new Locale.Builder().setLanguage(locale.getLanguage()).setRegion(locale.getCountry()); + } else { + if (locale.getCountry().isEmpty()) break; + builder.setRegion(null); } - break; + locale = builder.build(); } return null; } diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/Locales.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/Locales.java index 969ff4d0fd..f0ca82de40 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/Locales.java +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/Locales.java @@ -44,13 +44,15 @@ import static org.apache.sis.util.resources.IndexedResourceBundle.LOGGER; * * @author Martin Desruisseaux (IRD, Geomatys) * @author Cullen Rombach (Image Matters) - * @version 0.8 + * @version 1.5 * @since 0.3 */ public final class Locales extends Static { /** * A read-only map for canonicalizing the locales. Filled on class * initialization in order to avoid the need for synchronization. + * + * @see #unique(Locale) */ private static final Map<Locale,Locale> POOL; static { @@ -100,7 +102,6 @@ public final class Locales extends Static { */ private static final short[] ISO3, ISO2; static { - final Short CONFLICT = 0; // Sentinel value for conflicts (paranoiac safety). final Map<Short,Short> map = new TreeMap<>(); for (final Locale locale : POOL.values()) { short type = LANGUAGE; // 0 for language, or leftmost bit set for country. @@ -118,13 +119,13 @@ public final class Locales extends Static { if (p != null && p != alpha2) { // We do not expect any conflict. But if it happen anyway, conservatively // remember that we should not perform any substitution for that code. - map.put(alpha3, CONFLICT); + map.put(alpha3, (short) 0); } } } } while ((type ^= COUNTRY) != LANGUAGE); } - while (map.values().remove(CONFLICT)); // Remove all conflicts that we may have found. + map.values().removeIf((v) -> v == (short) 0); // Remove all conflicts that we may have found. ISO3 = new short[map.size()]; ISO2 = new short[map.size()]; int i = 0; @@ -207,7 +208,6 @@ filter: for (final Locale locale : locales) { * @param locales the locales from which to get the languages. * @return the languages, without country or variant information. */ - @SuppressWarnings("deprecation") private static Locale[] getLanguages(final Locale... locales) { final Set<String> codes = JDK19.newLinkedHashSet(locales.length); for (final Locale locale : locales) { @@ -215,9 +215,9 @@ filter: for (final Locale locale : locales) { } int i=0; final Locale[] languages = new Locale[codes.size()]; + final var builder = new Locale.Builder(); for (final String code : codes) { - // TODO: replace by Locale.of(…) with JDK19. - languages[i++] = unique(new Locale(code)); + languages[i++] = unique(builder.setLanguage(code).build()); } return languages; } @@ -358,7 +358,6 @@ filter: for (final Locale locale : locales) { * @return a unique instance of the given locale, or {@code locale} if the given locale is not cached. */ public static Locale unique(final Locale locale) { - final Locale candidate = POOL.get(locale); - return (candidate != null) ? candidate : locale; + return POOL.getOrDefault(locale, locale); } } diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/LoggingWatcher.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/LoggingWatcher.java index c3da1d85ad..0b1addf8c0 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/LoggingWatcher.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/LoggingWatcher.java @@ -93,7 +93,7 @@ public final class LoggingWatcher implements BeforeEachCallback, AfterEachCallba * @ResourceLock(value=LoggingWatcher.LOCK, mode=ResourceAccessMode.READ_WRITE) * @Execution(ExecutionMode.SAME_THREAD) * public class MyTest { - * } + * } * } */ public static final String LOCK = "Logging"; @@ -244,6 +244,7 @@ public final class LoggingWatcher implements BeforeEachCallback, AfterEachCallba assertTrue(allFilters.remove(this)); logger.setFilter(allFilters.peek()); allFilters = null; + // Note: references to `allFilters` may still exist in other `LoggingWatcher` instances. } } @@ -252,7 +253,7 @@ public final class LoggingWatcher implements BeforeEachCallback, AfterEachCallba * This method adds the logging message to the {@link #messages} list. * * @param record the intercepted log record. - * @return {@code true} if verbose mode, or {@code false} is quiet mode. + * @return {@code true} if verbose mode, or {@code false} if quiet mode. */ @Override public final boolean isLoggable(final LogRecord record) { @@ -264,6 +265,9 @@ public final class LoggingWatcher implements BeforeEachCallback, AfterEachCallba */ LoggingWatcher owner = null; synchronized (logger) { + if (allFilters == null) { // Should never be null, but sometime happens for an unknown reason. + return true; + } for (final LoggingWatcher w : allFilters) { if (w.isMultiThread || w.threadId == record.getLongThreadID()) { owner = w; diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/CRSChooser.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/CRSChooser.java index 8ba3e2497e..f4ec1b16a5 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/CRSChooser.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/CRSChooser.java @@ -152,6 +152,7 @@ public class CRSChooser extends Dialog<CoordinateReferenceSystem> { * @param areaOfInterest geographic area for which to choose a CRS, or {@code null} if no restriction. * @param locale the preferred locale for displaying object name, or {@code null} for the default locale. */ + @SuppressWarnings({"unchecked", "this-escape"}) public CRSChooser(final CRSAuthorityFactory factory, final Envelope areaOfInterest, Locale locale) { this.areaOfInterest = Utils.toGeographic(CRSChooser.class, "<init>", areaOfInterest); if (locale == null) locale = Locale.getDefault(); @@ -347,7 +348,7 @@ public class CRSChooser extends Dialog<CoordinateReferenceSystem> { /** * Sets the text that describes the domain of validity. */ - private void setDomainOfValidity(CoordinateReferenceSystem crs, final Locale locale) { + private void setDomainOfValidity(final CoordinateReferenceSystem crs, final Locale locale) { String extent = null; for (ObjectDomain c : crs.getDomains()) { extent = Extents.getDescription(c.getDomainOfValidity(), locale); @@ -356,9 +357,9 @@ public class CRSChooser extends Dialog<CoordinateReferenceSystem> { String tip = extent; Color color = Styles.NORMAL_TEXT; if (!Utils.intersects(areaOfInterest, crs)) { - tip = Resources.forLocale(locale).getString(Resources.Keys.DoesNotCoverAOI); - extent = Styles.WARNING_ICON + " " + (extent != null ? extent : tip); - color = Styles.ERROR_TEXT; + tip = Resources.forLocale(locale).getString(Resources.Keys.DoesNotCoverAOI); + extent = Styles.WARNING_ICON + " " + (extent != null ? extent : tip); + color = Styles.ERROR_TEXT; } domain.setTextFill(color); domain.setText(extent);