This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits 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 2953d8bbee fix(Filter): handle During and AnyIntersects with Period 
objects
2953d8bbee is described below

commit 2953d8bbeeed2bcee26ed76382946d740de60913
Author: jsorel <[email protected]>
AuthorDate: Tue Nov 17 15:33:37 2026 +0100

    fix(Filter): handle During and AnyIntersects with Period objects
---
 .../main/org/apache/sis/filter/TemporalFilter.java |  8 ++++-
 .../org/apache/sis/filter/TemporalOperation.java   | 21 +++++++++++++
 .../org/apache/sis/filter/TemporalFilterTest.java  | 34 ++++++++++++++++++++++
 3 files changed, 62 insertions(+), 1 deletion(-)

diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/TemporalFilter.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/TemporalFilter.java
index e86a63c9a8..271bdbe4c7 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/TemporalFilter.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/TemporalFilter.java
@@ -117,7 +117,13 @@ class TemporalFilter<R,T> extends BinaryFunction<R,T,T>
          * `commonType` of type `Class<T>` no matter if <T> is a super-type or 
a sub-type of <V>, we can
          * assert that the parameterized type of the two expressions is `<? 
extends T>`.
          */
-        final TemporalOperation<?> operation = 
factory.create(TimeMethods.forType(commonType)).unique();
+        /*
+         * Periods are compared by their beginning and ending instants, never 
as whole objects.
+         * Therefore, the comparison methods are requested for the `Period` 
interface rather than
+         * for the implementation class, which may be a final class without 
natural ordering.
+         */
+        final Class<?> methodsType = Period.class.isAssignableFrom(commonType) 
? Period.class : commonType;
+        final TemporalOperation<?> operation = 
factory.create(TimeMethods.forType(methodsType)).unique();
         assert operation.comparators.type.isAssignableFrom(commonType) : 
commonType;
         assert commonType.isAssignableFrom(c1) : c1;
         assert commonType.isAssignableFrom(c2) : c2;
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/TemporalOperation.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/TemporalOperation.java
index ff6fa3905a..b2d440e06f 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/TemporalOperation.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/TemporalOperation.java
@@ -650,6 +650,7 @@ abstract class TemporalOperation<T> implements Serializable 
{
     /**
      * The {@code "During"} operation. Defined by ISO 19108 as:
      * <ul>
+     *   <li>{@literal self > other.begin  AND  self < other.end}</li>
      *   <li>{@literal self.begin > other.begin  AND  self.end < 
other.end}</li>
      * </ul>
      *
@@ -674,6 +675,12 @@ abstract class TemporalOperation<T> implements 
Serializable {
             return '⊊';         // `self` is a proper (or strict) subset of 
`other`.
         }
 
+        /** Condition defined by ISO 19108:2006 (corrigendum) §5.2.3.5. */
+        @Override public boolean evaluate(final T self, final Period other) {
+            return compare(TimeMethods.Test.AFTER,  self, 
other.getBeginning()) &&
+                   compare(TimeMethods.Test.BEFORE, self, other.getEnding());
+        }
+
         /** Condition defined by ISO 19108:2006 (corrigendum) §5.2.3.5. */
         @Override public boolean evaluate(final Period self, final Period 
other) {
             return compare(TimeMethods.Test.AFTER,  self.getBeginning(), 
other.getBeginning()) &&
@@ -793,6 +800,8 @@ abstract class TemporalOperation<T> implements Serializable 
{
     /**
      * The {@code "AnyInteracts"} filter.
      * This is a shortcut for NOT (Before OR Meets OR MetBy OR After).
+     * An instant is handled as a tiny period, so an instant interacts with a 
period
+     * if it is after the period beginning and before the period ending.
      *
      * @param  <T>  the base type of temporal objects.
      */
@@ -810,6 +819,18 @@ abstract class TemporalOperation<T> implements 
Serializable {
             return TemporalOperatorName.ANY_INTERACTS;
         }
 
+        /** Extension to ISO 19108: handle instant as a tiny period. */
+        @Override public boolean evaluate(final T self, final Period other) {
+            return compare(TimeMethods.Test.AFTER,  self, 
other.getBeginning()) &&
+                   compare(TimeMethods.Test.BEFORE, self, other.getEnding());
+        }
+
+        /** Extension to ISO 19108: handle instant as a tiny period. */
+        @Override public boolean evaluate(final Period self, final T other) {
+            return compare(TimeMethods.Test.AFTER,  other, 
self.getBeginning()) &&
+                   compare(TimeMethods.Test.BEFORE, other, self.getEnding());
+        }
+
         /** Condition defined by OGC filter specification. */
         @Override public boolean evaluate(final Period self, final Period 
other) {
             final Instant selfBegin, selfEnd, otherBegin, otherEnd;
diff --git 
a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/filter/TemporalFilterTest.java
 
b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/filter/TemporalFilterTest.java
index 3a9ec8cf7c..ca506b72f3 100644
--- 
a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/filter/TemporalFilterTest.java
+++ 
b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/filter/TemporalFilterTest.java
@@ -18,6 +18,7 @@ package org.apache.sis.filter;
 
 import java.time.Instant;
 import org.apache.sis.geometry.WraparoundMethod;
+import org.apache.sis.temporal.TemporalObjects;
 import static 
org.apache.sis.util.internal.shared.Constants.MILLISECONDS_PER_DAY;
 
 // Test dependencies
@@ -359,4 +360,37 @@ public final class TemporalFilterTest extends TestCase {
         factory = new DefaultFilterFactory.Features<>(Object.class, 
Period.class, WraparoundMethod.NONE);
         testAfter();
     }
+
+    /**
+     * Tests filters between two period literals.
+     * The period class used by the literals is final and has no natural 
ordering.
+     */
+    @Test
+    public void testPeriodLiterals() {
+        final FilterFactory<Feature,Object,Object> ff = 
DefaultFilterFactory.forFeatures();
+        final Period inner = 
TemporalObjects.createPeriod(Instant.parse("2000-01-02T00:00:00Z"), 
Instant.parse("2000-01-03T00:00:00Z"));
+        final Period outer = 
TemporalObjects.createPeriod(Instant.parse("2000-01-01T00:00:00Z"), 
Instant.parse("2000-01-05T00:00:00Z"));
+        assertTrue (ff.during      (ff.literal(inner), 
ff.literal(outer)).test(null));
+        assertFalse(ff.during      (ff.literal(outer), 
ff.literal(inner)).test(null));
+        assertTrue (ff.anyInteracts(ff.literal(inner), 
ff.literal(outer)).test(null));
+    }
+
+    /**
+     * Tests "During" and "AnyInteracts" between an instant and a period.
+     */
+    @Test
+    public void testInstantAndPeriod() {
+        final FilterFactory<Feature,Object,Object> ff = 
DefaultFilterFactory.forFeatures();
+        final Period period = 
TemporalObjects.createPeriod(Instant.parse("2000-01-01T00:00:00Z"), 
Instant.parse("2000-01-05T00:00:00Z"));
+        final Instant inside  = Instant.parse("2000-01-03T00:00:00Z");
+        final Instant outside = Instant.parse("2000-01-07T00:00:00Z");
+        final Instant start   = Instant.parse("2000-01-01T00:00:00Z");
+        assertTrue (ff.during      (ff.literal(inside),  
ff.literal(period)).test(null));
+        assertFalse(ff.during      (ff.literal(outside), 
ff.literal(period)).test(null));
+        assertFalse(ff.during      (ff.literal(start),   
ff.literal(period)).test(null), "Boundaries are excluded.");
+        assertTrue (ff.anyInteracts(ff.literal(inside),  
ff.literal(period)).test(null));
+        assertTrue (ff.anyInteracts(ff.literal(period),  
ff.literal(inside)).test(null));
+        assertFalse(ff.anyInteracts(ff.literal(outside), 
ff.literal(period)).test(null));
+        assertFalse(ff.anyInteracts(ff.literal(start),   
ff.literal(period)).test(null), "Meets is not an interaction.");
+    }
 }

Reply via email to