You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ma...@apache.org on 2002/03/19 02:33:12 UTC
cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections TestArrayIterator.java
mas 02/03/18 17:33:12
Modified: collections/src/java/org/apache/commons/collections
ArrayIterator.java
collections/src/test/org/apache/commons/collections
TestArrayIterator.java
Log:
Documentation updates and new test case for specifying null to the
ArrayIterator constructor or the setArray(Object) method.
Revision Changes Path
1.12 +57 -9 jakarta-commons/collections/src/java/org/apache/commons/collections/ArrayIterator.java
Index: ArrayIterator.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/ArrayIterator.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ArrayIterator.java 19 Mar 2002 00:54:34 -0000 1.11
+++ ArrayIterator.java 19 Mar 2002 01:33:12 -0000 1.12
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/ArrayIterator.java,v 1.11 2002/03/19 00:54:34 mas Exp $
- * $Revision: 1.11 $
- * $Date: 2002/03/19 00:54:34 $
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/ArrayIterator.java,v 1.12 2002/03/19 01:33:12 mas Exp $
+ * $Revision: 1.12 $
+ * $Date: 2002/03/19 01:33:12 $
*
* ====================================================================
*
@@ -64,12 +64,12 @@
import java.util.Iterator;
import java.util.NoSuchElementException;
-/** Implements {@link Iterator} over an array of objects
+/** Implements an {@link Iterator} over an array of objects.
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @author Mauricio S. Moura
* @author <a href="mailto:mas@apache.org">Michael A. Smith</a>
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
*/
public class ArrayIterator implements Iterator {
@@ -78,9 +78,26 @@
private int index = 0;
+ /**
+ * Construct an ArrayIterator. Using this constructor, the iterator is
+ * equivalent to an empty iterator until {@link #setArray(Object)} is
+ * called to establish the array to iterate over.
+ **/
public ArrayIterator() {
}
-
+
+ /**
+ * Construct an ArrayIterator that will iterate over the values in the
+ * specified array.
+ *
+ * @param array the array to iterate over.
+ *
+ * @exception IllegalArgumentException if <code>array</code> is not an
+ * array.
+ *
+ * @exception NullPointerException
+ * if <code>array</code> is <code>null</code>
+ **/
public ArrayIterator(Object array) {
setArray( array );
}
@@ -104,19 +121,50 @@
// Properties
//-------------------------------------------------------------------------
+
+ /**
+ * Retrieves the array that this iterator is iterating over.
+ *
+ * @return the array this iterator iterates over, or <code>null</code> if
+ * the no-arg constructor was used and {@link #setArray(Object)} has never
+ * been called with a valid array.
+ **/
public Object getArray() {
return array;
}
/**
+ * Changes the array that the ArrayIterator should iterate over. If an
+ * array has previously been set (using the single-arg constructor or this
+ * method), that array along with the current iterator position within
+ * that array is discarded in favor of the argument to this method. This
+ * method can be used in combination with {@link #getArray()} to "reset"
+ * the iterator to the beginning of the array:
+ *
+ * <pre>
+ * ArrayIterator iterator = ...
+ * ...
+ * iterator.setArray(iterator.getArray());
+ * </pre>
+ *
+ * Note: Using i.setArray(i.getArray()) may throw a NullPointerException
+ * if no array has ever been set for the iterator (see {@link
+ * #getArray()})
+ *
+ * @param array the array that the iterator should iterate over.
+ *
* @exception IllegalArgumentException if <code>array</code> is not an
* array.
+ *
+ * @exception NullPointerException
+ * if <code>array</code> is <code>null</code>
**/
public void setArray( Object array ) {
// Array.getLength throws IllegalArgumentException if the object is not
- // an array. This call is made before saving the array and resetting
- // the index so that the array iterator remains in a consistent state
- // if the argument is not an array.
+ // an array or NullPointerException if the object is null. This call
+ // is made before saving the array and resetting the index so that the
+ // array iterator remains in a consistent state if the argument is not
+ // an array or is null.
this.length = Array.getLength( array );
this.array = array;
this.index = 0;
1.7 +15 -4 jakarta-commons/collections/src/test/org/apache/commons/collections/TestArrayIterator.java
Index: TestArrayIterator.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestArrayIterator.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TestArrayIterator.java 25 Feb 2002 22:48:52 -0000 1.6
+++ TestArrayIterator.java 19 Mar 2002 01:33:12 -0000 1.7
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestArrayIterator.java,v 1.6 2002/02/25 22:48:52 morgand Exp $
- * $Revision: 1.6 $
- * $Date: 2002/02/25 22:48:52 $
+ * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestArrayIterator.java,v 1.7 2002/03/19 01:33:12 mas Exp $
+ * $Revision: 1.7 $
+ * $Date: 2002/03/19 01:33:12 $
*
* ====================================================================
*
@@ -73,7 +73,7 @@
* @author James Strachan
* @author Mauricio S. Moura
* @author Morgan Delagrange
- * @version $Id: TestArrayIterator.java,v 1.6 2002/02/25 22:48:52 morgand Exp $
+ * @version $Id: TestArrayIterator.java,v 1.7 2002/03/19 01:33:12 mas Exp $
*/
public class TestArrayIterator extends TestIterator {
@@ -121,6 +121,17 @@
assertTrue("NoSuchElementException must be thrown",
e.getClass().equals((new NoSuchElementException()).getClass()));
}
+ }
+
+ public void testNullToConstructor() {
+ try {
+ Iterator iter = new ArrayIterator(null);
+
+ fail("Constructor should throw a NullPointerException when " +
+ "constructed with a null array");
+ } catch (NullPointerException e) {
+ // expected
+ }
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>