From 02687ec175ca69a7df32c02b8ed13b0f56bf9dfe Mon Sep 17 00:00:00 2001 From: Rodney Waldhoff Date: Fri, 28 Feb 2003 00:17:56 +0000 Subject: [PATCH] toward better serialization contract support in sublists git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130981 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractRandomAccessIntList.java | 11 +- .../AbstractCollectionIntCollection.java | 151 ++++++++++++++++ .../adapters/AbstractListIntList.java | 161 ++++++++++++++++++ .../adapters/CollectionIntCollection.java | 114 ++----------- .../primitives/adapters/ListIntList.java | 98 ++--------- ...onSerializableCollectionIntCollection.java | 78 +++++++++ .../adapters/NonSerializableListIntList.java | 80 +++++++++ .../primitives/TestArrayIntList.java | 6 +- .../TestArrayUnsignedShortList.java | 7 +- .../collections/primitives/TestIntList.java | 23 ++- .../primitives/adapters/TestListIntList.java | 25 ++- 11 files changed, 548 insertions(+), 206 deletions(-) create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/AbstractCollectionIntCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/AbstractListIntList.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCollectionIntCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/NonSerializableListIntList.java diff --git a/src/java/org/apache/commons/collections/primitives/AbstractRandomAccessIntList.java b/src/java/org/apache/commons/collections/primitives/AbstractRandomAccessIntList.java index 84750a13e..f617285ba 100644 --- a/src/java/org/apache/commons/collections/primitives/AbstractRandomAccessIntList.java +++ b/src/java/org/apache/commons/collections/primitives/AbstractRandomAccessIntList.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/AbstractRandomAccessIntList.java,v 1.11 2003/02/26 19:17:22 rwaldhoff Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/AbstractRandomAccessIntList.java,v 1.12 2003/02/28 00:17:52 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * @@ -57,7 +57,6 @@ package org.apache.commons.collections.primitives; -import java.io.Serializable; import java.util.ConcurrentModificationException; import java.util.NoSuchElementException; @@ -75,11 +74,11 @@ import java.util.NoSuchElementException; * to provide a more efficient implementation. * * @since Commons Collections 2.2 - * @version $Revision: 1.11 $ $Date: 2003/02/26 19:17:22 $ + * @version $Revision: 1.12 $ $Date: 2003/02/28 00:17:52 $ * * @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 @@ public abstract class AbstractRandomAccessIntList extends AbstractIntCollection // inner classes //------------------------------------------------------------------------- - private static class ComodChecker implements Serializable { + private static class ComodChecker { ComodChecker(AbstractRandomAccessIntList source) { _source = source; resyncModCount(); @@ -368,7 +367,7 @@ public abstract class AbstractRandomAccessIntList extends AbstractIntCollection 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(); diff --git a/src/java/org/apache/commons/collections/primitives/adapters/AbstractCollectionIntCollection.java b/src/java/org/apache/commons/collections/primitives/adapters/AbstractCollectionIntCollection.java new file mode 100644 index 000000000..0e8d45468 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/AbstractCollectionIntCollection.java @@ -0,0 +1,151 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/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 apache@apache.org. + * + * 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 + * . + * + */ + +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(); + } + + /** + * {@link IteratorIntIterator#wrap wraps} the + * {@link java.util.Iterator Iterator} + * returned by my underlying + * {@link 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. + * + */ + +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)); + } + + /** + * {@link ListIteratorIntListIterator#wrap wraps} the + * {@link IntList IntList} + * returned by my underlying + * {@link IntListIterator IntListIterator}, + * if any. + */ + public IntListIterator listIterator() { + return ListIteratorIntListIterator.wrap(getList().listIterator()); + } + + /** + * {@link ListIteratorIntListIterator#wrap wraps} the + * {@link IntList IntList} + * returned by my underlying + * {@link 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(); +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/CollectionIntCollection.java b/src/java/org/apache/commons/collections/primitives/adapters/CollectionIntCollection.java index ba330682d..4b3628dd6 100644 --- a/src/java/org/apache/commons/collections/primitives/adapters/CollectionIntCollection.java +++ b/src/java/org/apache/commons/collections/primitives/adapters/CollectionIntCollection.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/CollectionIntCollection.java,v 1.4 2003/02/26 19:17:23 rwaldhoff Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/CollectionIntCollection.java,v 1.5 2003/02/28 00:17:53 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * @@ -61,7 +61,6 @@ import java.io.Serializable; import java.util.Collection; import org.apache.commons.collections.primitives.IntCollection; -import org.apache.commons.collections.primitives.IntIterator; /** * Adapts a {@link java.lang.Number Number}-valued @@ -73,10 +72,10 @@ import org.apache.commons.collections.primitives.IntIterator; * implementation in the "obvious" way. * * @since Commons Collections 2.2 - * @version $Revision: 1.4 $ $Date: 2003/02/26 19:17:23 $ + * @version $Revision: 1.5 $ $Date: 2003/02/28 00:17:53 $ * @author Rodney Waldhoff */ -public class CollectionIntCollection implements IntCollection, Serializable { +public class CollectionIntCollection extends AbstractCollectionIntCollection implements Serializable { /** * Create an {@link IntCollection IntCollection} wrapping * the specified {@link Collection Collection}. When @@ -89,7 +88,13 @@ public class CollectionIntCollection implements IntCollection, Serializable { * null. */ 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 class CollectionIntCollection implements IntCollection, Serializable { 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(); + protected Collection getCollection() { + return _collection; } - - public boolean contains(int element) { - return _collection.contains(new Integer(element)); - } - - public boolean containsAll(IntCollection c) { - return _collection.containsAll(IntCollectionCollection.wrap(c)); - } - - /** - * If that is an {@link IntCollection IntCollection}, - * it is {@link IntCollectionCollection#wrap wrapped} and - * compared to my underlying {@link Collection Collection}, otherwise - * this method simply delegates to my underlying - * {@link 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(); - } - - /** - * {@link IteratorIntIterator#wrap wraps} the - * {@link java.util.Iterator Iterator} - * returned by my underlying - * {@link 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(); - } - - public int[] toArray() { - Object[] src = _collection.toArray(); - int[] dest = new int[src.length]; - for(int i=0;inull. */ 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 @@ public class ListIntList extends CollectionIntCollection implements IntList, Ser * @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)); - } - - /** - * {@link ListIteratorIntListIterator#wrap wraps} the - * {@link IntList IntList} - * returned by my underlying - * {@link IntListIterator IntListIterator}, - * if any. - */ - public IntListIterator listIterator() { - return ListIteratorIntListIterator.wrap(_list.listIterator()); - } - - /** - * {@link ListIteratorIntListIterator#wrap wraps} the - * {@link IntList IntList} - * returned by my underlying - * {@link 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; - + } diff --git a/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCollectionIntCollection.java b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCollectionIntCollection.java new file mode 100644 index 000000000..0bcf4ddef --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCollectionIntCollection.java @@ -0,0 +1,78 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/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 apache@apache.org. + * + * 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 + * . + * + */ + +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; + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableListIntList.java b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableListIntList.java new file mode 100644 index 000000000..b14ad7217 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableListIntList.java @@ -0,0 +1,80 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/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 apache@apache.org. + * + * 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 + * . + * + */ + +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; + +} diff --git a/src/test/org/apache/commons/collections/primitives/TestArrayIntList.java b/src/test/org/apache/commons/collections/primitives/TestArrayIntList.java index ba8cef3eb..6f85f26a5 100644 --- a/src/test/org/apache/commons/collections/primitives/TestArrayIntList.java +++ b/src/test/org/apache/commons/collections/primitives/TestArrayIntList.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestArrayIntList.java,v 1.8 2003/02/26 19:17:23 rwaldhoff Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestArrayIntList.java,v 1.9 2003/02/28 00:17:53 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * @@ -63,7 +63,7 @@ import junit.framework.TestSuite; import org.apache.commons.collections.BulkTest; /** - * @version $Revision: 1.8 $ $Date: 2003/02/26 19:17:23 $ + * @version $Revision: 1.9 $ $Date: 2003/02/28 00:17:53 $ * @author Rodney Waldhoff */ public class TestArrayIntList extends TestIntList { @@ -76,7 +76,7 @@ public class TestArrayIntList extends TestIntList { } 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; } diff --git a/src/test/org/apache/commons/collections/primitives/TestArrayUnsignedShortList.java b/src/test/org/apache/commons/collections/primitives/TestArrayUnsignedShortList.java index e2ff5119b..1c6f0e13e 100644 --- a/src/test/org/apache/commons/collections/primitives/TestArrayUnsignedShortList.java +++ b/src/test/org/apache/commons/collections/primitives/TestArrayUnsignedShortList.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestArrayUnsignedShortList.java,v 1.8 2003/02/26 19:17:23 rwaldhoff Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestArrayUnsignedShortList.java,v 1.9 2003/02/28 00:17:53 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * @@ -63,7 +63,7 @@ import junit.framework.TestSuite; import org.apache.commons.collections.BulkTest; /** - * @version $Revision: 1.8 $ $Date: 2003/02/26 19:17:23 $ + * @version $Revision: 1.9 $ $Date: 2003/02/28 00:17:53 $ * @author Rodney Waldhoff */ public class TestArrayUnsignedShortList extends TestIntList { @@ -76,8 +76,7 @@ public class TestArrayUnsignedShortList extends TestIntList { } 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); } diff --git a/src/test/org/apache/commons/collections/primitives/TestIntList.java b/src/test/org/apache/commons/collections/primitives/TestIntList.java index ba2c249a6..47ae4adda 100644 --- a/src/test/org/apache/commons/collections/primitives/TestIntList.java +++ b/src/test/org/apache/commons/collections/primitives/TestIntList.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestIntList.java,v 1.5 2003/02/26 19:17:23 rwaldhoff Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestIntList.java,v 1.6 2003/02/28 00:17:53 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * @@ -66,7 +66,7 @@ import org.apache.commons.collections.primitives.adapters.IntListList; import org.apache.commons.collections.primitives.adapters.ListIntList; /** - * @version $Revision: 1.5 $ $Date: 2003/02/26 19:17:23 $ + * @version $Revision: 1.6 $ $Date: 2003/02/28 00:17:53 $ * @author Rodney Waldhoff */ public abstract class TestIntList extends TestList { @@ -173,6 +173,12 @@ public abstract class TestIntList extends TestList { 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 @@ public abstract class TestIntList extends TestList { 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) ); + } } diff --git a/src/test/org/apache/commons/collections/primitives/adapters/TestListIntList.java b/src/test/org/apache/commons/collections/primitives/adapters/TestListIntList.java index 46eee7442..58b60f20e 100644 --- a/src/test/org/apache/commons/collections/primitives/adapters/TestListIntList.java +++ b/src/test/org/apache/commons/collections/primitives/adapters/TestListIntList.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/adapters/Attic/TestListIntList.java,v 1.1 2003/02/26 19:17:24 rwaldhoff Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/adapters/Attic/TestListIntList.java,v 1.2 2003/02/28 00:17:56 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * @@ -62,11 +62,12 @@ import java.util.ArrayList; 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; /** - * @version $Revision: 1.1 $ $Date: 2003/02/26 19:17:24 $ + * @version $Revision: 1.2 $ $Date: 2003/02/28 00:17:56 $ * @author Rodney Waldhoff */ public class TestListIntList extends TestIntList { @@ -79,16 +80,13 @@ public class TestListIntList extends TestIntList { } 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 @@ public class TestListIntList extends TestIntList { 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 // ------------------------------------------------------------------------ @@ -123,5 +135,4 @@ public class TestListIntList extends TestIntList { // need to add a serialized form to cvs } - }