* allow zero as an initial capacity for the primitive array lists (once again). (java.util.ArrayList allows it, why shouldn't we?)

* add tests to enforce the contract


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130812 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Rodney Waldhoff 2002-09-07 20:33:32 +00:00
parent 034ec419ea
commit a47d25a4ff
14 changed files with 188 additions and 155 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/primitives/Attic/FloatArrayList.java,v 1.4 2002/08/23 17:31:28 pjack Exp $
* $Revision: 1.4 $
* $Date: 2002/08/23 17:31:28 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/FloatArrayList.java,v 1.5 2002/09/07 20:33:32 rwaldhoff Exp $
* $Revision: 1.5 $
* $Date: 2002/09/07 20:33:32 $
*
* ====================================================================
*
@ -78,7 +78,7 @@ import java.util.ListIterator;
* {@link java.util.ArrayList} of {@link Float} values and allows for
* better compile-time type checking.<P>
*
* @version $Revision: 1.4 $ $Date: 2002/08/23 17:31:28 $
* @version $Revision: 1.5 $ $Date: 2002/09/07 20:33:32 $
* @author Rodney Waldhoff
*/
public class FloatArrayList extends AbstractList implements List, Serializable {
@ -98,11 +98,10 @@ public class FloatArrayList extends AbstractList implements List, Serializable {
* capacity.
*
* @param capacity the initial capacity for the list
* @throws IllegalArgumentException if capacity is less than or equal
* to zero
* @throws IllegalArgumentException if capacity is less than zero
*/
public FloatArrayList(int capacity) {
if (capacity <= 0) {
if (capacity < 0) {
throw new IllegalArgumentException("capacity=" + capacity);
}
_data = new float[capacity];

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/primitives/Attic/IntArrayList.java,v 1.5 2002/08/22 01:50:54 pjack Exp $
* $Revision: 1.5 $
* $Date: 2002/08/22 01:50:54 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/IntArrayList.java,v 1.6 2002/09/07 20:33:32 rwaldhoff Exp $
* $Revision: 1.6 $
* $Date: 2002/09/07 20:33:32 $
*
* ====================================================================
*
@ -78,7 +78,7 @@ import java.util.ListIterator;
* {@link java.util.ArrayList} of {@link Integer} values and allows for
* better compile-time type checking.<P>
*
* @version $Revision: 1.5 $ $Date: 2002/08/22 01:50:54 $
* @version $Revision: 1.6 $ $Date: 2002/09/07 20:33:32 $
* @author Rodney Waldhoff
*/
public class IntArrayList extends AbstractIntArrayList implements Serializable {
@ -96,11 +96,10 @@ public class IntArrayList extends AbstractIntArrayList implements Serializable {
* Constructs a new <Code>IntArrayList</Code> with the given capacity.
*
* @param the capacity for the list
* @throws IllegalArgumentException if the capacity is less than or
* equal to zero
* @throws IllegalArgumentException if the capacity is less than zero
*/
public IntArrayList(int capacity) {
if (capacity <= 0) {
if (capacity < 0) {
throw new IllegalArgumentException("capacity " + capacity);
}
_data = new int[capacity];

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/primitives/Attic/LongArrayList.java,v 1.5 2002/08/22 01:50:54 pjack Exp $
* $Revision: 1.5 $
* $Date: 2002/08/22 01:50:54 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/LongArrayList.java,v 1.6 2002/09/07 20:33:32 rwaldhoff Exp $
* $Revision: 1.6 $
* $Date: 2002/09/07 20:33:32 $
*
* ====================================================================
*
@ -78,7 +78,7 @@ import java.util.ListIterator;
* {@link java.util.ArrayList} of {@link Long} values and allows for
* better compile-time type checking.<P>
*
* @version $Revision: 1.5 $ $Date: 2002/08/22 01:50:54 $
* @version $Revision: 1.6 $ $Date: 2002/09/07 20:33:32 $
* @author Rodney Waldhoff
*/
public class LongArrayList extends AbstractLongArrayList implements Serializable {
@ -98,11 +98,10 @@ public class LongArrayList extends AbstractLongArrayList implements Serializable
* capacity.
*
* @param capacity the initial capacity for the array
* @throws IllegalArgumentException if the capacity is less than or
* equal to zero
* @throws IllegalArgumentException if the capacity is less than zero
*/
public LongArrayList(int capacity) {
if (capacity <= 0) {
if (capacity < 0) {
throw new IllegalArgumentException("capacity=" + capacity);
}
_data = new long[capacity];

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/primitives/Attic/ShortArrayList.java,v 1.5 2002/08/22 01:50:54 pjack Exp $
* $Revision: 1.5 $
* $Date: 2002/08/22 01:50:54 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/ShortArrayList.java,v 1.6 2002/09/07 20:33:32 rwaldhoff Exp $
* $Revision: 1.6 $
* $Date: 2002/09/07 20:33:32 $
*
* ====================================================================
*
@ -78,7 +78,7 @@ import java.util.ListIterator;
* {@link java.util.ArrayList} of {@link Short} values and allows for
* better compile-time type checking.<P>
*
* @version $Revision: 1.5 $ $Date: 2002/08/22 01:50:54 $
* @version $Revision: 1.6 $ $Date: 2002/09/07 20:33:32 $
* @author Rodney Waldhoff
*/
public class ShortArrayList extends AbstractShortArrayList implements Serializable {
@ -98,11 +98,10 @@ public class ShortArrayList extends AbstractShortArrayList implements Serializab
* capacity.
*
* @param capacity the initial capacity for the array
* @throws IllegalArgumentException if the capacity is less than or
* equal to zero
* @throws IllegalArgumentException if the capacity is less than zero
*/
public ShortArrayList(int capacity) {
if (capacity <= 0) {
if (capacity < 0) {
throw new IllegalArgumentException("capacity=" + capacity);
}
_data = new short[capacity];

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/primitives/Attic/UnsignedByteArrayList.java,v 1.5 2002/08/22 01:50:54 pjack Exp $
* $Revision: 1.5 $
* $Date: 2002/08/22 01:50:54 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/UnsignedByteArrayList.java,v 1.6 2002/09/07 20:33:32 rwaldhoff Exp $
* $Revision: 1.6 $
* $Date: 2002/09/07 20:33:32 $
*
* ====================================================================
*
@ -80,7 +80,7 @@ import java.util.ListIterator;
* than a {@link java.util.ArrayList} and offers better compile-time type
* checking.
*
* @version $Revision: 1.5 $ $Date: 2002/08/22 01:50:54 $
* @version $Revision: 1.6 $ $Date: 2002/09/07 20:33:32 $
* @author Rodney Waldhoff
*/
public class UnsignedByteArrayList extends AbstractShortArrayList implements Serializable {
@ -100,11 +100,10 @@ public class UnsignedByteArrayList extends AbstractShortArrayList implements Ser
* specified initial capacity.
*
* @param capacity the capacity for this list
* @throws IllegalArgumentException if the given capacity is less than
* or equal to zero
* @throws IllegalArgumentException if the given capacity is less than zero
*/
public UnsignedByteArrayList(int capacity) {
if (capacity <= 0) {
if (capacity < 0) {
throw new IllegalArgumentException("capacity=" + capacity);
}
_data = new byte[capacity];

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/primitives/Attic/UnsignedIntArrayList.java,v 1.5 2002/08/22 01:50:54 pjack Exp $
* $Revision: 1.5 $
* $Date: 2002/08/22 01:50:54 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/UnsignedIntArrayList.java,v 1.6 2002/09/07 20:33:32 rwaldhoff Exp $
* $Revision: 1.6 $
* $Date: 2002/09/07 20:33:32 $
*
* ====================================================================
*
@ -80,7 +80,7 @@ import java.util.ListIterator;
* than a {@link java.util.ArrayList} and offers better compile-time type
* checking.
*
* @version $Revision: 1.5 $ $Date: 2002/08/22 01:50:54 $
* @version $Revision: 1.6 $ $Date: 2002/09/07 20:33:32 $
* @author Rodney Waldhoff
*/
public class UnsignedIntArrayList extends AbstractLongArrayList implements Serializable {
@ -100,11 +100,10 @@ public class UnsignedIntArrayList extends AbstractLongArrayList implements Seria
* specified initial capacity.
*
* @param capacity the capacity for this list
* @throws IllegalArgumentException if the given capacity is less than
* or equal to zero
* @throws IllegalArgumentException if the given capacity is less than zero
*/
public UnsignedIntArrayList(int capacity) {
if (capacity <= 0) {
if (capacity < 0) {
throw new IllegalArgumentException("capacity=" + capacity);
}
_data = new int[capacity];

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/primitives/Attic/UnsignedShortArrayList.java,v 1.5 2002/08/22 01:50:54 pjack Exp $
* $Revision: 1.5 $
* $Date: 2002/08/22 01:50:54 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/UnsignedShortArrayList.java,v 1.6 2002/09/07 20:33:32 rwaldhoff Exp $
* $Revision: 1.6 $
* $Date: 2002/09/07 20:33:32 $
*
* ====================================================================
*
@ -80,7 +80,7 @@ import java.util.ListIterator;
* than a {@link java.util.ArrayList} and offers better compile-time type
* checking.
*
* @version $Revision: 1.5 $ $Date: 2002/08/22 01:50:54 $
* @version $Revision: 1.6 $ $Date: 2002/09/07 20:33:32 $
* @author Rodney Waldhoff
*/
public class UnsignedShortArrayList extends AbstractIntArrayList implements Serializable {
@ -101,11 +101,10 @@ public class UnsignedShortArrayList extends AbstractIntArrayList implements Seri
* specified initial capacity.
*
* @param capacity the capacity for this list
* @throws IllegalArgumentException if the given capacity is less than
* or equal to zero
* @throws IllegalArgumentException if the given capacity is less than zero
*/
public UnsignedShortArrayList(int capacity) {
if (capacity <= 0) {
if (capacity < 0) {
throw new IllegalArgumentException("capacity=" + capacity);
}
_data = new short[capacity];

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/primitives/Attic/TestFloatArrayList.java,v 1.2 2002/06/21 04:01:31 mas Exp $
* $Revision: 1.2 $
* $Date: 2002/06/21 04:01:31 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestFloatArrayList.java,v 1.3 2002/09/07 20:33:32 rwaldhoff Exp $
* $Revision: 1.3 $
* $Date: 2002/09/07 20:33:32 $
*
* ====================================================================
*
@ -68,7 +68,7 @@ import org.apache.commons.collections.TestList;
import java.util.List;
/**
* @version $Revision: 1.2 $ $Date: 2002/06/21 04:01:31 $
* @version $Revision: 1.3 $ $Date: 2002/09/07 20:33:32 $
* @author Rodney Waldhoff
*/
public class TestFloatArrayList extends TestList {
@ -98,6 +98,10 @@ public class TestFloatArrayList extends TestList {
//------------------------------------------------------------------- Tests
public void testZeroInitialCapacityIsValid() {
FloatArrayList list = new FloatArrayList(0);
}
public void testAddGet() {
FloatArrayList list = createList();
for(float i=0F;i<1000F;i++) {

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/primitives/Attic/TestIntArrayList.java,v 1.3 2002/08/19 21:19:03 pjack Exp $
* $Revision: 1.3 $
* $Date: 2002/08/19 21:19:03 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestIntArrayList.java,v 1.4 2002/09/07 20:33:32 rwaldhoff Exp $
* $Revision: 1.4 $
* $Date: 2002/09/07 20:33:32 $
*
* ====================================================================
*
@ -67,7 +67,7 @@ import junit.framework.TestSuite;
import org.apache.commons.collections.BulkTest;
/**
* @version $Revision: 1.3 $ $Date: 2002/08/19 21:19:03 $
* @version $Revision: 1.4 $ $Date: 2002/09/07 20:33:32 $
* @author Rodney Waldhoff
*/
public class TestIntArrayList extends TestAbstractIntArrayList {
@ -89,5 +89,11 @@ public class TestIntArrayList extends TestAbstractIntArrayList {
return new IntArrayList();
}
//---------------------------------------------------------------- Tests
public void testZeroInitialCapacityIsValid() {
IntArrayList list = new IntArrayList(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/primitives/Attic/TestLongArrayList.java,v 1.3 2002/08/19 21:19:03 pjack Exp $
* $Revision: 1.3 $
* $Date: 2002/08/19 21:19:03 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestLongArrayList.java,v 1.4 2002/09/07 20:33:32 rwaldhoff Exp $
* $Revision: 1.4 $
* $Date: 2002/09/07 20:33:32 $
*
* ====================================================================
*
@ -67,7 +67,7 @@ import junit.framework.TestSuite;
import org.apache.commons.collections.BulkTest;
/**
* @version $Revision: 1.3 $ $Date: 2002/08/19 21:19:03 $
* @version $Revision: 1.4 $ $Date: 2002/09/07 20:33:32 $
* @author Rodney Waldhoff
*/
public class TestLongArrayList extends TestAbstractLongArrayList {
@ -89,5 +89,11 @@ public class TestLongArrayList extends TestAbstractLongArrayList {
return new LongArrayList();
}
//---------------------------------------------------------------- Tests
public void testZeroInitialCapacityIsValid() {
LongArrayList list = new LongArrayList(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/primitives/Attic/TestShortArrayList.java,v 1.3 2002/08/19 21:19:03 pjack Exp $
* $Revision: 1.3 $
* $Date: 2002/08/19 21:19:03 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestShortArrayList.java,v 1.4 2002/09/07 20:33:32 rwaldhoff Exp $
* $Revision: 1.4 $
* $Date: 2002/09/07 20:33:32 $
*
* ====================================================================
*
@ -67,7 +67,7 @@ import junit.framework.TestSuite;
import org.apache.commons.collections.BulkTest;
/**
* @version $Revision: 1.3 $ $Date: 2002/08/19 21:19:03 $
* @version $Revision: 1.4 $ $Date: 2002/09/07 20:33:32 $
* @author Rodney Waldhoff
*/
public class TestShortArrayList extends TestAbstractShortArrayList {
@ -89,5 +89,11 @@ public class TestShortArrayList extends TestAbstractShortArrayList {
return new ShortArrayList();
}
//---------------------------------------------------------------- Tests
public void testZeroInitialCapacityIsValid() {
ShortArrayList list = new ShortArrayList(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/primitives/Attic/TestUnsignedByteArrayList.java,v 1.3 2002/08/19 21:19:03 pjack Exp $
* $Revision: 1.3 $
* $Date: 2002/08/19 21:19:03 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestUnsignedByteArrayList.java,v 1.4 2002/09/07 20:33:32 rwaldhoff Exp $
* $Revision: 1.4 $
* $Date: 2002/09/07 20:33:32 $
*
* ====================================================================
*
@ -67,7 +67,7 @@ import junit.framework.TestSuite;
import org.apache.commons.collections.BulkTest;
/**
* @version $Revision: 1.3 $ $Date: 2002/08/19 21:19:03 $
* @version $Revision: 1.4 $ $Date: 2002/09/07 20:33:32 $
* @author Rodney Waldhoff
*/
public class TestUnsignedByteArrayList extends TestAbstractShortArrayList {
@ -89,5 +89,11 @@ public class TestUnsignedByteArrayList extends TestAbstractShortArrayList {
return new UnsignedByteArrayList();
}
//---------------------------------------------------------------- Tests
public void testZeroInitialCapacityIsValid() {
UnsignedByteArrayList list = new UnsignedByteArrayList(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/primitives/Attic/TestUnsignedIntArrayList.java,v 1.3 2002/08/19 21:19:03 pjack Exp $
* $Revision: 1.3 $
* $Date: 2002/08/19 21:19:03 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestUnsignedIntArrayList.java,v 1.4 2002/09/07 20:33:32 rwaldhoff Exp $
* $Revision: 1.4 $
* $Date: 2002/09/07 20:33:32 $
*
* ====================================================================
*
@ -67,7 +67,7 @@ import junit.framework.TestSuite;
import org.apache.commons.collections.BulkTest;
/**
* @version $Revision: 1.3 $ $Date: 2002/08/19 21:19:03 $
* @version $Revision: 1.4 $ $Date: 2002/09/07 20:33:32 $
* @author Rodney Waldhoff
*/
public class TestUnsignedIntArrayList extends TestAbstractLongArrayList {
@ -89,5 +89,11 @@ public class TestUnsignedIntArrayList extends TestAbstractLongArrayList {
return new UnsignedIntArrayList();
}
//---------------------------------------------------------------- Tests
public void testZeroInitialCapacityIsValid() {
UnsignedIntArrayList list = new UnsignedIntArrayList(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/primitives/Attic/TestUnsignedShortArrayList.java,v 1.3 2002/08/19 21:19:03 pjack Exp $
* $Revision: 1.3 $
* $Date: 2002/08/19 21:19:03 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestUnsignedShortArrayList.java,v 1.4 2002/09/07 20:33:32 rwaldhoff Exp $
* $Revision: 1.4 $
* $Date: 2002/09/07 20:33:32 $
*
* ====================================================================
*
@ -67,7 +67,7 @@ import junit.framework.TestSuite;
import org.apache.commons.collections.BulkTest;
/**
* @version $Revision: 1.3 $ $Date: 2002/08/19 21:19:03 $
* @version $Revision: 1.4 $ $Date: 2002/09/07 20:33:32 $
* @author Rodney Waldhoff
*/
public class TestUnsignedShortArrayList extends TestAbstractIntArrayList {
@ -89,5 +89,11 @@ public class TestUnsignedShortArrayList extends TestAbstractIntArrayList {
return new UnsignedShortArrayList();
}
//---------------------------------------------------------------- Tests
public void testZeroInitialCapacityIsValid() {
UnsignedShortArrayList list = new UnsignedShortArrayList(0);
}
}