You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rw...@apache.org on 2002/09/07 22:33:32 UTC
cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections/primitives TestFloatArrayList.java TestIntArrayList.java TestLongArrayList.java TestShortArrayList.java TestUnsignedByteArrayList.java TestUnsignedIntArrayList.java TestUnsignedShortArrayList.java
rwaldhoff 2002/09/07 13:33:32
Modified: collections/src/java/org/apache/commons/collections/primitives
FloatArrayList.java IntArrayList.java
LongArrayList.java ShortArrayList.java
UnsignedByteArrayList.java
UnsignedIntArrayList.java
UnsignedShortArrayList.java
collections/src/test/org/apache/commons/collections/primitives
TestFloatArrayList.java TestIntArrayList.java
TestLongArrayList.java TestShortArrayList.java
TestUnsignedByteArrayList.java
TestUnsignedIntArrayList.java
TestUnsignedShortArrayList.java
Log:
* 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
Revision Changes Path
1.5 +6 -7 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/FloatArrayList.java
Index: FloatArrayList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/FloatArrayList.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FloatArrayList.java 23 Aug 2002 17:31:28 -0000 1.4
+++ FloatArrayList.java 7 Sep 2002 20:33:32 -0000 1.5
@@ -98,11 +98,10 @@
* 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];
1.6 +6 -7 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/IntArrayList.java
Index: IntArrayList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/IntArrayList.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- IntArrayList.java 22 Aug 2002 01:50:54 -0000 1.5
+++ IntArrayList.java 7 Sep 2002 20:33:32 -0000 1.6
@@ -96,11 +96,10 @@
* 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];
1.6 +6 -7 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/LongArrayList.java
Index: LongArrayList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/LongArrayList.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- LongArrayList.java 22 Aug 2002 01:50:54 -0000 1.5
+++ LongArrayList.java 7 Sep 2002 20:33:32 -0000 1.6
@@ -98,11 +98,10 @@
* 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];
1.6 +6 -7 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/ShortArrayList.java
Index: ShortArrayList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/ShortArrayList.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ShortArrayList.java 22 Aug 2002 01:50:54 -0000 1.5
+++ ShortArrayList.java 7 Sep 2002 20:33:32 -0000 1.6
@@ -98,11 +98,10 @@
* 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];
1.6 +32 -33 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/UnsignedByteArrayList.java
Index: UnsignedByteArrayList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/UnsignedByteArrayList.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- UnsignedByteArrayList.java 22 Aug 2002 01:50:54 -0000 1.5
+++ UnsignedByteArrayList.java 7 Sep 2002 20:33:32 -0000 1.6
@@ -100,11 +100,10 @@
* 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];
@@ -174,26 +173,26 @@
checkRangeIncludingEndpoint(index);
ensureCapacity(_size+1);
int numtomove = _size-index;
- System.arraycopy(_data,index,_data,index+1,numtomove);
- _data[index] = fromShort(value);
- _size++;
+ System.arraycopy(_data,index,_data,index+1,numtomove);
+ _data[index] = fromShort(value);
+ _size++;
}
public void clear() {
- modCount++;
+ modCount++;
_size = 0;
}
public short removeShortAt(int index) {
checkRange(index);
- modCount++;
+ modCount++;
short oldval = toShort(_data[index]);
- int numtomove = _size - index - 1;
- if(numtomove > 0) {
- System.arraycopy(_data,index+1,_data,index,numtomove);
+ int numtomove = _size - index - 1;
+ if(numtomove > 0) {
+ System.arraycopy(_data,index+1,_data,index,numtomove);
}
_size--;
- return oldval;
+ return oldval;
}
public boolean removeShort(short value) {
@@ -208,22 +207,22 @@
}
public void ensureCapacity(int mincap) {
- modCount++;
- if(mincap > _data.length) {
- int newcap = (_data.length * 3)/2 + 1;
- byte[] olddata = _data;
- _data = new byte[newcap < mincap ? mincap : newcap];
- System.arraycopy(olddata,0,_data,0,_size);
- }
+ modCount++;
+ if(mincap > _data.length) {
+ int newcap = (_data.length * 3)/2 + 1;
+ byte[] olddata = _data;
+ _data = new byte[newcap < mincap ? mincap : newcap];
+ System.arraycopy(olddata,0,_data,0,_size);
+ }
}
public void trimToSize() {
- modCount++;
- if(_size < _data.length) {
- byte[] olddata = _data;
- _data = new byte[_size];
- System.arraycopy(olddata,0,_data,0,_size);
- }
+ modCount++;
+ if(_size < _data.length) {
+ byte[] olddata = _data;
+ _data = new byte[_size];
+ System.arraycopy(olddata,0,_data,0,_size);
+ }
}
//---------------------------------------------------------------
@@ -246,17 +245,17 @@
}
private void writeObject(ObjectOutputStream out) throws IOException{
- out.defaultWriteObject();
+ out.defaultWriteObject();
out.writeInt(_data.length);
- for(int i=0;i<_size;i++) {
+ for(int i=0;i<_size;i++) {
out.writeByte(_data[i]);
}
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
+ in.defaultReadObject();
_data = new byte[in.readInt()];
- for(int i=0;i<_size;i++) {
+ for(int i=0;i<_size;i++) {
_data[i] = in.readByte();
}
}
1.6 +32 -33 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/UnsignedIntArrayList.java
Index: UnsignedIntArrayList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/UnsignedIntArrayList.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- UnsignedIntArrayList.java 22 Aug 2002 01:50:54 -0000 1.5
+++ UnsignedIntArrayList.java 7 Sep 2002 20:33:32 -0000 1.6
@@ -100,11 +100,10 @@
* 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];
@@ -174,26 +173,26 @@
checkRangeIncludingEndpoint(index);
ensureCapacity(_size+1);
int numtomove = _size-index;
- System.arraycopy(_data,index,_data,index+1,numtomove);
- _data[index] = fromLong(value);
- _size++;
+ System.arraycopy(_data,index,_data,index+1,numtomove);
+ _data[index] = fromLong(value);
+ _size++;
}
public void clear() {
- modCount++;
+ modCount++;
_size = 0;
}
public long removeLongAt(int index) {
checkRange(index);
- modCount++;
+ modCount++;
long oldval = toLong(_data[index]);
- int numtomove = _size - index - 1;
- if(numtomove > 0) {
- System.arraycopy(_data,index+1,_data,index,numtomove);
+ int numtomove = _size - index - 1;
+ if(numtomove > 0) {
+ System.arraycopy(_data,index+1,_data,index,numtomove);
}
_size--;
- return oldval;
+ return oldval;
}
public boolean removeLong(long value) {
@@ -208,22 +207,22 @@
}
public void ensureCapacity(int mincap) {
- modCount++;
- if(mincap > _data.length) {
- int newcap = (_data.length * 3)/2 + 1;
- int[] olddata = _data;
- _data = new int[newcap < mincap ? mincap : newcap];
- System.arraycopy(olddata,0,_data,0,_size);
- }
+ modCount++;
+ if(mincap > _data.length) {
+ int newcap = (_data.length * 3)/2 + 1;
+ int[] olddata = _data;
+ _data = new int[newcap < mincap ? mincap : newcap];
+ System.arraycopy(olddata,0,_data,0,_size);
+ }
}
public void trimToSize() {
- modCount++;
- if(_size < _data.length) {
- int[] olddata = _data;
- _data = new int[_size];
- System.arraycopy(olddata,0,_data,0,_size);
- }
+ modCount++;
+ if(_size < _data.length) {
+ int[] olddata = _data;
+ _data = new int[_size];
+ System.arraycopy(olddata,0,_data,0,_size);
+ }
}
//---------------------------------------------------------------
@@ -245,17 +244,17 @@
}
}
private void writeObject(ObjectOutputStream out) throws IOException{
- out.defaultWriteObject();
+ out.defaultWriteObject();
out.writeInt(_data.length);
- for(int i=0;i<_size;i++) {
+ for(int i=0;i<_size;i++) {
out.writeInt(_data[i]);
}
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
+ in.defaultReadObject();
_data = new int[in.readInt()];
- for(int i=0;i<_size;i++) {
+ for(int i=0;i<_size;i++) {
_data[i] = in.readInt();
}
}
1.6 +32 -33 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/UnsignedShortArrayList.java
Index: UnsignedShortArrayList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/UnsignedShortArrayList.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- UnsignedShortArrayList.java 22 Aug 2002 01:50:54 -0000 1.5
+++ UnsignedShortArrayList.java 7 Sep 2002 20:33:32 -0000 1.6
@@ -101,11 +101,10 @@
* 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];
@@ -175,26 +174,26 @@
checkRangeIncludingEndpoint(index);
ensureCapacity(_size+1);
int numtomove = _size-index;
- System.arraycopy(_data,index,_data,index+1,numtomove);
- _data[index] = fromInt(value);
- _size++;
+ System.arraycopy(_data,index,_data,index+1,numtomove);
+ _data[index] = fromInt(value);
+ _size++;
}
public void clear() {
- modCount++;
+ modCount++;
_size = 0;
}
public int removeIntAt(int index) {
checkRange(index);
- modCount++;
+ modCount++;
int oldval = toInt(_data[index]);
- int numtomove = _size - index - 1;
- if(numtomove > 0) {
- System.arraycopy(_data,index+1,_data,index,numtomove);
+ int numtomove = _size - index - 1;
+ if(numtomove > 0) {
+ System.arraycopy(_data,index+1,_data,index,numtomove);
}
_size--;
- return oldval;
+ return oldval;
}
public boolean removeInt(int value) {
@@ -209,22 +208,22 @@
}
public void ensureCapacity(int mincap) {
- modCount++;
- if(mincap > _data.length) {
- int newcap = (_data.length * 3)/2 + 1;
- short[] olddata = _data;
- _data = new short[newcap < mincap ? mincap : newcap];
- System.arraycopy(olddata,0,_data,0,_size);
- }
+ modCount++;
+ if(mincap > _data.length) {
+ int newcap = (_data.length * 3)/2 + 1;
+ short[] olddata = _data;
+ _data = new short[newcap < mincap ? mincap : newcap];
+ System.arraycopy(olddata,0,_data,0,_size);
+ }
}
public void trimToSize() {
- modCount++;
- if(_size < _data.length) {
- short[] olddata = _data;
- _data = new short[_size];
- System.arraycopy(olddata,0,_data,0,_size);
- }
+ modCount++;
+ if(_size < _data.length) {
+ short[] olddata = _data;
+ _data = new short[_size];
+ System.arraycopy(olddata,0,_data,0,_size);
+ }
}
//---------------------------------------------------------------
@@ -247,17 +246,17 @@
}
private void writeObject(ObjectOutputStream out) throws IOException{
- out.defaultWriteObject();
+ out.defaultWriteObject();
out.writeInt(_data.length);
- for(int i=0;i<_size;i++) {
+ for(int i=0;i<_size;i++) {
out.writeShort(_data[i]);
}
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
+ in.defaultReadObject();
_data = new short[in.readInt()];
- for(int i=0;i<_size;i++) {
+ for(int i=0;i<_size;i++) {
_data[i] = in.readShort();
}
}
1.3 +8 -4 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestFloatArrayList.java
Index: TestFloatArrayList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestFloatArrayList.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestFloatArrayList.java 21 Jun 2002 04:01:31 -0000 1.2
+++ TestFloatArrayList.java 7 Sep 2002 20:33:32 -0000 1.3
@@ -98,6 +98,10 @@
//------------------------------------------------------------------- Tests
+ public void testZeroInitialCapacityIsValid() {
+ FloatArrayList list = new FloatArrayList(0);
+ }
+
public void testAddGet() {
FloatArrayList list = createList();
for(float i=0F;i<1000F;i++) {
1.4 +10 -4 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestIntArrayList.java
Index: TestIntArrayList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestIntArrayList.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestIntArrayList.java 19 Aug 2002 21:19:03 -0000 1.3
+++ TestIntArrayList.java 7 Sep 2002 20:33:32 -0000 1.4
@@ -89,5 +89,11 @@
return new IntArrayList();
}
+ //---------------------------------------------------------------- Tests
+
+ public void testZeroInitialCapacityIsValid() {
+ IntArrayList list = new IntArrayList(0);
+ }
+
}
1.4 +10 -4 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestLongArrayList.java
Index: TestLongArrayList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestLongArrayList.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestLongArrayList.java 19 Aug 2002 21:19:03 -0000 1.3
+++ TestLongArrayList.java 7 Sep 2002 20:33:32 -0000 1.4
@@ -89,5 +89,11 @@
return new LongArrayList();
}
+ //---------------------------------------------------------------- Tests
+
+ public void testZeroInitialCapacityIsValid() {
+ LongArrayList list = new LongArrayList(0);
+ }
+
}
1.4 +10 -4 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestShortArrayList.java
Index: TestShortArrayList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestShortArrayList.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestShortArrayList.java 19 Aug 2002 21:19:03 -0000 1.3
+++ TestShortArrayList.java 7 Sep 2002 20:33:32 -0000 1.4
@@ -89,5 +89,11 @@
return new ShortArrayList();
}
+ //---------------------------------------------------------------- Tests
+
+ public void testZeroInitialCapacityIsValid() {
+ ShortArrayList list = new ShortArrayList(0);
+ }
+
}
1.4 +10 -4 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestUnsignedByteArrayList.java
Index: TestUnsignedByteArrayList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestUnsignedByteArrayList.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestUnsignedByteArrayList.java 19 Aug 2002 21:19:03 -0000 1.3
+++ TestUnsignedByteArrayList.java 7 Sep 2002 20:33:32 -0000 1.4
@@ -89,5 +89,11 @@
return new UnsignedByteArrayList();
}
+ //---------------------------------------------------------------- Tests
+
+ public void testZeroInitialCapacityIsValid() {
+ UnsignedByteArrayList list = new UnsignedByteArrayList(0);
+ }
+
}
1.4 +10 -4 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestUnsignedIntArrayList.java
Index: TestUnsignedIntArrayList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestUnsignedIntArrayList.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestUnsignedIntArrayList.java 19 Aug 2002 21:19:03 -0000 1.3
+++ TestUnsignedIntArrayList.java 7 Sep 2002 20:33:32 -0000 1.4
@@ -89,5 +89,11 @@
return new UnsignedIntArrayList();
}
+ //---------------------------------------------------------------- Tests
+
+ public void testZeroInitialCapacityIsValid() {
+ UnsignedIntArrayList list = new UnsignedIntArrayList(0);
+ }
+
}
1.4 +10 -4 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestUnsignedShortArrayList.java
Index: TestUnsignedShortArrayList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestUnsignedShortArrayList.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestUnsignedShortArrayList.java 19 Aug 2002 21:19:03 -0000 1.3
+++ TestUnsignedShortArrayList.java 7 Sep 2002 20:33:32 -0000 1.4
@@ -89,5 +89,11 @@
return new UnsignedShortArrayList();
}
+ //---------------------------------------------------------------- Tests
+
+ public void testZeroInitialCapacityIsValid() {
+ UnsignedShortArrayList list = new UnsignedShortArrayList(0);
+ }
+
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>