ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1387532 - in /ace/trunk/org.apache.ace.range.api: src/org/apache/ace/range/SortedRangeSet.java test/org/apache/ace/range/SortedRangeSetTest.java
Date Wed, 19 Sep 2012 11:48:08 GMT
Author: marrs
Date: Wed Sep 19 11:48:07 2012
New Revision: 1387532

URL: http://svn.apache.org/viewvc?rev=1387532&view=rev
Log:
ACE-293 Added the suggested method plus some test cases to validate its workings.

Modified:
    ace/trunk/org.apache.ace.range.api/src/org/apache/ace/range/SortedRangeSet.java
    ace/trunk/org.apache.ace.range.api/test/org/apache/ace/range/SortedRangeSetTest.java

Modified: ace/trunk/org.apache.ace.range.api/src/org/apache/ace/range/SortedRangeSet.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.range.api/src/org/apache/ace/range/SortedRangeSet.java?rev=1387532&r1=1387531&r2=1387532&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.range.api/src/org/apache/ace/range/SortedRangeSet.java (original)
+++ ace/trunk/org.apache.ace.range.api/src/org/apache/ace/range/SortedRangeSet.java Wed Sep
19 11:48:07 2012
@@ -189,6 +189,15 @@ public class SortedRangeSet
     public RangeIterator iterator() {
         return new RangeIterator(m_ranges.iterator());
     }
+    
+    /**
+     * Returns an iterator that iterates over all the <code>Range</code> instances
in this set.
+     * 
+     * @return an iterator of <code>Range</code> objects
+     */
+    public Iterator rangeIterator() {
+        return m_ranges.iterator();
+    }
 
     /**
      * Returns the highest value present in any of the ranges in this <code>SortredRangeSet</code>.

Modified: ace/trunk/org.apache.ace.range.api/test/org/apache/ace/range/SortedRangeSetTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.range.api/test/org/apache/ace/range/SortedRangeSetTest.java?rev=1387532&r1=1387531&r2=1387532&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.range.api/test/org/apache/ace/range/SortedRangeSetTest.java (original)
+++ ace/trunk/org.apache.ace.range.api/test/org/apache/ace/range/SortedRangeSetTest.java Wed
Sep 19 11:48:07 2012
@@ -20,9 +20,8 @@ package org.apache.ace.range;
 
 import static org.apache.ace.test.utils.TestUtils.UNIT;
 
-import org.apache.ace.range.Range;
-import org.apache.ace.range.RangeIterator;
-import org.apache.ace.range.SortedRangeSet;
+import java.util.Iterator;
+
 import org.testng.annotations.Test;
 
 public class SortedRangeSetTest {
@@ -70,6 +69,23 @@ public class SortedRangeSetTest {
         assert new SortedRangeSet(new long[] {1,3,5,7,9}).diffDest(new SortedRangeSet("1-10")).toRepresentation().equals("2,4,6,8,10")
: "Result of diff should be 2,4,6,8,10";
         assert new SortedRangeSet("1-5,8,12").diffDest(new SortedRangeSet("1-5,7,9,12,20")).toRepresentation().equals("7,9,20")
: "Result of diff should be 7,9,20";
     }
+    
+    @Test(groups = { UNIT })
+    public void validateRangeIterators() {
+        SortedRangeSet srs1 = new SortedRangeSet("1-10");
+        Iterator i1 = srs1.rangeIterator();
+        assert i1.hasNext() : "We should have one Range instance in our iterator.";
+        assert ((Range) i1.next()).toRepresentation().equals("1-10");
+        assert !i1.hasNext() : "There should be only one instance in our iterator.";
+        SortedRangeSet srs2 = new SortedRangeSet("1-5,8,10-15");
+        Iterator i2 = srs2.rangeIterator();
+        assert i2.hasNext() && i2.next() instanceof Range
+            && i2.hasNext() && i2.next() instanceof Range
+            && i2.hasNext() && i2.next() instanceof Range
+            && !i2.hasNext() : "There should be exactly three Range instances in
our iterator.";
+        SortedRangeSet srs3 = new SortedRangeSet("");
+        assert !srs3.iterator().hasNext() : "Iterator should be empty.";
+    }
 
     @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
     public void invalidRange() {



Mime
View raw message