Adapt for the removal of the `Duration`, `PeriodDuration` and `IntervalLength` interfaces from the `org.opengis.temporal` package.
Those interfaces are replaced by `java.time.temporal.TemporalAmount`, `java.time.Period` and `java.time.Duration` respectively.
https://github.com/opengeospatial/geoapi/issues/94
diff --git a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/filter/PeriodLiteral.java b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/filter/PeriodLiteral.java
index 5624bfe..3afd405 100644
--- a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/filter/PeriodLiteral.java
+++ b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/filter/PeriodLiteral.java
@@ -27,13 +27,13 @@
import org.opengis.filter.Expression;
import org.opengis.filter.Literal;
import org.opengis.temporal.Period;
-import org.opengis.temporal.Duration;
import org.opengis.temporal.RelativePosition;
import org.opengis.temporal.TemporalPosition;
import org.opengis.temporal.TemporalPrimitive;
import org.opengis.temporal.TemporalGeometricPrimitive;
// Specific to the geoapi-4.0 branch:
+import java.time.temporal.TemporalAmount;
import org.opengis.metadata.Identifier;
@@ -75,16 +75,16 @@
@Override public Identifier getName() {throw new UnsupportedOperationException();}
@Override public TemporalPosition getTemporalPosition() {throw new UnsupportedOperationException();}
@Override public RelativePosition relativePosition(TemporalPrimitive o) {throw new UnsupportedOperationException();}
- @Override public Duration distance(TemporalGeometricPrimitive o) {throw new UnsupportedOperationException();}
- @Override public Duration length() {throw new UnsupportedOperationException();}
+ @Override public TemporalAmount distance(TemporalGeometricPrimitive o) {throw new UnsupportedOperationException();}
+ @Override public TemporalAmount length() {throw new UnsupportedOperationException();}
};
}
/** Not needed for the tests. */
@Override public Identifier getName() {throw new UnsupportedOperationException();}
@Override public RelativePosition relativePosition(TemporalPrimitive o) {throw new UnsupportedOperationException();}
- @Override public Duration distance(TemporalGeometricPrimitive o) {throw new UnsupportedOperationException();}
- @Override public Duration length() {throw new UnsupportedOperationException();}
+ @Override public TemporalAmount distance(TemporalGeometricPrimitive o) {throw new UnsupportedOperationException();}
+ @Override public TemporalAmount length() {throw new UnsupportedOperationException();}
@Override public <N> Expression<Feature,N> toValueType(Class<N> target) {throw new UnsupportedOperationException();}
/**
diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java
index de564ef..06708bb 100644
--- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java
+++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java
@@ -17,12 +17,12 @@
package org.apache.sis.metadata.iso.distribution;
import java.util.Collection;
+import java.time.temporal.TemporalAmount;
import jakarta.xml.bind.annotation.XmlType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.opengis.util.InternationalString;
-import org.opengis.temporal.PeriodDuration;
import org.opengis.metadata.citation.OnlineResource;
import org.opengis.metadata.distribution.DigitalTransferOptions;
import org.opengis.metadata.distribution.Format;
@@ -32,7 +32,7 @@
import org.apache.sis.measure.ValueRange;
import org.apache.sis.metadata.internal.Dependencies;
import org.apache.sis.xml.bind.FilterByVersion;
-import org.apache.sis.xml.bind.gts.TM_PeriodDuration;
+import org.apache.sis.xml.bind.gts.TM_Duration;
import org.apache.sis.util.privy.CollectionsExt;
import static org.apache.sis.metadata.privy.ImplementationHelper.ensurePositive;
@@ -53,7 +53,7 @@
* @author Touraïvane (IRD)
* @author Cédric Briançon (Geomatys)
* @author Cullen Rombach (Image Matters)
- * @version 1.4
+ * @version 1.5
* @since 0.3
*/
@XmlType(name = "MD_DigitalTransferOptions_Type", propOrder = {
@@ -69,7 +69,7 @@
/**
* Serial number for inter-operability with different versions.
*/
- private static final long serialVersionUID = -2901375920581273330L;
+ private static final long serialVersionUID = -7094568309031595844L;
/**
* Tiles, layers, geographic areas, etc., in which data is available.
@@ -99,7 +99,7 @@
* Rate of occurrence of distribution.
*/
@SuppressWarnings("serial")
- private PeriodDuration transferFrequency;
+ private TemporalAmount transferFrequency;
/**
* Formats of distribution.
@@ -128,6 +128,7 @@
*
* @see #castOrCopy(DigitalTransferOptions)
*/
+ @SuppressWarnings("this-escape")
public DefaultDigitalTransferOptions(final DigitalTransferOptions object) {
super(object);
if (object != null) {
@@ -297,8 +298,8 @@
*/
@Override
@XmlElement(name = "transferFrequency")
- @XmlJavaTypeAdapter(TM_PeriodDuration.Since2014.class)
- public PeriodDuration getTransferFrequency() {
+ @XmlJavaTypeAdapter(TM_Duration.Since2014.class)
+ public TemporalAmount getTransferFrequency() {
return transferFrequency;
}
@@ -309,7 +310,7 @@
*
* @since 0.5
*/
- public void setTransferFrequency(final PeriodDuration newValue) {
+ public void setTransferFrequency(final TemporalAmount newValue) {
checkWritePermission(transferFrequency);
transferFrequency = newValue;
}
diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/distribution/package-info.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/distribution/package-info.java
index 04079f2..07becb2 100644
--- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/distribution/package-info.java
+++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/distribution/package-info.java
@@ -68,7 +68,7 @@
* @author Touraïvane (IRD)
* @author Cédric Briançon (Geomatys)
* @author Cullen Rombach (Image Matters)
- * @version 1.4
+ * @version 1.5
* @since 0.3
*/
@XmlSchema(location="https://schemas.isotc211.org/19115/-3/mrd/1.0/mrd.xsd",
diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/identification/AbstractIdentification.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/identification/AbstractIdentification.java
index 8fde87b..e3132e1 100644
--- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/identification/AbstractIdentification.java
+++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/identification/AbstractIdentification.java
@@ -49,8 +49,8 @@
import org.apache.sis.util.iso.Types;
// Specific to the geoapi-3.1 and geoapi-4.0 branches:
+import java.time.temporal.TemporalAmount;
import org.opengis.metadata.identification.AssociatedResource;
-import org.opengis.temporal.Duration;
// Specific to the geoapi-4.0 branch:
import org.opengis.metadata.citation.Responsibility;
@@ -86,7 +86,7 @@
* @author Touraïvane (IRD)
* @author Cédric Briançon (Geomatys)
* @author Cullen Rombach (Image Matters)
- * @version 1.4
+ * @version 1.5
* @since 0.3
*/
@XmlType(name = "AbstractMD_Identification_Type", propOrder = {
@@ -127,7 +127,7 @@
/**
* Serial number for compatibility with different versions.
*/
- private static final long serialVersionUID = -1132210324047663554L;
+ private static final long serialVersionUID = 157053637951213015L;
/**
* Citation for the resource(s).
@@ -182,7 +182,7 @@
* Smallest resolvable temporal period in a resource.
*/
@SuppressWarnings("serial")
- private Collection<Duration> temporalResolutions;
+ private Collection<TemporalAmount> temporalResolutions;
/**
* Main theme(s) of the resource.
@@ -277,6 +277,7 @@
*
* @see #castOrCopy(Identification)
*/
+ @SuppressWarnings("this-escape")
public AbstractIdentification(final Identification object) {
super(object);
if (object != null) {
@@ -288,7 +289,7 @@
pointOfContacts = copyCollection(object.getPointOfContacts(), Responsibility.class);
spatialRepresentationTypes = copyCollection(object.getSpatialRepresentationTypes(), SpatialRepresentationType.class);
spatialResolutions = copyCollection(object.getSpatialResolutions(), Resolution.class);
- temporalResolutions = copyCollection(object.getTemporalResolutions(), Duration.class);
+ temporalResolutions = copyCollection(object.getTemporalResolutions(), TemporalAmount.class);
topicCategories = copyCollection(object.getTopicCategories(), TopicCategory.class);
extents = copyCollection(object.getExtents(), Extent.class);
additionalDocumentations = copyCollection(object.getAdditionalDocumentations(), Citation.class);
@@ -520,12 +521,12 @@
*
* @return smallest resolvable temporal period in a resource.
*
- * @since 2.0
+ * @since 1.5
*/
@Override
// @XmlElement at the end of this class.
- public Collection<Duration> getTemporalResolutions() {
- return temporalResolutions = nonNullCollection(temporalResolutions, Duration.class);
+ public Collection<TemporalAmount> getTemporalResolutions() {
+ return temporalResolutions = nonNullCollection(temporalResolutions, TemporalAmount.class);
}
/**
@@ -533,10 +534,10 @@
*
* @param newValues the new temporal resolutions.
*
- * @since 2.0
+ * @since 1.5
*/
- public void setTemporalResolutions(final Collection<? extends Duration> newValues) {
- temporalResolutions = writeCollection(newValues, temporalResolutions, Duration.class);
+ public void setTemporalResolutions(final Collection<? extends TemporalAmount> newValues) {
+ temporalResolutions = writeCollection(newValues, temporalResolutions, TemporalAmount.class);
}
/**
@@ -852,7 +853,7 @@
* into {@code PeriodDuration} objects. Need to add support for {@code IntervalLength} in the future.
*/
@XmlElement(name = "temporalResolution")
- private Collection<Duration> getTemporalResolution() {
+ private Collection<TemporalAmount> getTemporalResolution() {
return FilterByVersion.CURRENT_METADATA.accept() ? getTemporalResolutions() : null;
}
diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/identification/package-info.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/identification/package-info.java
index 9a90e2c..8aa8ff4 100644
--- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/identification/package-info.java
+++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/identification/package-info.java
@@ -96,7 +96,7 @@
* @author Touraïvane (IRD)
* @author Cédric Briançon (Geomatys)
* @author Cullen Rombach (Image Matters)
- * @version 1.4
+ * @version 1.5
* @since 0.3
*/
@XmlSchema(location="https://schemas.isotc211.org/19115/-3/mri/1.0/mri.xsd",
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 b2b4cdf..9a6ca19 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
@@ -20,6 +20,7 @@
import java.util.Iterator;
import java.util.Collection;
import java.util.Collections;
+import java.time.temporal.TemporalAmount;
import jakarta.xml.bind.annotation.XmlType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
@@ -29,7 +30,6 @@
import org.opengis.metadata.maintenance.MaintenanceInformation;
import org.opengis.metadata.maintenance.ScopeCode;
import org.opengis.metadata.maintenance.ScopeDescription;
-import org.opengis.temporal.PeriodDuration;
import org.opengis.util.InternationalString;
import org.apache.sis.metadata.iso.ISOMetadata;
import org.apache.sis.metadata.iso.citation.DefaultCitationDate;
@@ -69,7 +69,7 @@
* @author Guilhem Legal (Geomatys)
* @author Rémi Maréchal (Geomatys)
* @author Cullen Rombach (Image Matters)
- * @version 1.4
+ * @version 1.5
* @since 0.3
*/
@XmlType(name = "MD_MaintenanceInformation_Type", propOrder = {
@@ -88,7 +88,7 @@
/**
* Serial number for inter-operability with different versions.
*/
- private static final long serialVersionUID = -8736825706141936429L;
+ private static final long serialVersionUID = -7934472150551882812L;
/**
* Frequency with which changes and additions are made to the resource after the
@@ -106,7 +106,7 @@
* Maintenance period other than those defined, in milliseconds.
*/
@SuppressWarnings("serial")
- private PeriodDuration userDefinedMaintenanceFrequency;
+ private TemporalAmount userDefinedMaintenanceFrequency;
/**
* Type of resource and / or extent to which the maintenance information applies.
@@ -307,7 +307,7 @@
*/
@Override
@XmlElement(name = "userDefinedMaintenanceFrequency")
- public PeriodDuration getUserDefinedMaintenanceFrequency() {
+ public TemporalAmount getUserDefinedMaintenanceFrequency() {
return userDefinedMaintenanceFrequency;
}
@@ -316,7 +316,7 @@
*
* @param newValue the new user defined maintenance frequency.
*/
- public void setUserDefinedMaintenanceFrequency(final PeriodDuration newValue) {
+ public void setUserDefinedMaintenanceFrequency(final TemporalAmount newValue) {
checkWritePermission(userDefinedMaintenanceFrequency);
userDefinedMaintenanceFrequency = newValue;
}
diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/maintenance/package-info.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/maintenance/package-info.java
index 2b75091..e72b18d 100644
--- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/maintenance/package-info.java
+++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/maintenance/package-info.java
@@ -63,7 +63,7 @@
* @author Touraïvane (IRD)
* @author Cédric Briançon (Geomatys)
* @author Cullen Rombach (Image Matters)
- * @version 1.4
+ * @version 1.5
* @since 0.3
*/
@XmlSchema(location="https://schemas.isotc211.org/19115/-3/mmi/1.0/mmi.xsd",
@@ -83,7 +83,7 @@
@XmlJavaTypeAdapter(MD_Scope.class),
@XmlJavaTypeAdapter(MD_ScopeCode.class),
@XmlJavaTypeAdapter(MD_ScopeDescription.class),
- @XmlJavaTypeAdapter(TM_PeriodDuration.class),
+ @XmlJavaTypeAdapter(TM_Duration.class),
// Java types, primitive types and basic OGC types handling
@XmlJavaTypeAdapter(StringAdapter.class),
@@ -104,4 +104,4 @@
import org.apache.sis.xml.bind.gco.*;
import org.apache.sis.xml.bind.metadata.*;
import org.apache.sis.xml.bind.metadata.code.*;
-import org.apache.sis.xml.bind.gts.TM_PeriodDuration;
+import org.apache.sis.xml.bind.gts.TM_Duration;
diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/simple/SimpleDuration.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/simple/SimpleDuration.java
deleted file mode 100644
index ca7d4a9..0000000
--- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/simple/SimpleDuration.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sis.metadata.simple;
-
-import org.apache.sis.util.privy.Numerics;
-
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.temporal.Duration;
-
-
-/**
- * A temporary implementation of {@link Duration}.
- * Will probably be deleted in some future version.
- *
- * @author Martin Desruisseaux (Geomatys)
- */
-public class SimpleDuration implements Duration {
- /**
- * Duration in days.
- */
- public final double duration;
-
- /**
- * Creates a new duration.
- *
- * @param duration the duration in days.
- */
- public SimpleDuration(final double duration) {
- this.duration = duration;
- }
-
- /**
- * Returns a string representation of this duration.
- *
- * @return the duration with its unit of measurement.
- */
- @Override
- public String toString() {
- return duration + " days";
- }
-
- /**
- * Returns a hash code value for this duration.
- */
- @Override
- public int hashCode() {
- return Double.hashCode(duration) ^ 37;
- }
-
- /**
- * Compares this duration with the given object for equality.
- *
- * @param other the object to compare with this duration.
- */
- @Override
- public boolean equals(final Object other) {
- if (other instanceof SimpleDuration) {
- return Numerics.equals(duration, ((SimpleDuration) other).duration);
- }
- return false;
- }
-}
diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gts/TM_Duration.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gts/TM_Duration.java
index b2ae505..945dca9 100644
--- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gts/TM_Duration.java
+++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gts/TM_Duration.java
@@ -16,27 +16,31 @@
*/
package org.apache.sis.xml.bind.gts;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import javax.xml.datatype.Duration;
+import javax.xml.datatype.DatatypeConfigurationException;
import jakarta.xml.bind.annotation.XmlElement;
-import org.opengis.temporal.PeriodDuration;
import org.apache.sis.xml.bind.Context;
+import org.apache.sis.xml.privy.XmlUtilities;
import org.apache.sis.xml.bind.gco.PropertyType;
-import org.apache.sis.util.Classes;
import org.apache.sis.util.resources.Errors;
// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.temporal.Duration;
+import java.time.Period;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAmount;
+import java.time.temporal.TemporalUnit;
/**
* Wraps a {@code gts:TM_Duration} element.
*
- * @todo Current implementation supports only ISO 19108 {@code Duration} that are instance of {@code DurationPeriod}.
- *
* @author Guilhem Legal (Geomatys)
* @author Martin Desruisseaux (Geomatys)
* @author Cullen Rombach (Image Matters)
*/
-public final class TM_Duration extends PropertyType<TM_Duration, Duration> {
+public class TM_Duration extends PropertyType<TM_Duration, TemporalAmount> {
/**
* Empty constructor for JAXB.
*/
@@ -44,60 +48,135 @@
}
/**
- * Wraps a Temporal Duration value at marshalling-time.
+ * Wraps a duration value at marshalling-time.
*
* @param metadata the metadata value to marshal.
*/
- private TM_Duration(final Duration metadata) {
+ private TM_Duration(final TemporalAmount metadata) {
super(metadata);
}
/**
- * Returns the Duration value wrapped by a {@code gts:TM_Duration} element.
+ * Returns the duration value wrapped by a {@code gts:TM_Duration} element.
*
* @param value the value to marshal.
* @return the adapter which wraps the metadata value.
*/
@Override
- protected TM_Duration wrap(final Duration value) {
+ protected TM_Duration wrap(final TemporalAmount value) {
return new TM_Duration(value);
}
/**
- * Returns the GeoAPI interface which is bound by this adapter.
+ * Returns the interface which is bound by this adapter.
*
- * @return {@code Duration.class}
+ * @return {@code TemporalAmount.class}
*/
@Override
- protected Class<Duration> getBoundType() {
- return Duration.class;
+ protected final Class<TemporalAmount> getBoundType() {
+ return TemporalAmount.class;
}
/**
- * Returns the {@link Duration} generated from the metadata value.
+ * Returns the {@code Duration} generated from the metadata value.
* This method is systematically called at marshalling time by JAXB.
*
* @return the time period, or {@code null}.
*/
@XmlElement(name = "TM_Duration")
- public javax.xml.datatype.Duration getElement() {
- if (metadata != null) {
- if (metadata instanceof PeriodDuration) {
- return TM_PeriodDuration.toXML((PeriodDuration) metadata);
+ public final Duration getElement() {
+ @SuppressWarnings("LocalVariableHidesMemberVariable")
+ final TemporalAmount metadata = this.metadata;
+ if (metadata != null) try {
+ BigInteger years = null;
+ BigInteger months = null;
+ BigInteger days = null;
+ BigInteger hours = null;
+ BigInteger minutes = null;
+ BigDecimal seconds = null;
+ for (TemporalUnit unit : metadata.getUnits()) {
+ if (unit instanceof ChronoUnit) {
+ final BigInteger value = BigInteger.valueOf(metadata.get(unit));
+ switch ((ChronoUnit) unit) {
+ case YEARS: years = value; continue;
+ case MONTHS: months = value; continue;
+ case DAYS: days = value; continue;
+ case HOURS: hours = value; continue;
+ case MINUTES: minutes = value; continue;
+ case SECONDS: seconds = new BigDecimal(value); continue;
+ case MILLIS: seconds = addSeconds(seconds, value, 1000); continue;
+ case MICROS: seconds = addSeconds(seconds, value, 1_000_000); continue;
+ case NANOS: seconds = addSeconds(seconds, value, 1_000_000_000); continue;
+ }
+ }
+ Context.warningOccured(Context.current(), TM_Duration.class, "getElement",
+ Errors.class, Errors.Keys.UnsupportedType_1, unit);
+ return null;
}
- Context.warningOccured(Context.current(), TM_Duration.class, "getElement", Errors.class,
- Errors.Keys.UnsupportedType_1, Classes.getClass(metadata));
+ return XmlUtilities.getDatatypeFactory().newDuration(true, years, months, days, hours, minutes, seconds);
+ } catch (DatatypeConfigurationException e) {
+ Context.warningOccured(Context.current(), TM_Duration.class, "getElement", e, true);
}
return null;
}
/**
- * Sets the value from the {@link Duration}.
+ * Returns <var>current</var> + (<var>numerator</var> / <var>denominator</var>) in seconds.
+ * If {@code current} is {@code null}, then it is considered zero.
+ *
+ * @param current the value to add to in number of seconds, or {@code null} if not yet defined.
+ * @param numerator numerator of the number of seconds to add.
+ * @param denominator denominator of the number of seconds to add.
+ * @return return of the addition, or {@code null} if none.
+ */
+ private static BigDecimal addSeconds(final BigDecimal current, final BigInteger numerator, final int denominator) {
+ if (BigInteger.ZERO.equals(numerator)) {
+ return current;
+ }
+ BigDecimal toAdd = new BigDecimal(numerator).divide(BigDecimal.valueOf(denominator));
+ return (current != null) ? current.add(toAdd) : toAdd;
+ }
+
+ /**
+ * Sets the value from the {@code Duration}.
* This method is called at unmarshalling time by JAXB.
*
* @param duration the value to set.
*/
- public void setElement(final javax.xml.datatype.Duration duration) {
- metadata = TM_PeriodDuration.toISO(duration);
+ public void setElement(final Duration duration) {
+ if (duration != null) {
+ int years = duration.getYears(); // 0 if not present.
+ int months = duration.getMonths();
+ int days = duration.getDays();
+ if ((years | months | days) != 0) {
+ metadata = Period.of(years, months, days);
+ } else {
+ int hours = duration.getHours();
+ int minutes = duration.getMinutes();
+ int seconds = duration.getSeconds();
+ if ((hours | minutes | seconds) != 0) {
+ metadata = java.time.Duration.ofSeconds(((hours * 24L) + minutes)*60 + seconds);
+ }
+ }
+ }
+ }
+
+ /**
+ * Wraps the value only if marshalling an element from the ISO 19115:2014 metadata model.
+ * Otherwise (i.e. if marshalling according legacy ISO 19115:2003 model), omits the element.
+ */
+ public static final class Since2014 extends TM_Duration {
+ /** Empty constructor used only by JAXB. */
+ public Since2014() {
+ }
+
+ /**
+ * Wraps the given value in an ISO 19115-3 element, unless we are marshalling an older document.
+ *
+ * @return a non-null value only if marshalling ISO 19115-3 or newer.
+ */
+ @Override protected TM_Duration wrap(final TemporalAmount value) {
+ return accept2014() ? super.wrap(value) : null;
+ }
}
}
diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gts/TM_PeriodDuration.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gts/TM_PeriodDuration.java
deleted file mode 100644
index 6024d50..0000000
--- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gts/TM_PeriodDuration.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sis.xml.bind.gts;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import javax.xml.datatype.Duration;
-import javax.xml.datatype.DatatypeFactory;
-import javax.xml.datatype.DatatypeConfigurationException;
-import jakarta.xml.bind.annotation.XmlElement;
-import org.opengis.temporal.PeriodDuration;
-import org.opengis.util.InternationalString;
-import org.apache.sis.xml.bind.Context;
-import org.apache.sis.xml.privy.XmlUtilities;
-import org.apache.sis.xml.bind.gco.PropertyType;
-import org.apache.sis.metadata.privy.TemporalUtilities;
-import org.apache.sis.util.SimpleInternationalString;
-
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.temporal.TemporalFactory;
-
-
-/**
- * Wraps a {@code gts:TM_PeriodDuration} element.
- *
- * @todo The work done in the {@link #getElement()} and {@link #setElement(Duration)} methods should move
- * to {@link org.apache.sis.xml.ValueConverter}. However, they rely on the {@link org.opengis.temporal}
- * API in geoapi-pending, which is not very clear... We prefer to hide this for now.
- *
- * @author Guilhem Legal (Geomatys)
- * @author Martin Desruisseaux (Geomatys)
- */
-public class TM_PeriodDuration extends PropertyType<TM_PeriodDuration, PeriodDuration> {
- /**
- * Empty constructor for JAXB.
- */
- public TM_PeriodDuration() {
- }
-
- /**
- * Wraps a Temporal Period Duration value at marshalling-time.
- *
- * @param metadata the metadata value to marshal.
- */
- private TM_PeriodDuration(final PeriodDuration metadata) {
- super(metadata);
- }
-
- /**
- * Returns the Period Duration value wrapped by a {@code gts:TM_PeriodDuration} element.
- *
- * @param value the value to marshal.
- * @return the adapter which wraps the metadata value.
- */
- @Override
- protected TM_PeriodDuration wrap(final PeriodDuration value) {
- return new TM_PeriodDuration(value);
- }
-
- /**
- * Returns the GeoAPI interface which is bound by this adapter.
- *
- * @return {@code PeriodDuration.class}
- */
- @Override
- protected final Class<PeriodDuration> getBoundType() {
- return PeriodDuration.class;
- }
-
- /**
- * Returns the {@link Duration} generated from the metadata value.
- * This method is systematically called at marshalling time by JAXB.
- *
- * @return the time period, or {@code null}.
- */
- @XmlElement(name = "TM_PeriodDuration")
- public final Duration getElement() {
- return toXML(metadata);
- }
-
- /**
- * Converts the given ISO 19108 duration into a Java XML duration.
- */
- static Duration toXML(final PeriodDuration metadata) {
- if (metadata != null) try {
- /*
- * Get the DatatypeFactory first because if not available, then we don't need to parse
- * the calendar fields. This has the side effect of not validating the calendar fields
- * syntax (which should be integer values), but maybe this is what the user wants.
- */
- final DatatypeFactory factory = XmlUtilities.getDatatypeFactory();
- InternationalString value;
- BigInteger years = null;
- if ((value = metadata.getYears()) != null) {
- years = new BigInteger(value.toString());
- }
- BigInteger months = null;
- if ((value = metadata.getMonths()) != null) {
- months = new BigInteger(value.toString());
- }
- BigInteger days = null;
- if ((value = metadata.getDays()) != null) {
- days = new BigInteger(value.toString());
- }
- BigInteger hours = null;
- if ((value = metadata.getHours()) != null) {
- hours = new BigInteger(value.toString());
- }
- BigInteger minutes = null;
- if ((value = metadata.getMinutes()) != null) {
- minutes = new BigInteger(value.toString());
- }
- BigDecimal seconds = null;
- if ((value = metadata.getSeconds()) != null) {
- seconds = new BigDecimal(value.toString());
- }
- return factory.newDuration(true, years, months, days, hours, minutes, seconds);
- } catch (DatatypeConfigurationException e) {
- Context.warningOccured(Context.current(), TM_PeriodDuration.class, "toXML", e, true);
- }
- return null;
- }
-
- /**
- * Sets the value from the {@link Duration}.
- * This method is called at unmarshalling time by JAXB.
- *
- * @param duration the adapter to set.
- */
- public final void setElement(final Duration duration) {
- metadata = toISO(duration);
- }
-
- /**
- * Converts the given Java XML duration into an ISO 19108 duration.
- */
- static PeriodDuration toISO(final Duration duration) {
- if (duration != null) {
- final TemporalFactory factory = TemporalUtilities.getTemporalFactory();
- InternationalString years = null;
- int value;
- if ((value = duration.getYears()) != 0) {
- years = new SimpleInternationalString(Integer.toString(value));
- }
- InternationalString months = null;
- if ((value = duration.getMonths()) != 0) {
- months = new SimpleInternationalString(Integer.toString(value));
- }
- InternationalString weeks = null; // No weeks in javax.xml.datatype.Duration
- InternationalString days = null;
- if ((value = duration.getDays()) != 0) {
- days = new SimpleInternationalString(Integer.toString(value));
- }
- InternationalString hours = null;
- if ((value = duration.getHours()) != 0) {
- hours = new SimpleInternationalString(Integer.toString(value));
- }
- InternationalString minutes = null;
- if ((value = duration.getMinutes()) != 0) {
- minutes = new SimpleInternationalString(Integer.toString(value));
- }
- InternationalString seconds = null;
- if ((value = duration.getSeconds()) != 0) {
- seconds = new SimpleInternationalString(Integer.toString(value));
- }
- return factory.createPeriodDuration(years, months, weeks, days, hours, minutes, seconds);
- }
- return null;
- }
-
- /**
- * Wraps the value only if marshalling an element from the ISO 19115:2014 metadata model.
- * Otherwise (i.e. if marshalling according legacy ISO 19115:2003 model), omits the element.
- */
- public static final class Since2014 extends TM_PeriodDuration {
- /** Empty constructor used only by JAXB. */
- public Since2014() {
- }
-
- /**
- * Wraps the given value in an ISO 19115-3 element, unless we are marshalling an older document.
- *
- * @return a non-null value only if marshalling ISO 19115-3 or newer.
- */
- @Override protected TM_PeriodDuration wrap(final PeriodDuration value) {
- return accept2014() ? super.wrap(value) : null;
- }
- }
-}
diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/PropertyAccessorTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/PropertyAccessorTest.java
index 9bbd700..f093384 100644
--- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/PropertyAccessorTest.java
+++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/PropertyAccessorTest.java
@@ -66,9 +66,9 @@
import org.opengis.metadata.content.AttributeGroup;
import org.opengis.referencing.ObjectDomain;
import org.opengis.referencing.datum.DatumEnsemble;
-import org.opengis.temporal.Duration;
// Specific to the geoapi-4.0 branch:
+import java.time.temporal.TemporalAmount;
import org.opengis.metadata.citation.Responsibility;
@@ -215,7 +215,7 @@
Identification.class, "getPointOfContacts", "pointOfContacts", "pointOfContact", "Point of contacts", Responsibility[].class,
Identification.class, "getSpatialRepresentationTypes", "spatialRepresentationTypes", "spatialRepresentationType", "Spatial representation types", SpatialRepresentationType[].class,
Identification.class, "getSpatialResolutions", "spatialResolutions", "spatialResolution", "Spatial resolutions", Resolution[].class,
- Identification.class, "getTemporalResolutions", "temporalResolutions", "temporalResolution", "Temporal resolutions", Duration[].class,
+ Identification.class, "getTemporalResolutions", "temporalResolutions", "temporalResolution", "Temporal resolutions", TemporalAmount[].class,
Identification.class, "getTopicCategories", "topicCategories", "topicCategory", "Topic categories", TopicCategory[].class,
Identification.class, "getExtents", "extents", "extent", "Extents", Extent[].class,
Identification.class, "getAdditionalDocumentations", "additionalDocumentations", "additionalDocumentation", "Additional documentations", Citation[].class,
diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/MetadataBuilder.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/MetadataBuilder.java
index 652d2bc..7ab125d 100644
--- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/MetadataBuilder.java
+++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/MetadataBuilder.java
@@ -17,6 +17,8 @@
package org.apache.sis.storage.base;
import java.time.Instant;
+import java.time.Duration;
+import java.time.temporal.TemporalAmount;
import java.util.Date;
import java.util.Locale;
import java.util.Optional;
@@ -68,6 +70,7 @@
import org.apache.sis.util.iso.Types;
import org.apache.sis.util.logging.Logging;
import org.apache.sis.util.privy.CollectionsExt;
+import org.apache.sis.util.privy.StandardDateFormat;
import org.apache.sis.util.privy.Strings;
import org.apache.sis.util.resources.Vocabulary;
import org.apache.sis.metadata.ModifiableMetadata;
@@ -102,9 +105,7 @@
import org.apache.sis.measure.Units;
// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.temporal.Duration;
import org.opengis.feature.FeatureType;
-import org.apache.sis.metadata.simple.SimpleDuration;
/**
@@ -2026,7 +2027,8 @@
*/
public final void addTemporalResolution(final double duration) {
if (Double.isFinite(duration)) {
- addIfNotPresent(identification().getTemporalResolutions(), new SimpleDuration(duration));
+ addIfNotPresent(identification().getTemporalResolutions(),
+ Duration.ofMillis(Math.round(duration * StandardDateFormat.MILLISECONDS_PER_DAY)));
}
}
@@ -3189,7 +3191,7 @@
for (Resolution r : info.getSpatialResolutions()) {
addIfNotPresent(identification.getSpatialResolutions(), r);
}
- for (Duration r : info.getTemporalResolutions()) {
+ for (TemporalAmount r : info.getTemporalResolutions()) {
addIfNotPresent(identification.getTemporalResolutions(), r);
}
for (Format r : info.getResourceFormats()) {
diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/temporal/DefaultPeriodDuration.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/temporal/DefaultPeriodDuration.java
deleted file mode 100644
index 8464454..0000000
--- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/temporal/DefaultPeriodDuration.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sis.pending.temporal;
-
-import java.util.Objects;
-import org.opengis.util.InternationalString;
-
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.temporal.PeriodDuration;
-
-
-/**
- * Default implementation of GeoAPI period duration. This is a temporary class;
- * GeoAPI temporal interfaces are expected to change a lot in a future revision.
- *
- * @author Martin Desruisseaux (Geomatys)
- */
-final class DefaultPeriodDuration implements PeriodDuration {
- /** Components of this period duration. */
- private final InternationalString years, months, week, days, hours, minutes, seconds;
-
- /**
- * Creates a new duration.
- */
- DefaultPeriodDuration(
- final InternationalString years, final InternationalString months,
- final InternationalString week, final InternationalString days,
- final InternationalString hours, final InternationalString minutes, final InternationalString seconds)
- {
- this.years = years;
- this.months = months;
- this.week = week;
- this.days = days;
- this.hours = hours;
- this.minutes = minutes;
- this.seconds = seconds;
- }
-
-
- @Override public InternationalString getDesignator() {return null;}
- @Override public InternationalString getYears() {return years;}
- @Override public InternationalString getMonths() {return months;}
- @Override public InternationalString getDays() {return days;}
- @Override public InternationalString getTimeIndicator() {return null;}
- @Override public InternationalString getHours() {return hours;}
- @Override public InternationalString getMinutes() {return minutes;}
- @Override public InternationalString getSeconds() {return seconds;}
-
- /** String representation. */
- @Override public String toString() {
- return "PeriodDuration[" + years + '-' + months + '-' + days + ' ' + hours + ':' + minutes + ':' + seconds + ']';
- }
-
- /** Hash code value of the time position. */
- @Override public int hashCode() {
- return Objects.hash(years, months, week, days, hours, minutes, seconds);
- }
-
- /** Compares with given object for equality. */
- @Override public boolean equals(final Object obj) {
- if (obj instanceof DefaultPeriodDuration) {
- DefaultPeriodDuration other = (DefaultPeriodDuration) obj;
- return Objects.equals(other.years, years) &&
- Objects.equals(other.months, months) &&
- Objects.equals(other.week, week) &&
- Objects.equals(other.days, days) &&
- Objects.equals(other.hours, hours) &&
- Objects.equals(other.minutes, minutes) &&
- Objects.equals(other.seconds, seconds);
- }
- return false;
- }
-}
diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/temporal/DefaultTemporalFactory.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/temporal/DefaultTemporalFactory.java
index 660f3d8..05ace75 100644
--- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/temporal/DefaultTemporalFactory.java
+++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/temporal/DefaultTemporalFactory.java
@@ -58,15 +58,6 @@
return new DefaultPeriod(begin, end);
}
- /** Creates a period duration. */
- @Override public PeriodDuration createPeriodDuration(
- InternationalString years, InternationalString months,
- InternationalString week, InternationalString days,
- InternationalString hours, InternationalString minutes, InternationalString seconds)
- {
- return new DefaultPeriodDuration(years, months, week, days, hours, minutes, seconds);
- }
-
/** Returns the exception to be thrown by all unsupported methods. */
static UnsupportedOperationException unsupported() {
return new UnsupportedOperationException(Errors.format(Errors.Keys.MissingRequiredModule_1, "sis-temporal"));
@@ -108,12 +99,6 @@
}
/** Unsupported. */
- @SuppressWarnings("rawtypes")
- @Override public IntervalLength createIntervalLenght(Unit unit, int radix, int factor, int value) {
- throw unsupported();
- }
-
- /** Unsupported. */
@Override public JulianDate createJulianDate(TemporalReferenceSystem frame, IndeterminateValue indeterminatePosition, Number coordinateValue) {
throw unsupported();
}
diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/temporal/Primitive.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/temporal/Primitive.java
index d176fa6..0287791 100644
--- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/temporal/Primitive.java
+++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/temporal/Primitive.java
@@ -16,12 +16,12 @@
*/
package org.apache.sis.pending.temporal;
-import org.opengis.temporal.Duration;
import org.opengis.temporal.RelativePosition;
import org.opengis.temporal.TemporalGeometricPrimitive;
import org.opengis.temporal.TemporalPrimitive;
// Specific to the geoapi-4.0 branch:
+import java.time.temporal.TemporalAmount;
import org.opengis.metadata.Identifier;
@@ -63,12 +63,12 @@
}
/** Absolute value of the difference between temporal positions. */
- @Override public final Duration distance(TemporalGeometricPrimitive other) {
+ @Override public final TemporalAmount distance(TemporalGeometricPrimitive other) {
throw DefaultTemporalFactory.unsupported();
}
/** Duration of this temporal geometric primitive. */
- @Override public final Duration length() {
+ @Override public final TemporalAmount length() {
return null; // Do not throw an exception here; this is invoked by reflection.
}
}
diff --git a/geoapi/snapshot b/geoapi/snapshot
index 41a6799..eba6172 160000
--- a/geoapi/snapshot
+++ b/geoapi/snapshot
@@ -1 +1 @@
-Subproject commit 41a6799cb2940149f5f034db64365241198da439
+Subproject commit eba6172d3a3b555c40736fa23efae8ec865d1fba