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 70549aeb3a `TM_Primitive` shall show the period or the instant, but
not both.
70549aeb3a is described below
commit 70549aeb3ab665d189ff7f2c1c91487b721c08ef
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Tue May 14 18:54:55 2024 +0200
`TM_Primitive` shall show the period or the instant, but not both.
---
.../sis/pending/temporal/TemporalUtilities.java | 35 +++++++++++++++++++---
.../org/apache/sis/xml/bind/gml/TM_Primitive.java | 5 ++--
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/pending/temporal/TemporalUtilities.java
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/pending/temporal/TemporalUtilities.java
index 3b10e63c48..9dbd8518ad 100644
---
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/pending/temporal/TemporalUtilities.java
+++
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/pending/temporal/TemporalUtilities.java
@@ -66,7 +66,31 @@ public final class TemporalUtilities {
}
/**
- * Returns the given value as an instant if the period is a single point
in time, or {@code null} otherwis.
+ * Returns the given value as a period if it is not a single point in
time, or {@code null} otherwise.
+ * This method is mutually exclusive with {@link
#getInstant(TemporalPrimitive)}: if one method returns
+ * a non-null value, then the other method shall return a null value.
+ *
+ * @param time the instant or period for which to get a time range, or
{@code null}.
+ * @return the period, or {@code null} if none.
+ */
+ public static Period getPeriod(final TemporalPrimitive time) {
+ if (time instanceof Period) {
+ var p = (Period) time;
+ final Instant begin = p.getBeginning();
+ if (begin != null) {
+ final Instant end = p.getEnding();
+ if (end != null && !begin.equals(end)) {
+ return p;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the given value as an instant if the period is a single point
in time, or {@code null} otherwise.
+ * This method is mutually exclusive with {@link
#getPeriod(TemporalPrimitive)}: if one method returns a
+ * non-null value, then the other method shall return a null value.
*
* @param time the instant or period for which to get a date, or {@code
null}.
* @return the instant, or {@code null} if none.
@@ -76,9 +100,12 @@ public final class TemporalUtilities {
var p = (Period) time;
final Instant begin = p.getBeginning();
final Instant end = p.getEnding();
- if (begin == null) return end;
- if (end == null) return begin;
- if (begin.equals(end)) return end;
+ if (end == null) {
+ return begin;
+ }
+ if (begin == null || begin.equals(end)) {
+ return end;
+ }
}
return null;
}
diff --git
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gml/TM_Primitive.java
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gml/TM_Primitive.java
index a6bc941ef0..4e8c7de401 100644
---
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gml/TM_Primitive.java
+++
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gml/TM_Primitive.java
@@ -82,9 +82,8 @@ public class TM_Primitive extends PropertyType<TM_Primitive,
TemporalPrimitive>
*/
@XmlElement(name = "TimePeriod")
public final TimePeriod getTimePeriod() {
- @SuppressWarnings("LocalVariableHidesMemberVariable")
- final TemporalPrimitive metadata = this.metadata;
- return (metadata instanceof Period) ? new TimePeriod((Period)
metadata) : null;
+ Period period = TemporalUtilities.getPeriod(metadata);
+ return (period != null) ? new TimePeriod(period) : null;
}
/**