using the setArray(Object) method no longer produces an out of bounds

exception


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130654 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Morgan James Delagrange 2002-03-19 00:05:16 +00:00
parent 00be90bccc
commit 236ad31fbd
2 changed files with 34 additions and 9 deletions

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/Attic/ArrayIterator.java,v 1.9 2002/03/15 17:33:52 morgand Exp $
* $Revision: 1.9 $
* $Date: 2002/03/15 17:33:52 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/Attic/ArrayIterator.java,v 1.10 2002/03/19 00:05:10 morgand Exp $
* $Revision: 1.10 $
* $Date: 2002/03/19 00:05:10 $
*
* ====================================================================
*
@ -68,7 +68,7 @@ import java.util.NoSuchElementException;
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @author Mauricio S. Moura
* @version $Revision: 1.9 $
* @version $Revision: 1.10 $
*/
public class ArrayIterator implements Iterator {
@ -108,6 +108,6 @@ public class ArrayIterator implements Iterator {
public void setArray( Object array ) {
this.array = array;
this.index = -1;
this.index = 0;
}
}

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestArrayIterator2.java,v 1.2 2002/02/25 22:48:52 morgand Exp $
* $Revision: 1.2 $
* $Date: 2002/02/25 22:48:52 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestArrayIterator2.java,v 1.3 2002/03/19 00:05:16 morgand Exp $
* $Revision: 1.3 $
* $Date: 2002/03/19 00:05:16 $
*
* ====================================================================
*
@ -70,7 +70,7 @@ import java.util.NoSuchElementException;
*
* @author Morgan Delagrange
* @author James Strachan
* @version $Id: TestArrayIterator2.java,v 1.2 2002/02/25 22:48:52 morgand Exp $
* @version $Id: TestArrayIterator2.java,v 1.3 2002/03/19 00:05:16 morgand Exp $
*/
public class TestArrayIterator2 extends TestIterator {
@ -119,5 +119,30 @@ public class TestArrayIterator2 extends TestIterator {
e.getClass().equals((new NoSuchElementException()).getClass()));
}
}
// proves that an ArrayIterator set with the constructor has the same number of elements
// as an ArrayIterator set with setArray(Object)
public void testSetArray() {
Iterator iter1 = new ArrayIterator(testArray);
int count1 = 0;
while (iter1.hasNext()) {
++count1;
iter1.next();
}
assertEquals("the count should be right using the constructor",
count1,testArray.length);
ArrayIterator iter2 = new ArrayIterator();
iter2.setArray(testArray);
int count2 = 0;
while (iter2.hasNext()) {
++count2;
iter2.next();
}
assertEquals("the count should be right using setArray(Object)",
count2,testArray.length);
}
}