commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r594388 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/math/ test/org/apache/commons/lang/math/
Date Tue, 13 Nov 2007 01:29:11 GMT
Author: bayard
Date: Mon Nov 12 17:29:10 2007
New Revision: 594388

URL: http://svn.apache.org/viewvc?rev=594388&view=rev
Log:
Applying Ben's patch of Brian Egge's improvement in LANG-321

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/math/IntRange.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/math/LongRange.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/IntRangeTest.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/LongRangeTest.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/math/IntRange.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/math/IntRange.java?rev=594388&r1=594387&r2=594388&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/math/IntRange.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/math/IntRange.java Mon Nov
12 17:29:10 2007
@@ -381,4 +381,17 @@
         return toString;
     }
 
+    /**
+     * <p>Returns an array containing all the integer values in the range.</p>
+     *
+     * @return the <code>int[]</code> representation of this range
+     */
+    public int[] toArray() {
+        int[] array = new int[max - min + 1];
+        for (int i = 0; i < array.length; i++) {
+            array[i] = min + i;
+        }
+
+        return array;
+    }
 }

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/math/LongRange.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/math/LongRange.java?rev=594388&r1=594387&r2=594388&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/math/LongRange.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/math/LongRange.java Mon Nov
12 17:29:10 2007
@@ -394,4 +394,17 @@
         return toString;
     }
 
+    /**
+     * <p>Returns an array containing all the long values in the range.</p>
+     *
+     * @return the <code>long[]</code> representation of this range
+     */
+    public long[] toArray() {
+        long[] array = new long[(int)(max - min + 1L)];
+        for(int i = 0; i < array.length; i++) {
+            array[i] = min + i;
+        }
+        return array;
+    }
+
 }

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/IntRangeTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/IntRangeTest.java?rev=594388&r1=594387&r2=594388&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/IntRangeTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/IntRangeTest.java Mon
Nov 12 17:29:10 2007
@@ -21,6 +21,8 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import java.util.Arrays;
+
 /**
  * Test cases for the {@link IntRange} class.
  *
@@ -158,6 +160,13 @@
         IntRange big = new IntRange(Integer.MAX_VALUE, Integer.MAX_VALUE- 2);
         assertEquals(true, big.containsInteger(Integer.MAX_VALUE - 1));
         assertEquals(false, big.containsInteger(Integer.MAX_VALUE - 3));
+    }
+
+    public void testToArray() {
+        int[] threeItems = new IntRange(3, 5).toArray();
+        assertTrue(Arrays.equals(new int[]{3, 4, 5}, threeItems));
+        int[] oneItem = new IntRange(4).toArray();
+        assertTrue(Arrays.equals(new int[]{4}, oneItem));
     }
 
     //--------------------------------------------------------------------------

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/LongRangeTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/LongRangeTest.java?rev=594388&r1=594387&r2=594388&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/LongRangeTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/LongRangeTest.java Mon
Nov 12 17:29:10 2007
@@ -21,6 +21,8 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import java.util.Arrays;
+
 /**
  * Test cases for the {@link LongRange} class.
  *
@@ -146,6 +148,13 @@
         LongRange big = new LongRange(Long.MAX_VALUE, Long.MAX_VALUE- 2);
         assertEquals(true, big.containsLong(Long.MAX_VALUE - 1));
         assertEquals(false, big.containsLong(Long.MAX_VALUE - 3));
+    }
+
+    public void testToArray() {
+        long[] threeItems = new LongRange(3, 5).toArray();
+        assertTrue(Arrays.equals(new long[]{3, 4, 5}, threeItems));
+        long[] oneItem = new LongRange(4).toArray();
+        assertTrue(Arrays.equals(new long[]{4}, oneItem));
     }
 
     //--------------------------------------------------------------------------



Mime
View raw message