rwaldhoff 2003/02/27 16:17:56 Modified: collections/src/java/org/apache/commons/collections/primitives AbstractRandomAccessIntList.java collections/src/java/org/apache/commons/collections/primitives/adapters CollectionIntCollection.java ListIntList.java collections/src/test/org/apache/commons/collections/primitives TestArrayIntList.java TestArrayUnsignedShortList.java TestIntList.java collections/src/test/org/apache/commons/collections/primitives/adapters TestListIntList.java Added: collections/src/java/org/apache/commons/collections/primitives/adapters AbstractCollectionIntCollection.java AbstractListIntList.java NonSerializableCollectionIntCollection.java NonSerializableListIntList.java Log: toward better serialization contract support in sublists Revision Changes Path 1.12 +5 -6 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/AbstractRandomAccessIntList.java Index: AbstractRandomAccessIntList.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/AbstractRandomAccessIntList.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- AbstractRandomAccessIntList.java 26 Feb 2003 19:17:22 -0000 1.11 +++ AbstractRandomAccessIntList.java 28 Feb 2003 00:17:52 -0000 1.12 @@ -57,7 +57,6 @@ package org.apache.commons.collections.primitives; -import java.io.Serializable; import java.util.ConcurrentModificationException; import java.util.NoSuchElementException; @@ -79,7 +78,7 @@ * * @author Rodney Waldhoff */ -public abstract class AbstractRandomAccessIntList extends AbstractIntCollection implements IntList, Serializable { +public abstract class AbstractRandomAccessIntList extends AbstractIntCollection implements IntList { // constructors //------------------------------------------------------------------------- @@ -251,7 +250,7 @@ // inner classes //------------------------------------------------------------------------- - private static class ComodChecker implements Serializable { + private static class ComodChecker { ComodChecker(AbstractRandomAccessIntList source) { _source = source; resyncModCount(); @@ -368,7 +367,7 @@ private int _lastReturnedIndex = -1; } - protected static class RandomAccessIntSubList extends AbstractRandomAccessIntList implements IntList, Serializable { + protected static class RandomAccessIntSubList extends AbstractRandomAccessIntList implements IntList { RandomAccessIntSubList(AbstractRandomAccessIntList list, int fromIndex, int toIndex) { if(fromIndex < 0 || toIndex > list.size() || fromIndex > toIndex) { throw new IndexOutOfBoundsException(); 1.5 +14 -100 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/CollectionIntCollection.java Index: CollectionIntCollection.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/CollectionIntCollection.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- CollectionIntCollection.java 26 Feb 2003 19:17:23 -0000 1.4 +++ CollectionIntCollection.java 28 Feb 2003 00:17:53 -0000 1.5 @@ -61,7 +61,6 @@ import java.util.Collection; import org.apache.commons.collections.primitives.IntCollection; -import org.apache.commons.collections.primitives.IntIterator; /** * Adapts a [EMAIL PROTECTED] java.lang.Number Number}-valued @@ -76,7 +75,7 @@ * @version $Revision$ $Date$ * @author Rodney Waldhoff */ -public class CollectionIntCollection implements IntCollection, Serializable { +public class CollectionIntCollection extends AbstractCollectionIntCollection implements Serializable { /** * Create an [EMAIL PROTECTED] IntCollection IntCollection} wrapping * the specified [EMAIL PROTECTED] Collection Collection}. When @@ -89,7 +88,13 @@ * <code>null</code>. */ public static IntCollection wrap(Collection collection) { - return null == collection ? null : new CollectionIntCollection(collection); + if(null == collection) { + return null; + } else if(collection instanceof Serializable) { + return new CollectionIntCollection(collection); + } else { + return new NonSerializableCollectionIntCollection(collection); + } } /** @@ -106,101 +111,10 @@ public CollectionIntCollection(Collection collection) { _collection = collection; } - - public boolean add(int element) { - return _collection.add(new Integer(element)); - } - - public boolean addAll(IntCollection c) { - return _collection.addAll(IntCollectionCollection.wrap(c)); - } - - public void clear() { - _collection.clear(); - } - - public boolean contains(int element) { - return _collection.contains(new Integer(element)); - } - - public boolean containsAll(IntCollection c) { - return _collection.containsAll(IntCollectionCollection.wrap(c)); - } - - /** - * If <i>that</i> is an [EMAIL PROTECTED] IntCollection IntCollection}, - * it is [EMAIL PROTECTED] IntCollectionCollection#wrap wrapped} and - * compared to my underlying [EMAIL PROTECTED] Collection Collection}, otherwise - * this method simply delegates to my underlying - * [EMAIL PROTECTED] Collection Collection}. - */ - public boolean equals(Object that) { - if(that instanceof IntCollection) { - return _collection.equals(IntCollectionCollection.wrap((IntCollection)that)); - } else { - return _collection.equals(that); - } - } - - public int hashCode() { - return _collection.hashCode(); - } - - public String toString() { - return _collection.toString(); - } - - public boolean isEmpty() { - return _collection.isEmpty(); - } - - /** - * [EMAIL PROTECTED] IteratorIntIterator#wrap wraps} the - * [EMAIL PROTECTED] java.util.Iterator Iterator} - * returned by my underlying - * [EMAIL PROTECTED] Collection Collection}, - * if any. - */ - public IntIterator iterator() { - return IteratorIntIterator.wrap(_collection.iterator()); - } - - public boolean removeElement(int element) { - return _collection.remove(new Integer(element)); - } - - public boolean removeAll(IntCollection c) { - return _collection.removeAll(IntCollectionCollection.wrap(c)); - } - - public boolean retainAll(IntCollection c) { - return _collection.retainAll(IntCollectionCollection.wrap(c)); - } - public int size() { - return _collection.size(); + protected Collection getCollection() { + return _collection; } - - public int[] toArray() { - Object[] src = _collection.toArray(); - int[] dest = new int[src.length]; - for(int i=0;i<src.length;i++) { - dest[i] = ((Number)(src[i])).intValue(); - } - return dest; - } - - public int[] toArray(int[] dest) { - Object[] src = _collection.toArray(); - if(dest.length < src.length) { - dest = new int[src.length]; - } - for(int i=0;i<src.length;i++) { - dest[i] = ((Number)(src[i])).intValue(); - } - return dest; - } - - private Collection _collection = null; - + + private Collection _collection = null; } 1.6 +14 -84 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/ListIntList.java Index: ListIntList.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/ListIntList.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ListIntList.java 26 Feb 2003 19:17:23 -0000 1.5 +++ ListIntList.java 28 Feb 2003 00:17:53 -0000 1.6 @@ -60,10 +60,7 @@ import java.io.Serializable; import java.util.List; -import org.apache.commons.collections.primitives.IntCollection; -import org.apache.commons.collections.primitives.IntIterator; import org.apache.commons.collections.primitives.IntList; -import org.apache.commons.collections.primitives.IntListIterator; /** * Adapts a [EMAIL PROTECTED] Number}-valued [EMAIL PROTECTED] List List} @@ -77,7 +74,7 @@ * @version $Revision$ $Date$ * @author Rodney Waldhoff */ -public class ListIntList extends CollectionIntCollection implements IntList, Serializable { +public class ListIntList extends AbstractListIntList implements Serializable { /** * Create an [EMAIL PROTECTED] IntList IntList} wrapping @@ -92,7 +89,13 @@ * <code>null</code>. */ public static IntList wrap(List list) { - return null == list ? null : new ListIntList(list); + if(null == list) { + return null; + } else if(list instanceof Serializable) { + return new ListIntList(list); + } else { + return new NonSerializableListIntList(list); + } } /** @@ -107,86 +110,13 @@ * @see #wrap */ public ListIntList(List list) { - super(list); - _list = list; + _list = list; } - public void add(int index, int element) { - _list.add(index,new Integer(element)); - } - - public boolean addAll(int index, IntCollection collection) { - return _list.addAll(index,IntCollectionCollection.wrap(collection)); - } - - public int get(int index) { - return ((Number)_list.get(index)).intValue(); - } - - public int indexOf(int element) { - return _list.indexOf(new Integer(element)); - } - - public int lastIndexOf(int element) { - return _list.lastIndexOf(new Integer(element)); - } - - /** - * [EMAIL PROTECTED] ListIteratorIntListIterator#wrap wraps} the - * [EMAIL PROTECTED] IntList IntList} - * returned by my underlying - * [EMAIL PROTECTED] IntListIterator IntListIterator}, - * if any. - */ - public IntListIterator listIterator() { - return ListIteratorIntListIterator.wrap(_list.listIterator()); - } - - /** - * [EMAIL PROTECTED] ListIteratorIntListIterator#wrap wraps} the - * [EMAIL PROTECTED] IntList IntList} - * returned by my underlying - * [EMAIL PROTECTED] IntListIterator IntListIterator}, - * if any. - */ - public IntListIterator listIterator(int index) { - return ListIteratorIntListIterator.wrap(_list.listIterator(index)); - } - - public int removeElementAt(int index) { - return ((Number)_list.remove(index)).intValue(); - } - - public int set(int index, int element) { - return ((Number)_list.set(index,new Integer(element))).intValue(); - } - - public IntList subList(int fromIndex, int toIndex) { - return ListIntList.wrap(_list.subList(fromIndex,toIndex)); - } - - public boolean equals(Object obj) { - if(obj instanceof IntList) { - IntList that = (IntList)obj; - if(this == that) { - return true; - } else if(this.size() != that.size()) { - return false; - } else { - IntIterator thisiter = iterator(); - IntIterator thatiter = that.iterator(); - while(thisiter.hasNext()) { - if(thisiter.next() != thatiter.next()) { - return false; - } - } - return true; - } - } else { - return false; - } + protected List getList() { + return _list; } private List _list = null; - + } 1.1 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/AbstractCollectionIntCollection.java Index: AbstractCollectionIntCollection.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/AbstractCollectionIntCollection.java,v 1.1 2003/02/28 00:17:53 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.commons.collections.primitives.adapters; import java.util.Collection; import org.apache.commons.collections.primitives.IntCollection; import org.apache.commons.collections.primitives.IntIterator; /** * @since Commons Collections 2.2 * @version $Revision: 1.1 $ $Date: 2003/02/28 00:17:53 $ * @author Rodney Waldhoff */ abstract class AbstractCollectionIntCollection implements IntCollection { protected AbstractCollectionIntCollection() { } public boolean add(int element) { return getCollection().add(new Integer(element)); } public boolean addAll(IntCollection c) { return getCollection().addAll(IntCollectionCollection.wrap(c)); } public void clear() { getCollection().clear(); } public boolean contains(int element) { return getCollection().contains(new Integer(element)); } public boolean containsAll(IntCollection c) { return getCollection().containsAll(IntCollectionCollection.wrap(c)); } public String toString() { return getCollection().toString(); } public boolean isEmpty() { return getCollection().isEmpty(); } /** * [EMAIL PROTECTED] IteratorIntIterator#wrap wraps} the * [EMAIL PROTECTED] java.util.Iterator Iterator} * returned by my underlying * [EMAIL PROTECTED] Collection Collection}, * if any. */ public IntIterator iterator() { return IteratorIntIterator.wrap(getCollection().iterator()); } public boolean removeElement(int element) { return getCollection().remove(new Integer(element)); } public boolean removeAll(IntCollection c) { return getCollection().removeAll(IntCollectionCollection.wrap(c)); } public boolean retainAll(IntCollection c) { return getCollection().retainAll(IntCollectionCollection.wrap(c)); } public int size() { return getCollection().size(); } public int[] toArray() { Object[] src = getCollection().toArray(); int[] dest = new int[src.length]; for(int i=0;i<src.length;i++) { dest[i] = ((Number)(src[i])).intValue(); } return dest; } public int[] toArray(int[] dest) { Object[] src = getCollection().toArray(); if(dest.length < src.length) { dest = new int[src.length]; } for(int i=0;i<src.length;i++) { dest[i] = ((Number)(src[i])).intValue(); } return dest; } protected abstract Collection getCollection(); } 1.1 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/AbstractListIntList.java Index: AbstractListIntList.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/AbstractListIntList.java,v 1.1 2003/02/28 00:17:53 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.commons.collections.primitives.adapters; import java.util.Collection; import java.util.List; import org.apache.commons.collections.primitives.IntCollection; import org.apache.commons.collections.primitives.IntIterator; import org.apache.commons.collections.primitives.IntList; import org.apache.commons.collections.primitives.IntListIterator; /** * * @since Commons Collections 2.2 * @version $Revision: 1.1 $ $Date: 2003/02/28 00:17:53 $ * @author Rodney Waldhoff */ abstract class AbstractListIntList extends AbstractCollectionIntCollection implements IntList { public void add(int index, int element) { getList().add(index,new Integer(element)); } public boolean addAll(int index, IntCollection collection) { return getList().addAll(index,IntCollectionCollection.wrap(collection)); } public int get(int index) { return ((Number)getList().get(index)).intValue(); } public int indexOf(int element) { return getList().indexOf(new Integer(element)); } public int lastIndexOf(int element) { return getList().lastIndexOf(new Integer(element)); } /** * [EMAIL PROTECTED] ListIteratorIntListIterator#wrap wraps} the * [EMAIL PROTECTED] IntList IntList} * returned by my underlying * [EMAIL PROTECTED] IntListIterator IntListIterator}, * if any. */ public IntListIterator listIterator() { return ListIteratorIntListIterator.wrap(getList().listIterator()); } /** * [EMAIL PROTECTED] ListIteratorIntListIterator#wrap wraps} the * [EMAIL PROTECTED] IntList IntList} * returned by my underlying * [EMAIL PROTECTED] IntListIterator IntListIterator}, * if any. */ public IntListIterator listIterator(int index) { return ListIteratorIntListIterator.wrap(getList().listIterator(index)); } public int removeElementAt(int index) { return ((Number)getList().remove(index)).intValue(); } public int set(int index, int element) { return ((Number)getList().set(index,new Integer(element))).intValue(); } public IntList subList(int fromIndex, int toIndex) { return ListIntList.wrap(getList().subList(fromIndex,toIndex)); } public boolean equals(Object obj) { if(obj instanceof IntList) { IntList that = (IntList)obj; if(this == that) { return true; } else if(this.size() != that.size()) { return false; } else { IntIterator thisiter = iterator(); IntIterator thatiter = that.iterator(); while(thisiter.hasNext()) { if(thisiter.next() != thatiter.next()) { return false; } } return true; } } else { return false; } } public int hashCode() { return getList().hashCode(); } final protected Collection getCollection() { return getList(); } abstract protected List getList(); } 1.1 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCollectionIntCollection.java Index: NonSerializableCollectionIntCollection.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCollectionIntCollection.java,v 1.1 2003/02/28 00:17:53 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.commons.collections.primitives.adapters; import java.util.Collection; /** * @since Commons Collections 2.2 * @version $Revision: 1.1 $ $Date: 2003/02/28 00:17:53 $ * @author Rodney Waldhoff */ class NonSerializableCollectionIntCollection extends AbstractCollectionIntCollection { public NonSerializableCollectionIntCollection(Collection collection) { _collection = collection; } protected Collection getCollection() { return _collection; } private Collection _collection = null; } 1.1 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableListIntList.java Index: NonSerializableListIntList.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableListIntList.java,v 1.1 2003/02/28 00:17:53 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.commons.collections.primitives.adapters; import java.util.List; /** * * @since Commons Collections 2.2 * @version $Revision: 1.1 $ $Date: 2003/02/28 00:17:53 $ * @author Rodney Waldhoff */ class NonSerializableListIntList extends AbstractListIntList { protected NonSerializableListIntList(List list) { _list = list; } protected List getList() { return _list; } private List _list = null; } 1.9 +3 -3 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestArrayIntList.java Index: TestArrayIntList.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestArrayIntList.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- TestArrayIntList.java 26 Feb 2003 19:17:23 -0000 1.8 +++ TestArrayIntList.java 28 Feb 2003 00:17:53 -0000 1.9 @@ -76,7 +76,7 @@ } public static Test suite() { - //TestSuite suite = BulkTest.makeSuite(TestArrayIntList.class); + // BulkTests won't work, sublists are not serializable TestSuite suite = new TestSuite(TestArrayIntList.class); return suite; } 1.9 +3 -4 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestArrayUnsignedShortList.java Index: TestArrayUnsignedShortList.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestArrayUnsignedShortList.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- TestArrayUnsignedShortList.java 26 Feb 2003 19:17:23 -0000 1.8 +++ TestArrayUnsignedShortList.java 28 Feb 2003 00:17:53 -0000 1.9 @@ -76,8 +76,7 @@ } public static Test suite() { - //TestSuite suite = BulkTest.makeSuite(TestArrayUnsignedShortList.class); - //return suite; + // BulkTests won't work, sublists are not serializable return new TestSuite(TestArrayUnsignedShortList.class); } 1.6 +21 -2 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestIntList.java Index: TestIntList.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestIntList.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- TestIntList.java 26 Feb 2003 19:17:23 -0000 1.5 +++ TestIntList.java 28 Feb 2003 00:17:53 -0000 1.6 @@ -173,6 +173,12 @@ two.add(1); two.add(2); two.add(3); two.add(5); two.add(8); assertEquals("Larger non empty lists are equal",one,two); assertEquals("Equals is symmetric on larger non empty list",two,one); + + one.add(9); + two.add(10); + assertTrue(!one.equals(two)); + assertTrue(!two.equals(one)); + } public void testIntSubListEquals() { @@ -290,5 +296,18 @@ assertEquals(deser,list); } + public void testIntListSerializeDeserializeThenCompare() throws Exception { + IntList list = makeFullIntList(); + if(list instanceof Serializable) { + byte[] ser = writeExternalFormToBytes((Serializable)list); + IntList deser = (IntList)(readExternalFormFromBytes(ser)); + assertEquals("obj != deserialize(serialize(obj))",list,deser); + } + } + + public void testSubListsAreNotSerializable() throws Exception { + IntList list = makeFullIntList().subList(2,3); + assertTrue( ! (list instanceof Serializable) ); + } } 1.2 +18 -7 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestListIntList.java Index: TestListIntList.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestListIntList.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TestListIntList.java 26 Feb 2003 19:17:24 -0000 1.1 +++ TestListIntList.java 28 Feb 2003 00:17:56 -0000 1.2 @@ -62,6 +62,7 @@ import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.commons.collections.BulkTest; import org.apache.commons.collections.primitives.IntList; import org.apache.commons.collections.primitives.TestIntList; @@ -79,16 +80,13 @@ } public static Test suite() { - //TestSuite suite = BulkTest.makeSuite(TestListIntList.class); - // java.util.SubList is not serializable - TestSuite suite = new TestSuite(TestListIntList.class); + TestSuite suite = BulkTest.makeSuite(TestListIntList.class); return suite; } // collections testing framework // ------------------------------------------------------------------------ - /** * @see org.apache.commons.collections.primitives.TestIntList#makeEmptyIntList() */ @@ -96,6 +94,20 @@ return new ListIntList(new ArrayList()); } + public String[] ignoredSimpleTests() { + // sublists are not serializable + return new String[] { + "TestListIntList.bulkTestSubList.testFullListSerialization", + "TestListIntList.bulkTestSubList.testEmptyListSerialization", + "TestListIntList.bulkTestSubList.testCanonicalEmptyCollectionExists", + "TestListIntList.bulkTestSubList.testCanonicalFullCollectionExists", + "TestListIntList.bulkTestSubList.testEmptyListCompatibility", + "TestListIntList.bulkTestSubList.testFullListCompatibility", + "TestListIntList.bulkTestSubList.testSerializeDeserializeThenCompare", + "TestListIntList.bulkTestSubList.testSimpleSerialization" + }; + } + // tests // ------------------------------------------------------------------------ @@ -122,6 +134,5 @@ // XXX FIX ME XXX // need to add a serialized form to cvs } - }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]