From cfe724a9007adac4d204ba50f41faacc885ee610 Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Wed, 19 Mar 2008 03:43:19 +0000 Subject: [PATCH] Applying Fredrik Kjellberg's patch that adds getIteratorIndex() as per COLLECTIONS-289 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@638693 13f79535-47bb-0310-9956-ffa450edef68 --- .../iterators/CollatingIterator.java | 14 ++++++++ .../iterators/TestCollatingIterator.java | 33 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/java/org/apache/commons/collections/iterators/CollatingIterator.java b/src/java/org/apache/commons/collections/iterators/CollatingIterator.java index 44513194a..2aa905781 100644 --- a/src/java/org/apache/commons/collections/iterators/CollatingIterator.java +++ b/src/java/org/apache/commons/collections/iterators/CollatingIterator.java @@ -253,6 +253,20 @@ public class CollatingIterator implements Iterator { 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 // ------------------------------------------------------------------- /** diff --git a/src/test/org/apache/commons/collections/iterators/TestCollatingIterator.java b/src/test/org/apache/commons/collections/iterators/TestCollatingIterator.java index b844a7d15..2453edfb5 100644 --- a/src/test/org/apache/commons/collections/iterators/TestCollatingIterator.java +++ b/src/test/org/apache/commons/collections/iterators/TestCollatingIterator.java @@ -104,6 +104,7 @@ public class TestCollatingIterator extends AbstractTestIterator { for(int i=0;i