sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1704738 - in /sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure: NumberRange.java Range.java
Date Tue, 22 Sep 2015 21:58:56 GMT
Author: desruisseaux
Date: Tue Sep 22 21:58:54 2015
New Revision: 1704738

URL: http://svn.apache.org/viewvc?rev=1704738&view=rev
Log:
Bug fix: do not cache empty ranges.

Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java?rev=1704738&r1=1704737&r2=1704738&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java
[UTF-8] Tue Sep 22 21:58:54 2015
@@ -101,10 +101,19 @@ public class NumberRange<E extends Numbe
     private static final WeakHashSet<NumberRange<?>> POOL = new WeakHashSet<>((Class)
NumberRange.class);
 
     /**
-     * Returns a unique instance of the given range.
+     * Returns a unique instance of the given range, except if the range is empty.
+     *
+     * <div class="note"><b>Rational:</b>
+     * we exclude empty ranges because the {@link Range#equals(Object)} consider them as
equal.
+     * Consequently if empty ranges were included in the pool, this method would return in
some
+     * occasions an empty range with different values than the given {@code range} argument.
+     * </div>
      */
-    static <E extends Number & Comparable<? super E>, T extends NumberRange<E>>
T unique(final T range) {
-        return POOL.unique(range);
+    static <E extends Number & Comparable<? super E>, T extends NumberRange<E>>
T unique(T range) {
+        if (!range.isEmpty()) {
+            range = POOL.unique(range);
+        }
+        return range;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java?rev=1704738&r1=1704737&r2=1704738&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java [UTF-8]
Tue Sep 22 21:58:54 2015
@@ -277,7 +277,7 @@ public class Range<E extends Comparable<
     @Override
     public final boolean isEmpty() {
         if (minValue == null || maxValue == null) {
-            return false; // Unbounded: can't be empty.
+            return false; // Unbounded: can not be empty.
         }
         final int c = minValue.compareTo(maxValue);
         if (c < 0) {
@@ -561,6 +561,15 @@ public class Range<E extends Comparable<
 
     /**
      * Compares this range with the given object for equality.
+     * Two ranges are considered equal if they have the same {@link #getElementType() element
type} and:
+     *
+     * <ul>
+     *   <li>are both {@linkplain #isEmpty() empty}, or</li>
+     *   <li>have equal {@linkplain #getMinValue() minimum} and {@linkplain #getMaxValue()
maximum} values
+     *       with equal inclusive/exclusive flags.</li>
+     * </ul>
+     *
+     * Note that subclasses may add other requirements, for example on units of measurement.
      *
      * @param  object The object to compare with this range for equality.
      * @return {@code true} if the given object is equal to this range.



Mime
View raw message