commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r833337 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/Range.java test/org/apache/commons/lang/RangeTest.java
Date Fri, 06 Nov 2009 10:47:16 GMT
Author: bayard
Date: Fri Nov  6 10:47:15 2009
New Revision: 833337

URL: http://svn.apache.org/viewvc?rev=833337&view=rev
Log:
Added test for contains method, along with a null fix for contains and improved javadoc -
LANG-551

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/Range.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/RangeTest.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/Range.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/Range.java?rev=833337&r1=833336&r2=833337&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/Range.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/Range.java Fri Nov  6 10:47:15
2009
@@ -154,22 +154,19 @@
     //--------------------------------------------------------------------
     
     /**
-     * <p>Tests whether the specified <code>Number</code> occurs within
-     * this range.</p>
-     * 
-     * <p>The exact comparison implementation varies by subclass. It is
-     * intended that an <code>int</code> specific subclass will compare using
-     * <code>int</code> comparison.</p>
+     * <p>Tests whether the specified element occurs within this range.</p>
      * 
      * <p><code>null</code> is handled and returns <code>false</code>.</p>
      *
-     * @param number  the number to test, may be <code>null</code>
-     * @return <code>true</code> if the specified number occurs within this range
+     * @param element  the element to test, may be <code>null</code>
+     * @return <code>true</code> if the specified element occurs within this
range
      * @throws IllegalArgumentException if the <code>Number</code> cannot be
compared
      */
-    public boolean contains(T t) {
-// TODO: Rewrite in terms of !lessThan and !greaterThan?
-        return (comparator.compare(t, getMinimum()) > -1) && (comparator.compare(t,
getMaximum()) < 1);
+    public boolean contains(T element) {
+        if(element == null) {
+            return false;
+        }
+        return (comparator.compare(element, getMinimum()) > -1) && (comparator.compare(element,
getMaximum()) < 1);
     }
 
     public boolean lessThan(T element) {
@@ -177,7 +174,7 @@
             return false;
         }
         
-        return this.comparator.compare(this.getMinimum(), element) < 1;
+        return this.comparator.compare(getMinimum(), element) < 1;
     }
 
     public boolean greaterThan(T element) {

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/RangeTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/RangeTest.java?rev=833337&r1=833336&r2=833337&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/RangeTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/RangeTest.java Fri Nov  6 10:47:15
2009
@@ -95,4 +95,15 @@
         assertEquals(20f, floatRange.getMaximum(), 0.00001f);
         assertEquals(20d, doubleRange.getMaximum(), 0.00001d);
     }
+
+    public void testContains() {
+        assertFalse(intRange.contains(null));
+        
+        assertFalse(intRange.contains(5));
+        assertTrue(intRange.contains(10));
+        assertTrue(intRange.contains(15));
+        assertTrue(intRange.contains(20));
+        assertFalse(intRange.contains(25));
+    }
+
 }



Mime
View raw message