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 b708580e1ed0aa782c589e6b9d6b2f561ccde1ec Author: Martin Desruisseaux <[email protected]> AuthorDate: Thu Oct 2 12:05:05 2025 +0200 Remove deprecated methods related to `java.util.Date`. --- .../metadata/iso/citation/DefaultCitationDate.java | 17 +--- .../maintenance/DefaultMaintenanceInformation.java | 4 +- .../org/apache/sis/temporal/LenientDateFormat.java | 8 +- .../sis/metadata/iso/DefaultMetadataTest.java | 105 ++++++++++++++------- .../apache/sis/metadata/iso/MarshallingTest.java | 6 +- .../main/org/apache/sis/io/wkt/Formatter.java | 7 +- .../main/org/apache/sis/storage/gpx/Metadata.java | 5 +- 7 files changed, 89 insertions(+), 63 deletions(-) diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/citation/DefaultCitationDate.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/citation/DefaultCitationDate.java index 8f75d6a434..b806a621ab 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/citation/DefaultCitationDate.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/citation/DefaultCitationDate.java @@ -92,21 +92,6 @@ public class DefaultCitationDate extends ISOMetadata implements CitationDate { this.dateType = dateType; } - /** - * Constructs a citation date initialized to the given date. - * - * @param date the reference date for the cited resource. - * @param dateType the event used for reference date. - * - * @deprecated Replaced by {@link #DefaultCitationDate(Temporal, DateType)} - * in order to transition to {@code java.time} API. - */ - @Deprecated(since="1.5", forRemoval=true) - public DefaultCitationDate(final Date date, final DateType dateType) { - this.date = TemporalDate.toTemporal(date); - this.dateType = dateType; - } - /** * Constructs a new instance initialized with the values from the specified metadata object. * This is a <em>shallow</em> copy constructor, because the other metadata contained in the @@ -119,7 +104,7 @@ public class DefaultCitationDate extends ISOMetadata implements CitationDate { public DefaultCitationDate(final CitationDate object) { super(object); if (object != null) { - date = TemporalDate.toTemporal(object.getDate()); + date = object.getReferenceDate(); dateType = object.getDateType(); } } diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java index 81dc199fbe..8816f62478 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java @@ -30,6 +30,7 @@ import org.opengis.metadata.maintenance.MaintenanceInformation; import org.opengis.metadata.maintenance.ScopeCode; import org.opengis.metadata.maintenance.ScopeDescription; import org.opengis.util.InternationalString; +import org.apache.sis.temporal.TemporalDate; import org.apache.sis.metadata.iso.ISOMetadata; import org.apache.sis.metadata.iso.citation.DefaultCitationDate; import org.apache.sis.metadata.iso.legacy.LegacyPropertyAdapter; @@ -290,8 +291,7 @@ public class DefaultMaintenanceInformation extends ISOMetadata implements Mainte } } if (newValue != null) { - @SuppressWarnings("removal") - final var date = new DefaultCitationDate(newValue, DateType.NEXT_UPDATE); + final var date = new DefaultCitationDate(TemporalDate.toTemporal(newValue), DateType.NEXT_UPDATE); if (dates != null) { dates.add(date); } else { diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/temporal/LenientDateFormat.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/temporal/LenientDateFormat.java index 6e270849f6..c3672d4178 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/temporal/LenientDateFormat.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/temporal/LenientDateFormat.java @@ -50,9 +50,9 @@ import org.apache.sis.util.internal.shared.Constants; /** * A date format used for parsing dates in the {@code "yyyy-MM-dd'T'HH:mm:ss.SSSX"} pattern, but in which * the time is optional. For this class, "Standard" is interpreted as "close to ISO 19162 requirements", - * which is not necessarily identical to other ISO standards. + * which is not necessarily identical to other <abbr>ISO</abbr> standards. * - * <p>The main usage for this class is Well Known Text (WKT) parsing and formatting. + * <p>The main usage for this class is Well Known Text (<abbr>WKT</abbr>) parsing and formatting. * ISO 19162 uses ISO 8601:2004 for the dates. Any precision is allowed: the date could have only the year, * or only the year and month, <i>etc</i>. The clock part is optional and also have optional fields: can be * only hours, or only hours and minutes, <i>etc</i>. ISO 19162 said that the timezone is restricted to UTC @@ -227,14 +227,14 @@ replace: if (Character.isWhitespace(c)) { private final DateTimeFormatter formatWithoutZone; /** - * Creates a new format for a default locale in the UTC timezone. + * Creates a new format for a default locale in the <abbr>UTC</abbr> timezone. */ public LenientDateFormat() { formatWithoutZone = format = FORMAT; } /** - * Creates a new format for the given locale in the UTC timezone. + * Creates a new format for the given locale in the <abbr>UTC</abbr> timezone. * * @param locale the locale of the format to create. */ diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/DefaultMetadataTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/DefaultMetadataTest.java index 0366df65b8..6e5ea43db1 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/DefaultMetadataTest.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/DefaultMetadataTest.java @@ -16,6 +16,7 @@ */ package org.apache.sis.metadata.iso; +import java.time.Instant; import java.util.Date; import java.util.Locale; import java.util.Arrays; @@ -36,7 +37,6 @@ import org.apache.sis.metadata.iso.citation.DefaultCitationDate; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; import org.apache.sis.xml.test.TestCase; -import static org.apache.sis.test.TestUtilities.date; import static org.apache.sis.test.TestUtilities.getSingleton; import static org.apache.sis.metadata.Assertions.assertTitleEquals; @@ -55,6 +55,7 @@ import org.opengis.metadata.MetadataScope; * @author Martin Desruisseaux (Geomatys) * @author Cullen Rombach (Image Matters) */ +@SuppressWarnings("deprecation") public final class DefaultMetadataTest extends TestCase { /** * Creates a new test case. @@ -83,11 +84,15 @@ public final class DefaultMetadataTest extends TestCase { } /** - * Tests {@link DefaultMetadata#getFileIdentifier()} and {@link DefaultMetadata#setFileIdentifier(String)} - * legacy methods. Those methods should delegate to newer methods. + * Tests legacy methods related to file identifiers. + * The following methods should delegate to newer methods: + * + * <ul> + * <li>{@link DefaultMetadata#getFileIdentifier()}</li> + * <li>{@link DefaultMetadata#setFileIdentifier(String)}</li> + * </ul> */ @Test - @SuppressWarnings("deprecation") public void testFileIdentifier() { final var metadata = new DefaultMetadata(); assertNull(metadata.getFileIdentifier()); @@ -97,12 +102,16 @@ public final class DefaultMetadataTest extends TestCase { } /** - * Tests {@link DefaultMetadata#getLanguage()}, {@link DefaultMetadata#setLanguage(Locale)} - * and {@link DefaultMetadata#getLocales()} legacy methods. - * Those methods should delegate to newer methods. + * Tests legacy methods related to locales. + * The following methods should delegate to newer methods: + * + * <ul> + * <li>{@link DefaultMetadata#getLanguage()}</li> + * <li>{@link DefaultMetadata#setLanguage(Locale)}</li> + * <li>{@link DefaultMetadata#getLocales()}</li> + * </ul> */ @Test - @SuppressWarnings("deprecation") public void testLocales() { final var metadata = new DefaultMetadata(); assertNull(metadata.getLanguage()); @@ -135,10 +144,15 @@ public final class DefaultMetadataTest extends TestCase { } /** - * Compares the {@link DefaultMetadata#getLanguages()}, {@link DefaultMetadata#getLanguage()} and - * {@link DefaultMetadata#getLocales()} values against the expected array. + * Tests methods related to languages. + * The following methods should delegate to newer methods: + * + * <ul> + * <li>{@link DefaultMetadata#getLocalesAndCharsets()}</li> + * <li>{@link DefaultMetadata#getLanguage()}</li> + * <li>{@link DefaultMetadata#getLocales()}</li> + * </ul> */ - @SuppressWarnings("deprecation") private static void assertLanguagesEquals(final DefaultMetadata metadata, final Locale... expected) { assertArrayEquals(expected, metadata.getLocalesAndCharsets().keySet().toArray()); assertEquals (expected[0], metadata.getLanguage()); @@ -146,11 +160,15 @@ public final class DefaultMetadataTest extends TestCase { } /** - * Tests {@link DefaultMetadata#getParentIdentifier()} and {@link DefaultMetadata#setParentIdentifier(String)} - * methods. + * Tests legacy methods related to metadata identifiers. + * The following methods should delegate to newer methods: + * + * <ul> + * <li>{@link DefaultMetadata#getParentIdentifier()}</li> + * <li>{@link DefaultMetadata#setParentIdentifier(String)}</li> + * </ul> */ @Test - @SuppressWarnings("deprecation") public void testParentIdentifier() { final var metadata = new DefaultMetadata(); assertNull(metadata.getParentIdentifier()); @@ -164,12 +182,17 @@ public final class DefaultMetadataTest extends TestCase { } /** - * Tests {@link DefaultMetadata#getHierarchyLevels()}, {@link DefaultMetadata#getHierarchyLevelNames()}, - * {@link DefaultMetadata#setHierarchyLevels(Collection)} and {@link DefaultMetadata#setHierarchyLevelNames(Collection)} - * methods. + * Tests legacy methods related to metadata hierarchy levels. + * The following methods should delegate to newer methods: + * + * <ul> + * <li>{@link DefaultMetadata#getHierarchyLevels()}</li> + * <li>{@link DefaultMetadata#getHierarchyLevelNames()}</li> + * <li>{@link DefaultMetadata#setHierarchyLevels(Collection)}</li> + * <li>{@link DefaultMetadata#setHierarchyLevelNames(Collection)}</li> + * </ul> */ @Test - @SuppressWarnings("deprecation") public void testHierarchyLevels() { final var names = new String[] {"Bridges", "Golden Gate Bridge"}; final var levels = new ScopeCode[] {ScopeCode.FEATURE_TYPE, ScopeCode.FEATURE}; @@ -220,7 +243,13 @@ public final class DefaultMetadataTest extends TestCase { } /** - * Tests {@link DefaultMetadata#getDateStamp()} and {@link DefaultMetadata#setDateStamp(Date)} methods. + * Tests legacy methods related to date stamps. + * The following methods should delegate to newer methods: + * + * <ul> + * <li>{@link DefaultMetadata#getDateStamp()}</li> + * <li>{@link DefaultMetadata#setDateStamp(Date)}</li> + * </ul> */ @Test @SuppressWarnings("deprecation") @@ -230,30 +259,35 @@ public final class DefaultMetadataTest extends TestCase { /* * Verifies that the deprecated method get its value from the CitationDate objects. */ - Date creation = date("2014-10-07 00:00:00"); + Instant creation = Instant.parse("2014-10-07T00:00:00Z"); final var dates = new DefaultCitationDate[] { - new DefaultCitationDate(date("2014-10-09 00:00:00"), DateType.LAST_UPDATE), + new DefaultCitationDate(Instant.parse("2014-10-09T00:00:00Z"), DateType.LAST_UPDATE), new DefaultCitationDate(creation, DateType.CREATION) }; metadata.setDateInfo(Arrays.asList(dates)); - assertEquals(creation, metadata.getDateStamp()); + assertEquals(creation, metadata.getDateStamp().toInstant()); /* * Invoking the deprecated setters shall modify the CitationDate object * associated to DateType.CREATION. */ - creation = date("2014-10-06 00:00:00"); - metadata.setDateStamp(creation); - assertEquals(creation, dates[1].getDate()); + creation = Instant.parse("2014-10-06T00:00:00Z"); + metadata.setDateStamp(Date.from(creation)); + assertEquals(creation, dates[1].getDate().toInstant()); assertArrayEquals(dates, metadata.getDateInfo().toArray()); } /** - * Tests {@link DefaultMetadata#getMetadataStandardName()}, {@link DefaultMetadata#getMetadataStandardVersion()}, - * {@link DefaultMetadata#setMetadataStandardName(String)} and {@link DefaultMetadata#setMetadataStandardVersion(String)} - * methods. + * Tests legacy methods related to metadata version. + * The following methods should delegate to newer methods: + * + * <ul> + * <li>{@link DefaultMetadata#getMetadataStandardName()}</li> + * <li>{@link DefaultMetadata#getMetadataStandardVersion()}</li> + * <li>{@link DefaultMetadata#setMetadataStandardName(String)}</li> + * <li>{@link DefaultMetadata#setMetadataStandardVersion(String)}</li> + * </ul> */ @Test - @SuppressWarnings("deprecation") public void testMetadataStandard() { final var metadata = new DefaultMetadata(); assertNull(metadata.getMetadataStandardName()); @@ -271,17 +305,22 @@ public final class DefaultMetadataTest extends TestCase { } /** - * Tests {@link DefaultMetadata#getDataSetUri()}. + * Tests legacy methods related to <abbr>URI</abbr>. + * The following methods should delegate to newer methods: + * + * <ul> + * <li>{@link DefaultMetadata#getDataSetUri()}</li> + * </ul> * * @throws URISyntaxException if the URI used in this test is malformed. */ @Test - @SuppressWarnings("deprecation") public void testDataSetUri() throws URISyntaxException { final var metadata = new DefaultMetadata(); metadata.setDataSetUri("file:/tmp/myfile.txt"); assertEquals("file:/tmp/myfile.txt", metadata.getDataSetUri()); - assertEquals("file:/tmp/myfile.txt", getSingleton(getSingleton(metadata.getIdentificationInfo()) - .getCitation().getOnlineResources()).getLinkage().toString()); + assertEquals("file:/tmp/myfile.txt", + getSingleton(getSingleton(metadata.getIdentificationInfo()).getCitation().getOnlineResources()) + .getLinkage().toString()); } } diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/MarshallingTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/MarshallingTest.java index 61136a694a..5685ed4bcf 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/MarshallingTest.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/MarshallingTest.java @@ -229,7 +229,8 @@ public final class MarshallingTest extends TestUsingFile implements Filter { new DefaultResponsibility(Role.POINT_OF_CONTACT, null, individual2))); } // Date info (date stamp in legacy ISO 19115:2003 model) - final var dateInfo = Set.of(new DefaultCitationDate(new Date(1260961229580L), DateType.CREATION)); + final var dateInfo = Set.of(new DefaultCitationDate( + Instant.ofEpochMilli(1260961229580L), DateType.CREATION)); md.setDateInfo(dateInfo); { // Metadata standard @@ -435,7 +436,8 @@ public final class MarshallingTest extends TestUsingFile implements Filter { */ var maintenanceInfo = new DefaultMaintenanceInformation(); maintenanceInfo.setMaintenanceAndUpdateFrequency(MaintenanceFrequency.NOT_PLANNED); - maintenanceInfo.getMaintenanceDates().add(new DefaultCitationDate(new Date(32503676400000L), DateType.REVISION)); + maintenanceInfo.getMaintenanceDates().add(new DefaultCitationDate( + Instant.ofEpochMilli(32503676400000L), DateType.REVISION)); final var maintenanceScope = new DefaultScope(); maintenanceScope.setLevel(ScopeCode.MODEL); { diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/Formatter.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/Formatter.java index 7aa1e3a014..17412831f1 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/Formatter.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/Formatter.java @@ -1246,12 +1246,11 @@ public class Formatter implements Localized { /** * Appends a date. * The {@linkplain Symbols#getSeparator() element separator} will be written before the date if needed. + * This method exists for compatibility with legacy date objects, but {@link #append(Temporal)} should + * be preferred in newer code. * * @param date the date to append to the WKT, or {@code null} if none. - * - * @deprecated Replaced by {@link #append(Temporal)}. */ - @Deprecated(since="1.5", forRemoval=true) public void append(final Date date) { if (date != null) { appendSeparator(); @@ -1261,7 +1260,7 @@ public class Formatter implements Localized { /** * Appends a Boolean value. - * The {@linkplain Symbols#getSeparator() element separator} will be written before the boolean if needed. + * The {@linkplain Symbols#getSeparator() element separator} will be written before the Boolean if needed. * * @param value the Boolean to append to the WKT. */ diff --git a/endorsed/src/org.apache.sis.storage.xml/main/org/apache/sis/storage/gpx/Metadata.java b/endorsed/src/org.apache.sis.storage.xml/main/org/apache/sis/storage/gpx/Metadata.java index 95871c2b89..bbd3d7bb09 100644 --- a/endorsed/src/org.apache.sis.storage.xml/main/org/apache/sis/storage/gpx/Metadata.java +++ b/endorsed/src/org.apache.sis.storage.xml/main/org/apache/sis/storage/gpx/Metadata.java @@ -44,11 +44,12 @@ import org.apache.sis.io.TableAppender; import org.apache.sis.metadata.simple.SimpleMetadata; import org.apache.sis.util.SimpleInternationalString; import org.apache.sis.util.internal.shared.UnmodifiableArrayList; +import org.apache.sis.util.iso.Types; import org.apache.sis.metadata.iso.citation.DefaultCitationDate; import org.apache.sis.metadata.iso.identification.DefaultKeywords; import org.apache.sis.metadata.iso.extent.Extents; import org.apache.sis.referencing.CommonCRS; -import org.apache.sis.util.iso.Types; +import org.apache.sis.temporal.TemporalDate; // Specific to the geoapi-3.1 and geoapi-4.0 branches: import org.opengis.metadata.citation.Responsibility; @@ -364,7 +365,7 @@ public final class Metadata extends SimpleMetadata { @Override public Collection<CitationDate> getDates() { if (time != null) { - return Collections.singletonList(new DefaultCitationDate(time, DateType.CREATION)); + return Collections.singletonList(new DefaultCitationDate(TemporalDate.toTemporal(time), DateType.CREATION)); } return Collections.emptyList(); }
