sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1443115 - /sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Range.java
Date Wed, 06 Feb 2013 18:27:53 GMT
Author: desruisseaux
Date: Wed Feb  6 18:27:53 2013
New Revision: 1443115

URL: http://svn.apache.org/viewvc?rev=1443115&view=rev
Log:
Moved isEmpty() just below the getters for min/max values, because is provides an information
derived from those values.
Added a check for unbounded values, and added javadoc.

Modified:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Range.java

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Range.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Range.java?rev=1443115&r1=1443114&r2=1443115&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Range.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Range.java Wed Feb
 6 18:27:53 2013
@@ -159,6 +159,26 @@ public class Range<T extends Comparable<
         return isMaxIncluded;
     }
 
+    /**
+     * Returns {@code true} if this range is empty. A range is empty if the
+     * {@linkplain #getMinValue() minimum value} is smaller than the
+     * {@linkplain #getMaxValue() maximum value}, or if they are equal while
+     * at least one of them is exclusive.
+     *
+     * @return {@code true} if this range is empty.
+     */
+    public boolean isEmpty() {
+        if (minValue == null || maxValue == null) {
+            return false; // Unbounded: can't be empty.
+        }
+        final int c = minValue.compareTo(maxValue);
+        if (c < 0) {
+            return false; // Minimum is smaller than maximum.
+        }
+        // If min and max are equal, then the range is empty if at least one of them is exclusive.
+        return (c != 0) || !isMinIncluded || !isMaxIncluded;
+    }
+
     public boolean contains(final T value) throws IllegalArgumentException
     {
 
@@ -368,26 +388,6 @@ public class Range<T extends Comparable<
         return ranges;
     }
 
-    public boolean isEmpty()
-    {
-        if (isMinIncluded && isMaxIncluded)
-        {
-            if (minValue.compareTo(maxValue) > 0)
-            {
-                return true;
-            }
-        }
-        else
-        {
-            if (minValue.compareTo(maxValue) >= 0)
-            {
-                return true;
-            }
-
-        }
-        return false;
-    }
-
     @Override
     public boolean equals(Object object)
     {



Mime
View raw message