commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r638693 - in /commons/proper/collections/trunk/src: java/org/apache/commons/collections/iterators/CollatingIterator.java test/org/apache/commons/collections/iterators/TestCollatingIterator.java
Date Wed, 19 Mar 2008 03:43:21 GMT
Author: bayard
Date: Tue Mar 18 20:43:19 2008
New Revision: 638693

URL: http://svn.apache.org/viewvc?rev=638693&view=rev
Log:
Applying Fredrik Kjellberg's patch that adds getIteratorIndex() as per COLLECTIONS-289

Modified:
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/CollatingIterator.java
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestCollatingIterator.java

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/CollatingIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/CollatingIterator.java?rev=638693&r1=638692&r2=638693&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/CollatingIterator.java
(original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/CollatingIterator.java
Tue Mar 18 20:43:19 2008
@@ -253,6 +253,20 @@
         it.remove();
     }
 
+    /**
+     * Returns the index of the iterator that returned the last element.
+     * 
+     * @return the index of the iterator that returned the last element
+     * @throws IllegalStateException if there is no last returned element
+     */
+    public int getIteratorIndex() {
+        if (lastReturned == -1) {
+            throw new IllegalStateException("No value has been returned yet");
+        }
+        
+        return lastReturned;
+    }
+    
     // Private Methods
     // -------------------------------------------------------------------
     /** 

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestCollatingIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestCollatingIterator.java?rev=638693&r1=638692&r2=638693&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestCollatingIterator.java
(original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestCollatingIterator.java
Tue Mar 18 20:43:19 2008
@@ -104,6 +104,7 @@
         for(int i=0;i<evens.size();i++) {
             assertTrue(iter.hasNext());
             assertEquals(evens.get(i),iter.next());
+            assertEquals(0,iter.getIteratorIndex());
         }
         assertTrue(!iter.hasNext());
     }
@@ -113,6 +114,7 @@
         for(int i=0;i<20;i++) {
             assertTrue(iter.hasNext());
             assertEquals(new Integer(i),iter.next());
+            assertEquals(i % 2,iter.getIteratorIndex());
         }
         assertTrue(!iter.hasNext());
     }
@@ -122,6 +124,7 @@
         for(int i=0;i<20;i++) {
             assertTrue(iter.hasNext());
             assertEquals(new Integer(i),iter.next());
+            assertEquals((i % 2) == 0 ? 1 : 0,iter.getIteratorIndex());
         }
         assertTrue(!iter.hasNext());
     }
@@ -133,8 +136,10 @@
         for(int i=0;i<evens.size();i++) {
             assertTrue(iter.hasNext());
             assertEquals(evens.get(i),iter.next());
+            assertEquals(0,iter.getIteratorIndex());
             assertTrue(iter.hasNext());
             assertEquals(evens.get(i),iter.next());
+            assertEquals(1,iter.getIteratorIndex());
         }
         assertTrue(!iter.hasNext());
     }
@@ -147,33 +152,61 @@
         iter.addIterator(odds.iterator());
         
         assertEquals(new Integer(0),iter.next());  // even   0
+        assertEquals(1,iter.getIteratorIndex());
         assertEquals(new Integer(1),iter.next());  // fib    1
+        assertEquals(0,iter.getIteratorIndex());
         assertEquals(new Integer(1),iter.next());  // fib    1
+        assertEquals(0,iter.getIteratorIndex());
         assertEquals(new Integer(1),iter.next());  // odd    1
+        assertEquals(2,iter.getIteratorIndex());
         assertEquals(new Integer(2),iter.next());  // fib    2
+        assertEquals(0,iter.getIteratorIndex());
         assertEquals(new Integer(2),iter.next());  // even   2
+        assertEquals(1,iter.getIteratorIndex());
         assertEquals(new Integer(3),iter.next());  // fib    3
+        assertEquals(0,iter.getIteratorIndex());
         assertEquals(new Integer(3),iter.next());  // odd    3
+        assertEquals(2,iter.getIteratorIndex());
         assertEquals(new Integer(4),iter.next());  // even   4
+        assertEquals(1,iter.getIteratorIndex());
         assertEquals(new Integer(5),iter.next());  // fib    5
+        assertEquals(0,iter.getIteratorIndex());
         assertEquals(new Integer(5),iter.next());  // odd    5
+        assertEquals(2,iter.getIteratorIndex());
         assertEquals(new Integer(6),iter.next());  // even   6
+        assertEquals(1,iter.getIteratorIndex());
         assertEquals(new Integer(7),iter.next());  // odd    7
+        assertEquals(2,iter.getIteratorIndex());
         assertEquals(new Integer(8),iter.next());  // fib    8
+        assertEquals(0,iter.getIteratorIndex());
         assertEquals(new Integer(8),iter.next());  // even   8
+        assertEquals(1,iter.getIteratorIndex());
         assertEquals(new Integer(9),iter.next());  // odd    9
+        assertEquals(2,iter.getIteratorIndex());
         assertEquals(new Integer(10),iter.next()); // even  10
+        assertEquals(1,iter.getIteratorIndex());
         assertEquals(new Integer(11),iter.next()); // odd   11
+        assertEquals(2,iter.getIteratorIndex());
         assertEquals(new Integer(12),iter.next()); // even  12
+        assertEquals(1,iter.getIteratorIndex());
         assertEquals(new Integer(13),iter.next()); // fib   13
+        assertEquals(0,iter.getIteratorIndex());
         assertEquals(new Integer(13),iter.next()); // odd   13
+        assertEquals(2,iter.getIteratorIndex());
         assertEquals(new Integer(14),iter.next()); // even  14
+        assertEquals(1,iter.getIteratorIndex());
         assertEquals(new Integer(15),iter.next()); // odd   15
+        assertEquals(2,iter.getIteratorIndex());
         assertEquals(new Integer(16),iter.next()); // even  16
+        assertEquals(1,iter.getIteratorIndex());
         assertEquals(new Integer(17),iter.next()); // odd   17
+        assertEquals(2,iter.getIteratorIndex());
         assertEquals(new Integer(18),iter.next()); // even  18
+        assertEquals(1,iter.getIteratorIndex());
         assertEquals(new Integer(19),iter.next()); // odd   19
+        assertEquals(2,iter.getIteratorIndex());
         assertEquals(new Integer(21),iter.next()); // fib   21
+        assertEquals(0,iter.getIteratorIndex());
 
         assertTrue(!iter.hasNext());
     }



Mime
View raw message