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 65deba1d23660cbdf0b6808d8a4c615db16ff2f5
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Wed Apr 22 17:49:01 2020 +0200

    Change `GeneralEnvelope.setTimeRange(…)` contract regarding null values in 
a way more convenient for creating "is before" and "is after" filters.
    Add some documentation.
---
 .../org/apache/sis/geometry/GeneralEnvelope.java   | 23 +++++++++++++++-------
 .../sis/util/collection/FrequencySortedSet.java    |  3 +++
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
 
b/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
index 6d7d026..fed4233 100644
--- 
a/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
+++ 
b/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
@@ -469,19 +469,28 @@ public class GeneralEnvelope extends ArrayEnvelope 
implements Cloneable, Seriali
      * floating point values using {@link 
org.apache.sis.referencing.crs.DefaultTemporalCRS},
      * then delegates to {@link #setRange(int, double, double)}.
      *
-     * Beware that any unspecified time will be convered to {@link Double#NaN} 
value, therefore invalidating the time
-     * range.
-     *
-     * @param  startTime  the lower temporal value, or {@code null} if 
unspecified.
-     * @param  endTime    the upper temporal value, or {@code null} if 
unspecified.
-     * @return whether the temporal component has been set.
+     * <p>Null value means no time limit. More specifically
+     * null {@code startTime} is mapped to {@linkplain 
Double#NEGATIVE_INFINITY −∞} and
+     * null {@code endTime}   is mapped to {@linkplain 
Double#POSITIVE_INFINITY +∞}.
+     * This rule makes easy to create <cite>is before</cite> or <cite>is 
after</cite> temporal filters,
+     * which can be combined with other envelopes using {@linkplain 
#intersect(Envelope) intersection}
+     * for logical AND, or {@linkplain #add(Envelope) union} for logical OR 
operations.</p>
+     *
+     * @param  startTime  the lower temporal value, or {@code null} if 
unbounded.
+     * @param  endTime    the upper temporal value, or {@code null} if 
unbounded.
+     * @return whether the temporal component has been set, or {@code false}
+     *         if no temporal dimension has been found in this envelope.
      *
      * @since 1.0
      */
     public boolean setTimeRange(final Instant startTime, final Instant 
endTime) {
         final TemporalAccessor t = TemporalAccessor.of(crs, 0);
         if (t != null) {
-            setRange(t.dimension, t.timeCRS.toValue(startTime), 
t.timeCRS.toValue(endTime));
+            double lower = t.timeCRS.toValue(startTime);
+            double upper = t.timeCRS.toValue(endTime);
+            if (Double.isNaN(lower)) lower = Double.NEGATIVE_INFINITY;
+            if (Double.isNaN(upper)) upper = Double.POSITIVE_INFINITY;
+            setRange(t.dimension, lower, upper);
             return true;
         } else {
             return false;
diff --git 
a/core/sis-utility/src/main/java/org/apache/sis/util/collection/FrequencySortedSet.java
 
b/core/sis-utility/src/main/java/org/apache/sis/util/collection/FrequencySortedSet.java
index 3396c34..b75137e 100644
--- 
a/core/sis-utility/src/main/java/org/apache/sis/util/collection/FrequencySortedSet.java
+++ 
b/core/sis-utility/src/main/java/org/apache/sis/util/collection/FrequencySortedSet.java
@@ -60,6 +60,8 @@ public class FrequencySortedSet<E> extends AbstractSet<E> 
implements SortedSet<E
     /**
      * The frequency of occurrence for each element. We must use a linked hash 
map instead of an ordinary
      * hash map because we want to preserve insertion order for elements that 
occur at the same frequency.
+     * Values are positives if this set sorts by increasing frequencies, or 
negatives if this set sorts by
+     * decreasing frequencies.
      */
     private final Map<E,Integer> count;
 
@@ -153,6 +155,7 @@ public class FrequencySortedSet<E> extends AbstractSet<E> 
implements SortedSet<E
             sorted = null;
             occurrence ^= order;
             return count.merge(element, occurrence, (old, n) -> 
Math.addExact(old, n) - order) == occurrence;
+            // Note: the subtraction by `order` can not overflow.
         }
         return false;
     }

Reply via email to