From cb320f7403f3676b403084da986777911a12cc0a Mon Sep 17 00:00:00 2001 From: Rodney Waldhoff Date: Tue, 15 Apr 2003 00:11:20 +0000 Subject: [PATCH] add double collections and tests git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131010 13f79535-47bb-0310-9956-ffa450edef68 --- .../primitives/AbstractDoubleCollection.java | 175 +++++++ .../primitives/ArrayDoubleList.java | 265 +++++++++++ .../primitives/DoubleCollection.java | 246 ++++++++++ .../primitives/DoubleIterator.java | 101 ++++ .../collections/primitives/DoubleList.java | 291 ++++++++++++ .../primitives/DoubleListIterator.java | 186 ++++++++ .../primitives/RandomAccessDoubleList.java | 430 ++++++++++++++++++ .../AbstractCollectionDoubleCollection.java | 151 ++++++ .../AbstractDoubleCollectionCollection.java | 154 +++++++ .../adapters/AbstractDoubleListList.java | 164 +++++++ .../adapters/AbstractListDoubleList.java | 161 +++++++ .../adapters/CollectionDoubleCollection.java | 114 +++++ .../adapters/DoubleCollectionCollection.java | 117 +++++ .../adapters/DoubleIteratorIterator.java | 117 +++++ .../DoubleListIteratorListIterator.java | 141 ++++++ .../primitives/adapters/DoubleListList.java | 115 +++++ .../adapters/IteratorDoubleIterator.java | 119 +++++ .../primitives/adapters/ListDoubleList.java | 116 +++++ .../ListIteratorDoubleListIterator.java | 141 ++++++ ...erializableCollectionDoubleCollection.java | 78 ++++ ...erializableDoubleCollectionCollection.java | 82 ++++ .../NonSerializableDoubleListList.java | 83 ++++ .../NonSerializableListDoubleList.java | 80 ++++ .../TestAbstractDoubleCollection.java | 113 +++++ .../collections/primitives/TestAll.java | 8 +- .../primitives/TestArrayDoubleList.java | 222 +++++++++ .../primitives/TestDoubleIterator.java | 157 +++++++ .../primitives/TestDoubleList.java | 426 +++++++++++++++++ .../primitives/TestDoubleListIterator.java | 91 ++++ .../TestRandomAccessDoubleList.java | 155 +++++++ .../primitives/adapters/TestAll.java | 13 +- .../TestCollectionDoubleCollection.java | 136 ++++++ .../TestDoubleCollectionCollection.java | 136 ++++++ .../adapters/TestDoubleIteratorIterator.java | 122 +++++ .../TestDoubleListIteratorListIterator.java | 180 ++++++++ .../adapters/TestDoubleListList.java | 155 +++++++ .../adapters/TestIteratorDoubleIterator.java | 118 +++++ .../adapters/TestListDoubleList.java | 155 +++++++ .../TestListIteratorDoubleListIterator.java | 118 +++++ 39 files changed, 5928 insertions(+), 4 deletions(-) create mode 100644 src/java/org/apache/commons/collections/primitives/AbstractDoubleCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/ArrayDoubleList.java create mode 100644 src/java/org/apache/commons/collections/primitives/DoubleCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/DoubleIterator.java create mode 100644 src/java/org/apache/commons/collections/primitives/DoubleList.java create mode 100644 src/java/org/apache/commons/collections/primitives/DoubleListIterator.java create mode 100644 src/java/org/apache/commons/collections/primitives/RandomAccessDoubleList.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/AbstractCollectionDoubleCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/AbstractDoubleCollectionCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/AbstractDoubleListList.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/AbstractListDoubleList.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/CollectionDoubleCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/DoubleCollectionCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/DoubleIteratorIterator.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/DoubleListIteratorListIterator.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/DoubleListList.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/IteratorDoubleIterator.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/ListDoubleList.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/ListIteratorDoubleListIterator.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCollectionDoubleCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/NonSerializableDoubleCollectionCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/NonSerializableDoubleListList.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/NonSerializableListDoubleList.java create mode 100644 src/test/org/apache/commons/collections/primitives/TestAbstractDoubleCollection.java create mode 100644 src/test/org/apache/commons/collections/primitives/TestArrayDoubleList.java create mode 100644 src/test/org/apache/commons/collections/primitives/TestDoubleIterator.java create mode 100644 src/test/org/apache/commons/collections/primitives/TestDoubleList.java create mode 100644 src/test/org/apache/commons/collections/primitives/TestDoubleListIterator.java create mode 100644 src/test/org/apache/commons/collections/primitives/TestRandomAccessDoubleList.java create mode 100644 src/test/org/apache/commons/collections/primitives/adapters/TestCollectionDoubleCollection.java create mode 100644 src/test/org/apache/commons/collections/primitives/adapters/TestDoubleCollectionCollection.java create mode 100644 src/test/org/apache/commons/collections/primitives/adapters/TestDoubleIteratorIterator.java create mode 100644 src/test/org/apache/commons/collections/primitives/adapters/TestDoubleListIteratorListIterator.java create mode 100644 src/test/org/apache/commons/collections/primitives/adapters/TestDoubleListList.java create mode 100644 src/test/org/apache/commons/collections/primitives/adapters/TestIteratorDoubleIterator.java create mode 100644 src/test/org/apache/commons/collections/primitives/adapters/TestListDoubleList.java create mode 100644 src/test/org/apache/commons/collections/primitives/adapters/TestListIteratorDoubleListIterator.java diff --git a/src/java/org/apache/commons/collections/primitives/AbstractDoubleCollection.java b/src/java/org/apache/commons/collections/primitives/AbstractDoubleCollection.java new file mode 100644 index 000000000..4cf479225 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/AbstractDoubleCollection.java @@ -0,0 +1,175 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/AbstractDoubleCollection.java,v 1.1 2003/04/15 00:11:19 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; + +/** + * Abstract base class for {@link DoubleCollection}s. + *

+ * Read-only subclasses must override {@link #iterator} + * and {@link #size}. Mutable subclasses + * should also override {@link #add} and + * {@link DoubleIterator#remove DoubleIterator.remove}. + * All other methods have at least some base implementation + * derived from these. Subclasses may choose to override + * these methods to provide a more efficient implementation. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:19 $ + * + * @author Rodney Waldhoff + */ +public abstract class AbstractDoubleCollection implements DoubleCollection { + public abstract DoubleIterator iterator(); + public abstract int size(); + + protected AbstractDoubleCollection() { } + + /** Unsupported in this base implementation. */ + public boolean add(double element) { + throw new UnsupportedOperationException("add(double) is not supported."); + } + + public boolean addAll(DoubleCollection c) { + boolean modified = false; + for(DoubleIterator iter = c.iterator(); iter.hasNext(); ) { + modified |= add(iter.next()); + } + return modified; + } + + public void clear() { + for(DoubleIterator iter = iterator(); iter.hasNext();) { + iter.next(); + iter.remove(); + } + } + + public boolean contains(double element) { + for(DoubleIterator iter = iterator(); iter.hasNext();) { + if(iter.next() == element) { + return true; + } + } + return false; + } + + public boolean containsAll(DoubleCollection c) { + for(DoubleIterator iter = c.iterator(); iter.hasNext();) { + if(!contains(iter.next())) { + return false; + } + } + return true; + } + + public boolean isEmpty() { + return (0 == size()); + } + + public boolean removeElement(double element) { + for(DoubleIterator iter = iterator(); iter.hasNext();) { + if(iter.next() == element) { + iter.remove(); + return true; + } + } + return false; + } + + public boolean removeAll(DoubleCollection c) { + boolean modified = false; + for(DoubleIterator iter = c.iterator(); iter.hasNext(); ) { + modified |= removeElement(iter.next()); + } + return modified; + } + + public boolean retainAll(DoubleCollection c) { + boolean modified = false; + for(DoubleIterator iter = iterator(); iter.hasNext();) { + if(!c.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + public double[] toArray() { + double[] array = new double[size()]; + int i = 0; + for(DoubleIterator iter = iterator(); iter.hasNext();) { + array[i] = iter.next(); + i++; + } + return array; + } + + public double[] toArray(double[] a) { + if(a.length < size()) { + return toArray(); + } else { + int i = 0; + for(DoubleIterator iter = iterator(); iter.hasNext();) { + a[i] = iter.next(); + i++; + } + return a; + } + } +} diff --git a/src/java/org/apache/commons/collections/primitives/ArrayDoubleList.java b/src/java/org/apache/commons/collections/primitives/ArrayDoubleList.java new file mode 100644 index 000000000..9b5b5cf97 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/ArrayDoubleList.java @@ -0,0 +1,265 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/ArrayDoubleList.java,v 1.1 2003/04/15 00:11:19 rwaldhoff Exp $ + * ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002-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; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; + +/** + * An {@link DoubleList} backed by an array of doubles. + * This implementation supports all optional methods. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:19 $ + * + * @author Rodney Waldhoff + */ +public class ArrayDoubleList extends RandomAccessDoubleList implements DoubleList, Serializable { + + // constructors + //------------------------------------------------------------------------- + + /** + * Construct an empty list with the default + * initial capacity. + */ + public ArrayDoubleList() { + this(8); + } + + /** + * Construct an empty list with the given + * initial capacity. + * @throws IllegalArgumentException when initialCapacity is negative + */ + public ArrayDoubleList(int initialCapacity) { + if(initialCapacity < 0) { + throw new IllegalArgumentException("capacity " + initialCapacity); + } + _data = new double[initialCapacity]; + _size = 0; + } + + /** + * Constructs a list containing the elements of the given collection, + * in the order they are returned by that collection's iterator. + * + * @see ArrayDoubleList#addAll(org.apache.commons.collections.primitives.DoubleCollection) + * @param that the non-null collection of doubles + * to add + * @throws NullPointerException if that is null + */ + public ArrayDoubleList(DoubleCollection that) { + this(that.size()); + addAll(that); + } + + // DoubleList methods + //------------------------------------------------------------------------- + + public double get(int index) { + checkRange(index); + return _data[index]; + } + + public int size() { + return _size; + } + + /** + * Removes the element at the specified position in + * (optional operation). Any subsequent elements + * are shifted to the left, subtracting one from their + * indices. Returns the element that was removed. + * + * @param index the index of the element to remove + * @return the value of the element that was removed + * + * @throws UnsupportedOperationException when this operation is not + * supported + * @throws IndexOutOfBoundsException if the specified index is out of range + */ + public double removeElementAt(int index) { + checkRange(index); + incrModCount(); + double oldval = _data[index]; + int numtomove = _size - index - 1; + if(numtomove > 0) { + System.arraycopy(_data,index+1,_data,index,numtomove); + } + _size--; + return oldval; + } + + /** + * Replaces the element at the specified + * position in me with the specified element + * (optional operation). + * + * @param index the index of the element to change + * @param element the value to be stored at the specified position + * @return the value previously stored at the specified position + * + * @throws UnsupportedOperationException when this operation is not + * supported + * @throws IndexOutOfBoundsException if the specified index is out of range + */ + public double set(int index, double element) { + checkRange(index); + incrModCount(); + double oldval = _data[index]; + _data[index] = element; + return oldval; + } + + /** + * Inserts the specified element at the specified position + * (optional operation). Shifts the element currently + * at that position (if any) and any subsequent elements to the + * right, increasing their indices. + * + * @param index the index at which to insert the element + * @param element the value to insert + * + * @throws UnsupportedOperationException when this operation is not + * supported + * @throws IllegalArgumentException if some aspect of the specified element + * prevents it from being added to me + * @throws IndexOutOfBoundsException if the specified index is out of range + */ + public void add(int index, double element) { + checkRangeIncludingEndpoint(index); + incrModCount(); + ensureCapacity(_size+1); + int numtomove = _size-index; + System.arraycopy(_data,index,_data,index+1,numtomove); + _data[index] = element; + _size++; + } + + // capacity methods + //------------------------------------------------------------------------- + + /** + * Increases my capacity, if necessary, to ensure that I can hold at + * least the number of elements specified by the minimum capacity + * argument without growing. + */ + public void ensureCapacity(int mincap) { + incrModCount(); + if(mincap > _data.length) { + int newcap = (_data.length * 3)/2 + 1; + double[] olddata = _data; + _data = new double[newcap < mincap ? mincap : newcap]; + System.arraycopy(olddata,0,_data,0,_size); + } + } + + /** + * Reduce my capacity, if necessary, to match my + * current {@link #size size}. + */ + public void trimToSize() { + incrModCount(); + if(_size < _data.length) { + double[] olddata = _data; + _data = new double[_size]; + System.arraycopy(olddata,0,_data,0,_size); + } + } + + // private methods + //------------------------------------------------------------------------- + + private void writeObject(ObjectOutputStream out) throws IOException{ + out.defaultWriteObject(); + out.writeInt(_data.length); + for(int i=0;i<_size;i++) { + out.writeDouble(_data[i]); + } + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + _data = new double[in.readInt()]; + for(int i=0;i<_size;i++) { + _data[i] = in.readDouble(); + } + } + + private final void checkRange(int index) { + if(index < 0 || index >= _size) { + throw new IndexOutOfBoundsException("Should be at least 0 and less than " + _size + ", found " + index); + } + } + + private final void checkRangeIncludingEndpoint(int index) { + if(index < 0 || index > _size) { + throw new IndexOutOfBoundsException("Should be at least 0 and at most " + _size + ", found " + index); + } + } + + // attributes + //------------------------------------------------------------------------- + + private transient double[] _data = null; + private int _size = 0; + +} diff --git a/src/java/org/apache/commons/collections/primitives/DoubleCollection.java b/src/java/org/apache/commons/collections/primitives/DoubleCollection.java new file mode 100644 index 000000000..8ee886d0b --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/DoubleCollection.java @@ -0,0 +1,246 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/DoubleCollection.java,v 1.1 2003/04/15 00:11:19 rwaldhoff Exp $ + * ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002-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; + +/** + * A collection of double values. + * + * @see org.apache.commons.collections.primitives.adapters.DoubleCollectionCollection + * @see org.apache.commons.collections.primitives.adapters.CollectionDoubleCollection + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:19 $ + * + * @author Rodney Waldhoff + */ +public interface DoubleCollection { + /** + * Ensures that I contain the specified element + * (optional operation). Returns true + * iff I changed as a result of this call. + *

+ * If a collection refuses to add the specified + * element for any reason other than that it already contains + * the element, it must throw an exception (rather than + * simply returning false). This preserves the invariant + * that a collection always contains the specified element after + * this call returns. + * + * @param element the value whose presence within me is to be ensured + * @return true iff I changed as a result of this call + * + * @throws UnsupportedOperationException when this operation is not + * supported + * @throws IllegalArgumentException may be thrown if some aspect of the + * specified element prevents it from being added to me + */ + boolean add(double element); + + /** + * {@link #add Adds} all of the elements in the + * specified collection to me (optional operation). + * + * @param c the collection of elements whose presence within me is to + * be ensured + * @return true iff I changed as a result of this call + * + * @throws UnsupportedOperationException when this operation is not + * supported + * @throws IllegalArgumentException may be thrown if some aspect of some + * specified element prevents it from being added to me + */ + boolean addAll(DoubleCollection c); + + /** + * Removes all my elements (optional operation). + * I will be {@link #isEmpty empty} after this + * method successfully returns. + * + * @throws UnsupportedOperationException when this operation is not + * supported + */ + void clear(); + + /** + * Returns true iff I contain + * the specified element. + * + * @param element the value whose presence within me is to be tested + * @return true iff I contain the specified element + */ + boolean contains(double element); + + /** + * Returns true iff I {@link #contains contain} + * all of the elements in the given collection. + * + * @param c the collection of elements whose presence within me is to + * be tested + * @return true iff I contain the all the specified elements + */ + boolean containsAll(DoubleCollection c); + + /** + * Returns true iff I contain no elements. + * @return true iff I contain no elements. + */ + boolean isEmpty(); + + /** + * Returns an {@link DoubleIterator iterator} over all my elements. + * This base interface places no constraints on the order + * in which the elements are returned by the returned iterator. + * @return an {@link DoubleIterator iterator} over all my elements. + */ + DoubleIterator iterator(); + + /** + * Removes all of my elements that are contained in the + * specified collection (optional operation). + * The behavior of this method is unspecified if + * the given collection is modified while this method + * is executing. Note that this includes the case + * in which the given collection is this collection, + * and it is not empty. + * + * @param c the collection of elements to remove + * @return true iff I contained the at least one of the + * specified elements, in other words, returns true + * iff I changed as a result of this call + * + * @throws UnsupportedOperationException when this operation is not + * supported + */ + boolean removeAll(DoubleCollection c); + + /** + * Removes a single occurrence of the specified element + * (optional operation). + * + * @param element the element to remove, if present + * @return true iff I contained the specified element, + * in other words, iff I changed as a result of this call + * + * @throws UnsupportedOperationException when this operation is not + * supported + */ + boolean removeElement(double element); + + /** + * Removes all of my elements that are not contained in the + * specified collection (optional operation). + * (In other words, retains only my elements that are + * contained in the specified collection.) + * The behavior of this method is unspecified if + * the given collection is modified while this method + * is executing. + * + * @param c the collection of elements to retain + * @return true iff I changed as a result + * of this call + * + * @throws UnsupportedOperationException when this operation is not + * supported + */ + boolean retainAll(DoubleCollection c); + + /** + * Returns the number of elements I contain. + * @return the number of elements I contain + */ + int size(); + + /** + * Returns an array containing all of my elements. + * The length of the returned array will be equal + * to my {@link #size size}. + *

+ * The returned array will be independent of me, + * so that callers may modify that + * returned array without modifying this collection. + *

+ * When I guarantee the order in which + * elements are returned by an {@link #iterator iterator}, + * the returned array will contain elements in the + * same order. + * + * @return an array containing all my elements + */ + double[] toArray(); + + /** + * Returns an array containing all of my elements, + * using the given array if it is large + * enough. When the length of the given array is + * larger than the number of elements I contain, + * values outside of my range will be unchanged. + *

+ * The returned array will be independent of me, + * so that callers may modify that + * returned array without modifying this collection. + *

+ * When I guarantee the order in which + * elements are returned by an {@link #iterator iterator}, + * the returned array will contain elements in the + * same order. + * + * @param a an array that may be used to contain the elements + * @return an array containing all my elements + */ + double[] toArray(double[] a); +} diff --git a/src/java/org/apache/commons/collections/primitives/DoubleIterator.java b/src/java/org/apache/commons/collections/primitives/DoubleIterator.java new file mode 100644 index 000000000..3dc9cf185 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/DoubleIterator.java @@ -0,0 +1,101 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/DoubleIterator.java,v 1.1 2003/04/15 00:11:19 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; + +/** + * An iterator over double values. + * + * @see org.apache.commons.collections.primitives.adapters.DoubleIteratorIterator + * @see org.apache.commons.collections.primitives.adapters.IteratorDoubleIterator + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:19 $ + * + * @author Rodney Waldhoff + */ +public interface DoubleIterator { + /** + * Returns true iff I have more elements. + * (In other words, returns true iff + * a subsequent call to {@link #next next} will return + * an element rather than throwing an exception.) + * + * @return true iff I have more elements + */ + boolean hasNext(); + + /** + * Returns the next element in me. + * + * @return the next element in me + * @throws NoSuchElementException if there is no next element + */ + double next(); + + /** + * Removes from my underlying collection the last + * element {@link #next returned} by me + * (optional operation). + * + * @throws UnsupportedOperationException if this operation is not supported + * @throws IllegalStateException if {@link #next} has not yet been + * called, or {@link #remove} has already been called since + * the last call to {@link #next}. + */ + void remove(); +} diff --git a/src/java/org/apache/commons/collections/primitives/DoubleList.java b/src/java/org/apache/commons/collections/primitives/DoubleList.java new file mode 100644 index 000000000..a3ff9b30f --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/DoubleList.java @@ -0,0 +1,291 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/DoubleList.java,v 1.1 2003/04/15 00:11:19 rwaldhoff Exp $ + * ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002-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; + +/** + * An ordered collection of double values. + * + * @see org.apache.commons.collections.primitives.adapters.DoubleListList + * @see org.apache.commons.collections.primitives.adapters.ListDoubleList + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:19 $ + * + * @author Rodney Waldhoff + */ +public interface DoubleList extends DoubleCollection { + /** + * Appends the specified element to the end of me + * (optional operation). Returns true + * iff I changed as a result of this call. + *

+ * If a collection refuses to add the specified + * element for any reason other than that it already contains + * the element, it must throw an exception (rather than + * simply returning false). This preserves the invariant + * that a collection always contains the specified element after + * this call returns. + * + * @param element the value whose presence within me is to be ensured + * @return true iff I changed as a result of this call + * + * @throws UnsupportedOperationException when this operation is not + * supported + * @throws IllegalArgumentException may be thrown if some aspect of the + * specified element prevents it from being added to me + */ + boolean add(double element); + + /** + * Inserts the specified element at the specified position + * (optional operation). Shifts the element currently + * at that position (if any) and any subsequent elements to the + * right, increasing their indices. + * + * @param index the index at which to insert the element + * @param element the value to insert + * + * @throws UnsupportedOperationException when this operation is not + * supported + * @throws IllegalArgumentException if some aspect of the specified element + * prevents it from being added to me + * @throws IndexOutOfBoundsException if the specified index is out of range + */ + void add(int index, double element); + + /** + * Inserts all of the elements in the specified collection into me, + * at the specified position (optional operation). Shifts the + * element currently at that position (if any) and any subsequent + * elements to the right, increasing their indices. The new elements + * will appear in the order that they are returned by the given + * collection's {@link DoubleCollection#iterator iterator}. + * + * @param index the index at which to insert the first element from + * the specified collection + * @param collection the {@link DoubleCollection DoubleCollection} of elements to add + * @return true iff I changed as a result of this call + * + * @throws UnsupportedOperationException when this operation is not + * supported + * @throws IndexOutOfBoundsException if the specified index is out of range + */ + boolean addAll(int index, DoubleCollection collection); + + /** + * Returns true iff that is an DoubleList + * that contains the same elements in the same order as me. + * In other words, returns true iff that is + * an DoubleList that has the same {@link #size size} as me, + * and for which the elements returned by its + * {@link DoubleList#iterator iterator} are equal (==) to + * the corresponding elements within me. + * (This contract ensures that this method works properly across + * different implementations of the DoubleList interface.) + * + * @param that the object to compare to me + * @return true iff that is an DoubleList + * that contains the same elements in the same order as me + */ + boolean equals(Object that); + + /** + * Returns the value of the element at the specified position + * within me. + * + * @param index the index of the element to return + * @return the value of the element at the specified position + * @throws IndexOutOfBoundsException if the specified index is out of range + */ + double get(int index); + + /** + * Returns my hash code. + *

+ * The hash code of an DoubleList is defined to be the + * result of the following calculation: + *

 int hash = 1;
+     * for(DoubleIterator iter = iterator(); iter.hasNext(); ) {
+     *   double value = iter.next();
+     *   hash = 31*hash + (int)(value ^ (value >>> 32));
+     * }
+ *

+ * This contract ensures that this method is consistent with + * {@link #equals equals} and with the + * {@link java.util.List#hashCode hashCode} + * method of a {@link java.util.List List} of {@link Double}s. + * + * @return my hash code + */ + int hashCode(); + + /** + * Returns the index of the first occurrence + * of the specified element within me, + * or -1 if I do not contain + * the element. + * + * @param element the element to search for + * @return the smallest index of an element matching the specified value, + * or -1 if no such matching element can be found + */ + int indexOf(double element); + + /** + * Returns an {@link DoubleIterator iterator} over all my elements, + * in the appropriate sequence. + * @return an {@link DoubleIterator iterator} over all my elements. + */ + DoubleIterator iterator(); + + /** + * Returns the index of the last occurrence + * of the specified element within me, + * or -1 if I do not contain the element. + * + * @param element the element to search for + * @return the largest index of an element matching the specified value, + * or -1 if no such matching element can be found + */ + int lastIndexOf(double element); + + /** + * Returns a + * {@link DoubleListIterator bidirectional iterator} + * over all my elements, in the appropriate sequence. + */ + DoubleListIterator listIterator(); + + /** + * Returns a + * {@link DoubleListIterator bidirectional iterator} + * over all my elements, in the appropriate sequence, + * starting at the specified position. The + * specified index indicates the first + * element that would be returned by an initial + * call to the + * {@link DoubleListIterator#next next} + * method. An initial call to the + * {@link DoubleListIterator#previous previous} + * method would return the element with the specified + * index minus one. + * + * @throws IndexOutOfBoundsException if the specified index is out of range + */ + DoubleListIterator listIterator(int index); + + /** + * Removes the element at the specified position in + * (optional operation). Any subsequent elements + * are shifted to the left, subtracting one from their + * indices. Returns the element that was removed. + * + * @param index the index of the element to remove + * @return the value of the element that was removed + * + * @throws UnsupportedOperationException when this operation is not + * supported + * @throws IndexOutOfBoundsException if the specified index is out of range + */ + double removeElementAt(int index); + + /** + * Replaces the element at the specified + * position in me with the specified element + * (optional operation). + * + * @param index the index of the element to change + * @param element the value to be stored at the specified position + * @return the value previously stored at the specified position + * + * @throws UnsupportedOperationException when this operation is not + * supported + * @throws IndexOutOfBoundsException if the specified index is out of range + */ + double set(int index, double element); + + /** + * Returns a view of the elements within me + * between the specified fromIndex, inclusive, and + * toIndex, exclusive. The returned DoubleList + * is backed by me, so that any changes in + * the returned list are reflected in me, and vice-versa. + * The returned list supports all of the optional operations + * that I support. + *

+ * Note that when fromIndex == toIndex, + * the returned list is initially empty, and when + * fromIndex == 0 && toIndex == {@link #size() size()} + * the returned list is my "improper" sublist, containing all my elements. + *

+ * The semantics of the returned list become undefined + * if I am structurally modified in any way other than + * via the returned list. + * + * @param fromIndex the smallest index (inclusive) in me that appears in + * the returned list + * @param toIndex the largest index (exclusive) in me that appears in the + * returned list + * @return a view of this list from fromIndex (inclusive) to + * toIndex (exclusive) + * + * @throws IndexOutOfBoundsException if either specified index is out of range + */ + DoubleList subList(int fromIndex, int toIndex); + +} diff --git a/src/java/org/apache/commons/collections/primitives/DoubleListIterator.java b/src/java/org/apache/commons/collections/primitives/DoubleListIterator.java new file mode 100644 index 000000000..5140cb976 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/DoubleListIterator.java @@ -0,0 +1,186 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/DoubleListIterator.java,v 1.1 2003/04/15 00:11:19 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; + +/** + * A bi-directional iterator over double values. + * + * @see org.apache.commons.collections.primitives.adapters.DoubleListIteratorListIterator + * @see org.apache.commons.collections.primitives.adapters.ListIteratorDoubleListIterator + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:19 $ + * + * @author Rodney Waldhoff + */ +public interface DoubleListIterator extends DoubleIterator { + /** + * Inserts the specified element into my underlying collection + * (optional operation). + * The element is inserted immediately before the next element + * that would have been returned by {@link #next}, if any, + * and immediately after the next element that would have been + * returned by {@link #previous}, if any. + *

+ * The new element is inserted immediately before the implied + * cursor. A subsequent call to {@link #previous} will return + * the added element, a subsequent call to {@link #next} will + * be unaffected. This call increases by one the value that + * would be returned by a call to {@link #nextIndex} or + * {@link #previousIndex}. + * + * @param element the value to be inserted + * + * @throws UnsupportedOperationException when this operation is not + * supported + * @throws IllegalArgumentException if some aspect of the specified element + * prevents it from being added + */ + void add(double element); + + /** + * Returns true iff I have more elements + * when traversed in the forward direction. + * (In other words, returns true iff + * a call to {@link #next} will return an element + * rather than throwing an exception. + * + * @return true iff I have more elements when + * traversed in the forward direction + */ + boolean hasNext(); + + /** + * Returns true iff I have more elements + * when traversed in the reverse direction. + * (In other words, returns true iff + * a call to {@link #previous} will return an element + * rather than throwing an exception. + * + * @return true iff I have more elements when + * traversed in the reverse direction + */ + boolean hasPrevious(); + + /** + * Returns the next element in me when traversed in the + * forward direction. + * + * @return the next element in me + * @throws NoSuchElementException if there is no next element + */ + double next(); + + /** + * Returns the index of the element that would be returned + * by a subsequent call to {@link #next}, or the number + * of elements in my iteration if I have no next element. + * + * @return the index of the next element in me + */ + int nextIndex(); + + /** + * Returns the next element in me when traversed in the + * reverse direction. + * + * @return the previous element in me + * @throws NoSuchElementException if there is no previous element + */ + double previous(); + + /** + * Returns the index of the element that would be returned + * by a subsequent call to {@link #previous}, or + * -1 if I have no previous element. + * + * @return the index of the previous element in me + */ + int previousIndex(); + + /** + * Removes from my underlying collection the last + * element returned by {@link #next} or {@link #previous} + * (optional operation). + * + * @throws UnsupportedOperationException if this operation is not + * supported + * @throws IllegalStateException if neither {@link #next} nor + * {@link #previous} has yet been called, or + * {@link #remove} or {@link #add} has already been called since + * the last call to {@link #next} or {@link #previous}. + */ + void remove(); + + /** + * Replaces in my underlying collection the last + * element returned by {@link #next} or {@link #previous} + * with the specified value (optional operation). + * + * @param element the value to replace the last returned element with + * @throws UnsupportedOperationException if this operation is not + * supported + * @throws IllegalStateException if neither {@link #next} nor + * {@link #previous} has yet been called, or + * {@link #remove} or {@link #add} has already been called since + * the last call to {@link #next} or {@link #previous}. + * @throws IllegalArgumentException if some aspect of the specified element + * prevents it from being added + */ + void set(double element); +} diff --git a/src/java/org/apache/commons/collections/primitives/RandomAccessDoubleList.java b/src/java/org/apache/commons/collections/primitives/RandomAccessDoubleList.java new file mode 100644 index 000000000..8bf877cb1 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/RandomAccessDoubleList.java @@ -0,0 +1,430 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/RandomAccessDoubleList.java,v 1.1 2003/04/15 00:11:19 rwaldhoff Exp $ + * ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002-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; + +import java.util.ConcurrentModificationException; +import java.util.NoSuchElementException; + +/** + * Abstract base class for {@link DoubleList}s backed + * by random access structures like arrays. + *

+ * Read-only subclasses must override {@link #get} + * and {@link #size}. Mutable subclasses + * should also override {@link #set}. Variably-sized + * subclasses should also override {@link #add} + * and {@link #removeElementAt}. All other methods + * have at least some base implementation derived from + * these. Subclasses may choose to override these methods + * to provide a more efficient implementation. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:19 $ + * + * @author Rodney Waldhoff + */ +public abstract class RandomAccessDoubleList extends AbstractDoubleCollection implements DoubleList { + + // constructors + //------------------------------------------------------------------------- + + /** Constructs an empty list. */ + protected RandomAccessDoubleList() { + } + + // fully abstract methods + //------------------------------------------------------------------------- + + public abstract double get(int index); + public abstract int size(); + + // unsupported in base + //------------------------------------------------------------------------- + + /** + * Unsupported in this implementation. + * @throws UnsupportedOperationException since this method is not supported + */ + public double removeElementAt(int index) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported in this implementation. + * @throws UnsupportedOperationException since this method is not supported + */ + public double set(int index, double element) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported in this implementation. + * @throws UnsupportedOperationException since this method is not supported + */ + public void add(int index, double element) { + throw new UnsupportedOperationException(); + } + + //------------------------------------------------------------------------- + + // javadocs here are inherited + + public boolean add(double element) { + add(size(),element); + return true; + } + + public boolean addAll(int index, DoubleCollection collection) { + boolean modified = false; + for(DoubleIterator iter = collection.iterator(); iter.hasNext(); ) { + add(index++,iter.next()); + modified = true; + } + return modified; + } + + public int indexOf(double element) { + int i = 0; + for(DoubleIterator iter = iterator(); iter.hasNext(); ) { + if(iter.next() == element) { + return i; + } else { + i++; + } + } + return -1; + } + + public int lastIndexOf(double element) { + for(DoubleListIterator iter = listIterator(size()); iter.hasPrevious(); ) { + if(iter.previous() == element) { + return iter.nextIndex(); + } + } + return -1; + } + + public DoubleIterator iterator() { + return listIterator(); + } + + public DoubleListIterator listIterator() { + return listIterator(0); + } + + public DoubleListIterator listIterator(int index) { + return new RandomAccessDoubleListIterator(this,index); + } + + public DoubleList subList(int fromIndex, int toIndex) { + return new RandomAccessDoubleSubList(this,fromIndex,toIndex); + } + + public boolean equals(Object that) { + if(this == that) { + return true; + } else if(that instanceof DoubleList) { + DoubleList thatList = (DoubleList)that; + if(size() != thatList.size()) { + return false; + } + for(DoubleIterator thatIter = thatList.iterator(), thisIter = iterator(); thisIter.hasNext();) { + if(thisIter.next() != thatIter.next()) { + return false; + } + } + return true; + } else { + return false; + } + } + + public int hashCode() { + int hash = 1; + for(DoubleIterator iter = iterator(); iter.hasNext(); ) { + long bits = Double.doubleToLongBits(iter.next()); + hash = 31*hash + ((int)(bits ^ (bits >>> 32))); + } + return hash; + } + + public String toString() { + StringBuffer buf = new StringBuffer(); + buf.append("["); + for(DoubleIterator iter = iterator(); iter.hasNext();) { + buf.append(iter.next()); + if(iter.hasNext()) { + buf.append(", "); + } + } + buf.append("]"); + return buf.toString(); + } + + // protected utilities + //------------------------------------------------------------------------- + + /** Get my count of structural modifications. */ + protected int getModCount() { + return _modCount; + } + + /** Increment my count of structural modifications. */ + protected void incrModCount() { + _modCount++; + } + + // attributes + //------------------------------------------------------------------------- + + private int _modCount = 0; + + // inner classes + //------------------------------------------------------------------------- + + private static class ComodChecker { + ComodChecker(RandomAccessDoubleList source) { + _source = source; + resyncModCount(); + } + + protected RandomAccessDoubleList getList() { + return _source; + } + + protected void assertNotComodified() throws ConcurrentModificationException { + if(_expectedModCount != getList().getModCount()) { + throw new ConcurrentModificationException(); + } + } + + protected void resyncModCount() { + _expectedModCount = getList().getModCount(); + } + + private RandomAccessDoubleList _source = null; + private int _expectedModCount = -1; + } + + protected static class RandomAccessDoubleListIterator extends ComodChecker implements DoubleListIterator { + RandomAccessDoubleListIterator(RandomAccessDoubleList list, int index) { + super(list); + if(index < 0 || index > getList().size()) { + throw new IndexOutOfBoundsException("Index " + index + " not in [0," + getList().size() + ")"); + } else { + _nextIndex = index; + resyncModCount(); + } + } + + public boolean hasNext() { + assertNotComodified(); + return _nextIndex < getList().size(); + } + + public boolean hasPrevious() { + assertNotComodified(); + return _nextIndex > 0; + } + + public int nextIndex() { + assertNotComodified(); + return _nextIndex; + } + + public int previousIndex() { + assertNotComodified(); + return _nextIndex - 1; + } + + public double next() { + assertNotComodified(); + if(!hasNext()) { + throw new NoSuchElementException(); + } else { + double val = getList().get(_nextIndex); + _lastReturnedIndex = _nextIndex; + _nextIndex++; + return val; + } + } + + public double previous() { + assertNotComodified(); + if(!hasPrevious()) { + throw new NoSuchElementException(); + } else { + double val = getList().get(_nextIndex-1); + _lastReturnedIndex = _nextIndex-1; + _nextIndex--; + return val; + } + } + + public void add(double value) { + assertNotComodified(); + getList().add(_nextIndex,value); + _nextIndex++; + _lastReturnedIndex = -1; + resyncModCount(); + } + + public void remove() { + assertNotComodified(); + if(-1 == _lastReturnedIndex) { + throw new IllegalStateException(); + } else { + getList().removeElementAt(_lastReturnedIndex); + _lastReturnedIndex = -1; + _nextIndex--; + resyncModCount(); + } + } + + public void set(double value) { + assertNotComodified(); + if(-1 == _lastReturnedIndex) { + throw new IllegalStateException(); + } else { + getList().set(_lastReturnedIndex,value); + resyncModCount(); + } + } + + private int _nextIndex = 0; + private int _lastReturnedIndex = -1; + } + + protected static class RandomAccessDoubleSubList extends RandomAccessDoubleList implements DoubleList { + RandomAccessDoubleSubList(RandomAccessDoubleList list, int fromIndex, int toIndex) { + if(fromIndex < 0 || toIndex > list.size()) { + throw new IndexOutOfBoundsException(); + } else if(fromIndex > toIndex) { + throw new IllegalArgumentException(); + } else { + _list = list; + _offset = fromIndex; + _limit = toIndex - fromIndex; + _comod = new ComodChecker(list); + _comod.resyncModCount(); + } + } + + public double get(int index) { + checkRange(index); + _comod.assertNotComodified(); + return _list.get(toUnderlyingIndex(index)); + } + + public double removeElementAt(int index) { + checkRange(index); + _comod.assertNotComodified(); + double val = _list.removeElementAt(toUnderlyingIndex(index)); + _limit--; + _comod.resyncModCount(); + incrModCount(); + return val; + } + + public double set(int index, double element) { + checkRange(index); + _comod.assertNotComodified(); + double val = _list.set(toUnderlyingIndex(index),element); + incrModCount(); + _comod.resyncModCount(); + return val; + } + + public void add(int index, double element) { + checkRangeIncludingEndpoint(index); + _comod.assertNotComodified(); + _list.add(toUnderlyingIndex(index),element); + _limit++; + _comod.resyncModCount(); + incrModCount(); + } + + public int size() { + _comod.assertNotComodified(); + return _limit; + } + + private void checkRange(int index) { + if(index < 0 || index >= size()) { + throw new IndexOutOfBoundsException("index " + index + " not in [0," + size() + ")"); + } + } + + private void checkRangeIncludingEndpoint(int index) { + if(index < 0 || index > size()) { + throw new IndexOutOfBoundsException("index " + index + " not in [0," + size() + "]"); + } + } + + private int toUnderlyingIndex(int index) { + return (index + _offset); + } + + private int _offset = 0; + private int _limit = 0; + private RandomAccessDoubleList _list = null; + private ComodChecker _comod = null; + + } +} + diff --git a/src/java/org/apache/commons/collections/primitives/adapters/AbstractCollectionDoubleCollection.java b/src/java/org/apache/commons/collections/primitives/adapters/AbstractCollectionDoubleCollection.java new file mode 100644 index 000000000..b32ea9e6d --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/AbstractCollectionDoubleCollection.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/AbstractCollectionDoubleCollection.java,v 1.1 2003/04/15 00:11:20 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.DoubleCollection; +import org.apache.commons.collections.primitives.DoubleIterator; + +/** + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +abstract class AbstractCollectionDoubleCollection implements DoubleCollection { + protected AbstractCollectionDoubleCollection() { + } + + public boolean add(double element) { + return getCollection().add(new Double(element)); + } + + public boolean addAll(DoubleCollection c) { + return getCollection().addAll(DoubleCollectionCollection.wrap(c)); + } + + public void clear() { + getCollection().clear(); + } + + public boolean contains(double element) { + return getCollection().contains(new Double(element)); + } + + public boolean containsAll(DoubleCollection c) { + return getCollection().containsAll(DoubleCollectionCollection.wrap(c)); + } + + public String toString() { + return getCollection().toString(); + } + + public boolean isEmpty() { + return getCollection().isEmpty(); + } + + /** + * {@link IteratorDoubleIterator#wrap wraps} the + * {@link java.util.Iterator Iterator} + * returned by my underlying + * {@link Collection Collection}, + * if any. + */ + public DoubleIterator iterator() { + return IteratorDoubleIterator.wrap(getCollection().iterator()); + } + + public boolean removeElement(double element) { + return getCollection().remove(new Double(element)); + } + + public boolean removeAll(DoubleCollection c) { + return getCollection().removeAll(DoubleCollectionCollection.wrap(c)); + } + + public boolean retainAll(DoubleCollection c) { + return getCollection().retainAll(DoubleCollectionCollection.wrap(c)); + } + + public int size() { + return getCollection().size(); + } + + public double[] toArray() { + Object[] src = getCollection().toArray(); + double[] dest = new double[src.length]; + for(int i=0;i. + * + */ + +package org.apache.commons.collections.primitives.adapters; + +import java.lang.reflect.Array; +import java.util.Collection; +import java.util.Iterator; + +import org.apache.commons.collections.primitives.DoubleCollection; + +/** + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +abstract class AbstractDoubleCollectionCollection implements Collection { + + public boolean add(Object element) { + return getDoubleCollection().add(((Number)element).doubleValue()); + } + + public boolean addAll(Collection c) { + return getDoubleCollection().addAll(CollectionDoubleCollection.wrap(c)); + } + + public void clear() { + getDoubleCollection().clear(); + } + + public boolean contains(Object element) { + return getDoubleCollection().contains(((Number)element).doubleValue()); + } + + + public boolean containsAll(Collection c) { + return getDoubleCollection().containsAll(CollectionDoubleCollection.wrap(c)); + } + + public String toString() { + return getDoubleCollection().toString(); + } + + public boolean isEmpty() { + return getDoubleCollection().isEmpty(); + } + + /** + * {@link DoubleIteratorIterator#wrap wraps} the + * {@link org.apache.commons.collections.primitives.DoubleIterator DoubleIterator} + * returned by my underlying + * {@link DoubleCollection DoubleCollection}, + * if any. + */ + public Iterator iterator() { + return DoubleIteratorIterator.wrap(getDoubleCollection().iterator()); + } + + public boolean remove(Object element) { + return getDoubleCollection().removeElement(((Number)element).doubleValue()); + } + + public boolean removeAll(Collection c) { + return getDoubleCollection().removeAll(CollectionDoubleCollection.wrap(c)); + } + + public boolean retainAll(Collection c) { + return getDoubleCollection().retainAll(CollectionDoubleCollection.wrap(c)); + } + + public int size() { + return getDoubleCollection().size(); + } + + public Object[] toArray() { + double[] a = getDoubleCollection().toArray(); + Object[] A = new Object[a.length]; + for(int i=0;i a.length) { + A[a.length] = null; + } + + return A; + } + + protected abstract DoubleCollection getDoubleCollection(); +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/AbstractDoubleListList.java b/src/java/org/apache/commons/collections/primitives/adapters/AbstractDoubleListList.java new file mode 100644 index 000000000..6be99cd23 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/AbstractDoubleListList.java @@ -0,0 +1,164 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/AbstractDoubleListList.java,v 1.1 2003/04/15 00:11:20 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 java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +import org.apache.commons.collections.primitives.DoubleCollection; +import org.apache.commons.collections.primitives.DoubleList; + +/** + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +abstract class AbstractDoubleListList extends AbstractDoubleCollectionCollection implements List { + + public void add(int index, Object element) { + getDoubleList().add(index,((Number)element).doubleValue()); + } + + public boolean addAll(int index, Collection c) { + return getDoubleList().addAll(index,CollectionDoubleCollection.wrap(c)); + } + + public Object get(int index) { + return new Double(getDoubleList().get(index)); + } + + public int indexOf(Object element) { + return getDoubleList().indexOf(((Number)element).doubleValue()); + } + + public int lastIndexOf(Object element) { + return getDoubleList().lastIndexOf(((Number)element).doubleValue()); + } + + /** + * {@link DoubleListIteratorListIterator#wrap wraps} the + * {@link org.apache.commons.collections.primitives.DoubleListIterator DoubleListIterator} + * returned by my underlying + * {@link DoubleList DoubleList}, + * if any. + */ + public ListIterator listIterator() { + return DoubleListIteratorListIterator.wrap(getDoubleList().listIterator()); + } + + /** + * {@link DoubleListIteratorListIterator#wrap wraps} the + * {@link org.apache.commons.collections.primitives.DoubleListIterator DoubleListIterator} + * returned by my underlying + * {@link DoubleList DoubleList}, + * if any. + */ + public ListIterator listIterator(int index) { + return DoubleListIteratorListIterator.wrap(getDoubleList().listIterator(index)); + } + + public Object remove(int index) { + return new Double(getDoubleList().removeElementAt(index)); + } + + public Object set(int index, Object element) { + return new Double(getDoubleList().set(index, ((Number)element).doubleValue() )); + } + + public List subList(int fromIndex, int toIndex) { + return DoubleListList.wrap(getDoubleList().subList(fromIndex,toIndex)); + } + + public boolean equals(Object obj) { + if(obj instanceof List) { + List that = (List)obj; + if(this == that) { + return true; + } else if(this.size() != that.size()) { + return false; + } else { + Iterator thisiter = iterator(); + Iterator thatiter = that.iterator(); + while(thisiter.hasNext()) { + Object thiselt = thisiter.next(); + Object thatelt = thatiter.next(); + if(null == thiselt ? null != thatelt : !(thiselt.equals(thatelt))) { + return false; + } + } + return true; + } + } else { + return false; + } + } + + public int hashCode() { + return getDoubleList().hashCode(); + } + + protected final DoubleCollection getDoubleCollection() { + return getDoubleList(); + } + + protected abstract DoubleList getDoubleList(); + + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/AbstractListDoubleList.java b/src/java/org/apache/commons/collections/primitives/adapters/AbstractListDoubleList.java new file mode 100644 index 000000000..c99d3adcf --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/AbstractListDoubleList.java @@ -0,0 +1,161 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/AbstractListDoubleList.java,v 1.1 2003/04/15 00:11:20 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 java.util.List; + +import org.apache.commons.collections.primitives.DoubleCollection; +import org.apache.commons.collections.primitives.DoubleIterator; +import org.apache.commons.collections.primitives.DoubleList; +import org.apache.commons.collections.primitives.DoubleListIterator; + +/** + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +abstract class AbstractListDoubleList extends AbstractCollectionDoubleCollection implements DoubleList { + + public void add(int index, double element) { + getList().add(index,new Double(element)); + } + + public boolean addAll(int index, DoubleCollection collection) { + return getList().addAll(index,DoubleCollectionCollection.wrap(collection)); + } + + public double get(int index) { + return ((Number)getList().get(index)).doubleValue(); + } + + public int indexOf(double element) { + return getList().indexOf(new Double(element)); + } + + public int lastIndexOf(double element) { + return getList().lastIndexOf(new Double(element)); + } + + /** + * {@link ListIteratorDoubleListIterator#wrap wraps} the + * {@link DoubleList DoubleList} + * returned by my underlying + * {@link DoubleListIterator DoubleListIterator}, + * if any. + */ + public DoubleListIterator listIterator() { + return ListIteratorDoubleListIterator.wrap(getList().listIterator()); + } + + /** + * {@link ListIteratorDoubleListIterator#wrap wraps} the + * {@link DoubleList DoubleList} + * returned by my underlying + * {@link DoubleListIterator DoubleListIterator}, + * if any. + */ + public DoubleListIterator listIterator(int index) { + return ListIteratorDoubleListIterator.wrap(getList().listIterator(index)); + } + + public double removeElementAt(int index) { + return ((Number)getList().remove(index)).doubleValue(); + } + + public double set(int index, double element) { + return ((Number)getList().set(index,new Double(element))).doubleValue(); + } + + public DoubleList subList(int fromIndex, int toIndex) { + return ListDoubleList.wrap(getList().subList(fromIndex,toIndex)); + } + + public boolean equals(Object obj) { + if(obj instanceof DoubleList) { + DoubleList that = (DoubleList)obj; + if(this == that) { + return true; + } else if(this.size() != that.size()) { + return false; + } else { + DoubleIterator thisiter = iterator(); + DoubleIterator 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/CollectionDoubleCollection.java b/src/java/org/apache/commons/collections/primitives/adapters/CollectionDoubleCollection.java new file mode 100644 index 000000000..923b21b9a --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/CollectionDoubleCollection.java @@ -0,0 +1,114 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/CollectionDoubleCollection.java,v 1.1 2003/04/15 00:11:20 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.io.Serializable; +import java.util.Collection; + +import org.apache.commons.collections.primitives.DoubleCollection; + +/** + * Adapts a {@link java.lang.Number Number}-valued + * {@link java.util.Collection Collection} to the + * {@link DoubleCollection DoubleCollection} interface. + *

+ * This implementation delegates most methods + * to the provided {@link Collection Collection} + * implementation in the "obvious" way. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +final public class CollectionDoubleCollection extends AbstractCollectionDoubleCollection implements Serializable { + /** + * Create an {@link DoubleCollection DoubleCollection} wrapping + * the specified {@link Collection Collection}. When + * the given collection is null, + * returns null. + * + * @param collection the (possibly null) {@link Collection} to wrap + * @return an {@link DoubleCollection DoubleCollection} wrapping the given + * collection, or null when collection is + * null. + */ + public static DoubleCollection wrap(Collection collection) { + if(null == collection) { + return null; + } else if(collection instanceof Serializable) { + return new CollectionDoubleCollection(collection); + } else { + return new NonSerializableCollectionDoubleCollection(collection); + } + } + + /** + * Creates an {@link DoubleCollection DoubleCollection} wrapping + * the specified {@link Collection Collection}. + * @see #wrap + */ + public CollectionDoubleCollection(Collection collection) { + _collection = collection; + } + + protected Collection getCollection() { + return _collection; + } + + private Collection _collection = null; +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/DoubleCollectionCollection.java b/src/java/org/apache/commons/collections/primitives/adapters/DoubleCollectionCollection.java new file mode 100644 index 000000000..03497241f --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/DoubleCollectionCollection.java @@ -0,0 +1,117 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/DoubleCollectionCollection.java,v 1.1 2003/04/15 00:11:20 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.io.Serializable; +import java.util.Collection; + +import org.apache.commons.collections.primitives.DoubleCollection; + +/** + * Adapts an {@link DoubleCollection DoubleCollection} + * to the {@link java.util.Collection Collection} + * interface. + *

+ * This implementation delegates most methods + * to the provided {@link DoubleCollection DoubleCollection} + * implementation in the "obvious" way. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +final public class DoubleCollectionCollection extends AbstractDoubleCollectionCollection implements Serializable { + + /** + * Create a {@link Collection Collection} wrapping + * the specified {@link DoubleCollection DoubleCollection}. When + * the given collection is null, + * returns null. + * + * @param collection the (possibly null) + * {@link DoubleCollection DoubleCollection} to wrap + * @return a {@link Collection Collection} wrapping the given + * collection, or null when collection is + * null. + */ + public static Collection wrap(DoubleCollection collection) { + if(null == collection) { + return null; + } else if(collection instanceof Serializable) { + return new DoubleCollectionCollection(collection); + } else { + return new NonSerializableDoubleCollectionCollection(collection); + } + } + + /** + * Creates a {@link Collection Collection} wrapping + * the specified {@link DoubleCollection DoubleCollection}. + * @see #wrap + */ + public DoubleCollectionCollection(DoubleCollection collection) { + _collection = collection; + } + + + protected DoubleCollection getDoubleCollection() { + return _collection; + } + + private DoubleCollection _collection = null; +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/DoubleIteratorIterator.java b/src/java/org/apache/commons/collections/primitives/adapters/DoubleIteratorIterator.java new file mode 100644 index 000000000..dd679eb3e --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/DoubleIteratorIterator.java @@ -0,0 +1,117 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/DoubleIteratorIterator.java,v 1.1 2003/04/15 00:11:20 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.Iterator; + +import org.apache.commons.collections.primitives.DoubleIterator; + +/** + * Adapts an {@link DoubleIterator DoubleIterator} to the + * {@link java.util.Iterator Iterator} interface. + *

+ * This implementation delegates most methods + * to the provided {@link DoubleIterator DoubleIterator} + * implementation in the "obvious" way. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +public class DoubleIteratorIterator implements Iterator { + + /** + * Create an {@link Iterator Iterator} wrapping + * the specified {@link DoubleIterator DoubleIterator}. When + * the given iterator is null, + * returns null. + * + * @param iterator the (possibly null) + * {@link DoubleIterator DoubleIterator} to wrap + * @return an {@link Iterator Iterator} wrapping the given + * iterator, or null when iterator is + * null. + */ + public static Iterator wrap(DoubleIterator iterator) { + return null == iterator ? null : new DoubleIteratorIterator(iterator); + } + + /** + * Creates an {@link Iterator Iterator} wrapping + * the specified {@link DoubleIterator DoubleIterator}. + * @see #wrap + */ + public DoubleIteratorIterator(DoubleIterator iterator) { + _iterator = iterator; + } + + public boolean hasNext() { + return _iterator.hasNext(); + } + + public Object next() { + return new Double(_iterator.next()); + } + + public void remove() { + _iterator.remove(); + } + + private DoubleIterator _iterator = null; + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/DoubleListIteratorListIterator.java b/src/java/org/apache/commons/collections/primitives/adapters/DoubleListIteratorListIterator.java new file mode 100644 index 000000000..fc7ea16a8 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/DoubleListIteratorListIterator.java @@ -0,0 +1,141 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/DoubleListIteratorListIterator.java,v 1.1 2003/04/15 00:11:20 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.ListIterator; + +import org.apache.commons.collections.primitives.DoubleListIterator; + +/** + * Adapts an {@link DoubleListIterator DoubleListIterator} to the + * {@link ListIterator ListIterator} interface. + *

+ * This implementation delegates most methods + * to the provided {@link DoubleListIterator DoubleListIterator} + * implementation in the "obvious" way. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +public class DoubleListIteratorListIterator implements ListIterator { + + /** + * Create a {@link ListIterator ListIterator} wrapping + * the specified {@link DoubleListIterator DoubleListIterator}. When + * the given iterator is null, + * returns null. + * + * @param iterator the (possibly null) + * {@link DoubleListIterator DoubleListIterator} to wrap + * @return a {@link ListIterator ListIterator} wrapping the given + * iterator, or null when iterator is + * null. + */ + public static ListIterator wrap(DoubleListIterator iterator) { + return null == iterator ? null : new DoubleListIteratorListIterator(iterator); + } + + /** + * Creates an {@link ListIterator ListIterator} wrapping + * the specified {@link DoubleListIterator DoubleListIterator}. + * @see #wrap + */ + public DoubleListIteratorListIterator(DoubleListIterator iterator) { + _iterator = iterator; + } + + public int nextIndex() { + return _iterator.nextIndex(); + } + + public int previousIndex() { + return _iterator.previousIndex(); + } + + public boolean hasNext() { + return _iterator.hasNext(); + } + + public boolean hasPrevious() { + return _iterator.hasPrevious(); + } + + public Object next() { + return new Double(_iterator.next()); + } + + public Object previous() { + return new Double(_iterator.previous()); + } + + public void add(Object obj) { + _iterator.add(((Number)obj).doubleValue()); + } + + public void set(Object obj) { + _iterator.set(((Number)obj).doubleValue()); + } + + public void remove() { + _iterator.remove(); + } + + private DoubleListIterator _iterator = null; + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/DoubleListList.java b/src/java/org/apache/commons/collections/primitives/adapters/DoubleListList.java new file mode 100644 index 000000000..fc99b6aeb --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/DoubleListList.java @@ -0,0 +1,115 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/DoubleListList.java,v 1.1 2003/04/15 00:11:20 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.io.Serializable; +import java.util.List; + +import org.apache.commons.collections.primitives.DoubleList; + +/** + * Adapts an {@link DoubleList DoubleList} to the + * {@link List List} interface. + *

+ * This implementation delegates most methods + * to the provided {@link DoubleList DoubleList} + * implementation in the "obvious" way. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +final public class DoubleListList extends AbstractDoubleListList implements Serializable { + + /** + * Create a {@link List List} wrapping + * the specified {@link DoubleList DoubleList}. When + * the given list is null, + * returns null. + * + * @param list the (possibly null) + * {@link DoubleList DoubleList} to wrap + * @return a {@link List List} wrapping the given + * list, or null when list is + * null. + */ + public static List wrap(DoubleList list) { + if(null == list) { + return null; + } else if(list instanceof Serializable) { + return new DoubleListList(list); + } else { + return new NonSerializableDoubleListList(list); + } + } + + /** + * Creates a {@link List List} wrapping + * the specified {@link DoubleList DoubleList}. + * @see #wrap + */ + public DoubleListList(DoubleList list) { + _list = list; + } + + protected DoubleList getDoubleList() { + return _list; + } + + private DoubleList _list = null; +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/IteratorDoubleIterator.java b/src/java/org/apache/commons/collections/primitives/adapters/IteratorDoubleIterator.java new file mode 100644 index 000000000..985b4f905 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/IteratorDoubleIterator.java @@ -0,0 +1,119 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/IteratorDoubleIterator.java,v 1.1 2003/04/15 00:11:20 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.Iterator; + +import org.apache.commons.collections.primitives.DoubleIterator; + +/** + * Adapts a {@link java.lang.Number Number}-valued + * {@link Iterator Iterator} + * to the {@link DoubleIterator DoubleIterator} + * interface. + *

+ * This implementation delegates most methods + * to the provided {@link Iterator Iterator} + * implementation in the "obvious" way. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +public class IteratorDoubleIterator implements DoubleIterator { + + /** + * Create an {@link DoubleIterator DoubleIterator} wrapping + * the specified {@link Iterator Iterator}. When + * the given iterator is null, + * returns null. + * + * @param iterator the (possibly null) + * {@link Iterator Iterator} to wrap + * @return an {@link DoubleIterator DoubleIterator} wrapping the given + * iterator, or null when iterator is + * null. + */ + public static DoubleIterator wrap(Iterator iterator) { + return null == iterator ? null : new IteratorDoubleIterator(iterator); + } + + /** + * Creates an {@link DoubleIterator DoubleIterator} wrapping + * the specified {@link Iterator Iterator}. + * @see #wrap + */ + public IteratorDoubleIterator(Iterator iterator) { + _iterator = iterator; + } + + public boolean hasNext() { + return _iterator.hasNext(); + } + + public double next() { + return ((Number)(_iterator.next())).doubleValue(); + } + + public void remove() { + _iterator.remove(); + } + + private Iterator _iterator = null; + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/ListDoubleList.java b/src/java/org/apache/commons/collections/primitives/adapters/ListDoubleList.java new file mode 100644 index 000000000..1724e1b49 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/ListDoubleList.java @@ -0,0 +1,116 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/ListDoubleList.java,v 1.1 2003/04/15 00:11:20 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.io.Serializable; +import java.util.List; + +import org.apache.commons.collections.primitives.DoubleList; + +/** + * Adapts a {@link Number}-valued {@link List List} + * to the {@link DoubleList DoubleList} interface. + *

+ * This implementation delegates most methods + * to the provided {@link List List} + * implementation in the "obvious" way. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +public class ListDoubleList extends AbstractListDoubleList implements Serializable { + + /** + * Create an {@link DoubleList DoubleList} wrapping + * the specified {@link List List}. When + * the given list is null, + * returns null. + * + * @param list the (possibly null) + * {@link List List} to wrap + * @return a {@link DoubleList DoubleList} wrapping the given + * list, or null when list is + * null. + */ + public static DoubleList wrap(List list) { + if(null == list) { + return null; + } else if(list instanceof Serializable) { + return new ListDoubleList(list); + } else { + return new NonSerializableListDoubleList(list); + } + } + + /** + * Creates an {@link DoubleList DoubleList} wrapping + * the specified {@link List List}. + * @see #wrap + */ + public ListDoubleList(List list) { + _list = list; + } + + protected List getList() { + return _list; + } + + private List _list = null; + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/ListIteratorDoubleListIterator.java b/src/java/org/apache/commons/collections/primitives/adapters/ListIteratorDoubleListIterator.java new file mode 100644 index 000000000..13d578641 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/ListIteratorDoubleListIterator.java @@ -0,0 +1,141 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/ListIteratorDoubleListIterator.java,v 1.1 2003/04/15 00:11:20 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.ListIterator; + +import org.apache.commons.collections.primitives.DoubleListIterator; + +/** + * Adapts a {@link Number}-valued {@link ListIterator ListIterator} + * to the {@link DoubleListIterator DoubleListIterator} interface. + *

+ * This implementation delegates most methods + * to the provided {@link DoubleListIterator DoubleListIterator} + * implementation in the "obvious" way. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +public class ListIteratorDoubleListIterator implements DoubleListIterator { + + /** + * Create an {@link DoubleListIterator DoubleListIterator} wrapping + * the specified {@link ListIterator ListIterator}. When + * the given iterator is null, + * returns null. + * + * @param iterator the (possibly null) + * {@link ListIterator ListIterator} to wrap + * @return an {@link DoubleListIterator DoubleListIterator} wrapping the given + * iterator, or null when iterator is + * null. + */ + public static DoubleListIterator wrap(ListIterator iterator) { + return null == iterator ? null : new ListIteratorDoubleListIterator(iterator); + } + + /** + * Creates an {@link DoubleListIterator DoubleListIterator} wrapping + * the specified {@link ListIterator ListIterator}. + * @see #wrap + */ + public ListIteratorDoubleListIterator(ListIterator iterator) { + _iterator = iterator; + } + + public int nextIndex() { + return _iterator.nextIndex(); + } + + public int previousIndex() { + return _iterator.previousIndex(); + } + + public boolean hasNext() { + return _iterator.hasNext(); + } + + public boolean hasPrevious() { + return _iterator.hasPrevious(); + } + + public double next() { + return ((Number)_iterator.next()).doubleValue(); + } + + public double previous() { + return ((Number)_iterator.previous()).doubleValue(); + } + + public void add(double element) { + _iterator.add(new Double(element)); + } + + public void set(double element) { + _iterator.set(new Double(element)); + } + + public void remove() { + _iterator.remove(); + } + + private ListIterator _iterator = null; + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCollectionDoubleCollection.java b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCollectionDoubleCollection.java new file mode 100644 index 000000000..c97da9027 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCollectionDoubleCollection.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/NonSerializableCollectionDoubleCollection.java,v 1.1 2003/04/15 00:11:20 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/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +final class NonSerializableCollectionDoubleCollection extends AbstractCollectionDoubleCollection { + public NonSerializableCollectionDoubleCollection(Collection collection) { + _collection = collection; + } + + protected Collection getCollection() { + return _collection; + } + + private Collection _collection = null; + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableDoubleCollectionCollection.java b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableDoubleCollectionCollection.java new file mode 100644 index 000000000..8aacbeb19 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableDoubleCollectionCollection.java @@ -0,0 +1,82 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/NonSerializableDoubleCollectionCollection.java,v 1.1 2003/04/15 00:11:20 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 org.apache.commons.collections.primitives.DoubleCollection; + +/** + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +final class NonSerializableDoubleCollectionCollection extends AbstractDoubleCollectionCollection { + + /** + * Creates a {@link Collection Collection} wrapping + * the specified {@link DoubleCollection DoubleCollection}. + */ + public NonSerializableDoubleCollectionCollection(DoubleCollection collection) { + _collection = collection; + } + + protected DoubleCollection getDoubleCollection() { + return _collection; + } + + private DoubleCollection _collection = null; +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableDoubleListList.java b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableDoubleListList.java new file mode 100644 index 000000000..d7bef888b --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableDoubleListList.java @@ -0,0 +1,83 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/NonSerializableDoubleListList.java,v 1.1 2003/04/15 00:11:20 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 org.apache.commons.collections.primitives.DoubleList; + +/** + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +final class NonSerializableDoubleListList extends AbstractDoubleListList { + + /** + * Creates a {@link List List} wrapping + * the specified {@link DoubleList DoubleList}. + */ + public NonSerializableDoubleListList(DoubleList list) { + _list = list; + } + + protected DoubleList getDoubleList() { + return _list; + } + + private DoubleList _list = null; + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableListDoubleList.java b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableListDoubleList.java new file mode 100644 index 000000000..ad6025a28 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableListDoubleList.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/NonSerializableListDoubleList.java,v 1.1 2003/04/15 00:11:20 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/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +final class NonSerializableListDoubleList extends AbstractListDoubleList { + + protected NonSerializableListDoubleList(List list) { + _list = list; + } + + protected List getList() { + return _list; + } + + private List _list = null; + +} diff --git a/src/test/org/apache/commons/collections/primitives/TestAbstractDoubleCollection.java b/src/test/org/apache/commons/collections/primitives/TestAbstractDoubleCollection.java new file mode 100644 index 000000000..97564c94b --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/TestAbstractDoubleCollection.java @@ -0,0 +1,113 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestAbstractDoubleCollection.java,v 1.1 2003/04/15 00:11:20 rwaldhoff Exp $ + * ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002-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; + +import java.util.Collections; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.apache.commons.collections.primitives.adapters.IteratorDoubleIterator; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +public class TestAbstractDoubleCollection extends TestCase { + + // conventional + // ------------------------------------------------------------------------ + + public TestAbstractDoubleCollection(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestAbstractDoubleCollection.class); + } + + // tests + // ------------------------------------------------------------------------ + + public void testAddIsUnsupportedByDefault() { + DoubleCollection col = new DoubleCollectionImpl(); + try { + col.add((double)1); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) { + // expected + } + } + // inner classes + // ------------------------------------------------------------------------ + + + static class DoubleCollectionImpl extends AbstractDoubleCollection { + public DoubleCollectionImpl() { + } + + public DoubleIterator iterator() { + return new IteratorDoubleIterator(Collections.EMPTY_LIST.iterator()); + } + + public int size() { + return 0; + } + } +} \ No newline at end of file diff --git a/src/test/org/apache/commons/collections/primitives/TestAll.java b/src/test/org/apache/commons/collections/primitives/TestAll.java index 3b3c72673..9c5e40fc8 100644 --- a/src/test/org/apache/commons/collections/primitives/TestAll.java +++ b/src/test/org/apache/commons/collections/primitives/TestAll.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/TestAll.java,v 1.15 2003/04/13 22:30:56 rwaldhoff Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestAll.java,v 1.16 2003/04/15 00:11:20 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * @@ -62,7 +62,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; /** - * @version $Revision: 1.15 $ $Date: 2003/04/13 22:30:56 $ + * @version $Revision: 1.16 $ $Date: 2003/04/15 00:11:20 $ * @author Rodney Waldhoff */ public class TestAll extends TestCase { @@ -97,6 +97,10 @@ public class TestAll extends TestCase { suite.addTest(TestRandomAccessFloatList.suite()); suite.addTest(TestArrayFloatList.suite()); + suite.addTest(TestAbstractDoubleCollection.suite()); + suite.addTest(TestRandomAccessDoubleList.suite()); + suite.addTest(TestArrayDoubleList.suite()); + suite.addTest(org.apache.commons.collections.primitives.adapters.TestAll.suite()); suite.addTest(TestUnsignedByteArrayList.suite()); diff --git a/src/test/org/apache/commons/collections/primitives/TestArrayDoubleList.java b/src/test/org/apache/commons/collections/primitives/TestArrayDoubleList.java new file mode 100644 index 000000000..9089c9a20 --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/TestArrayDoubleList.java @@ -0,0 +1,222 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestArrayDoubleList.java,v 1.1 2003/04/15 00:11:20 rwaldhoff Exp $ + * ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002-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; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.collections.BulkTest; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +public class TestArrayDoubleList extends TestDoubleList { + + // conventional + // ------------------------------------------------------------------------ + + public TestArrayDoubleList(String testName) { + super(testName); + } + + public static Test suite() { + TestSuite suite = BulkTest.makeSuite(TestArrayDoubleList.class); + return suite; + } + + // collections testing framework + // ------------------------------------------------------------------------ + + protected DoubleList makeEmptyDoubleList() { + return new ArrayDoubleList(); + } + + public String[] ignoredSimpleTests() { + // sublists are not serializable + return new String[] { + "TestArrayDoubleList.bulkTestSubList.testFullListSerialization", + "TestArrayDoubleList.bulkTestSubList.testEmptyListSerialization", + "TestArrayDoubleList.bulkTestSubList.testCanonicalEmptyCollectionExists", + "TestArrayDoubleList.bulkTestSubList.testCanonicalFullCollectionExists", + "TestArrayDoubleList.bulkTestSubList.testEmptyListCompatibility", + "TestArrayDoubleList.bulkTestSubList.testFullListCompatibility", + "TestArrayDoubleList.bulkTestSubList.testSerializeDeserializeThenCompare", + "TestArrayDoubleList.bulkTestSubList.testSimpleSerialization" + }; + } + + // tests + // ------------------------------------------------------------------------ + + /** @TODO need to add serialized form to cvs */ + public void testCanonicalEmptyCollectionExists() { + // XXX FIX ME XXX + // need to add a serialized form to cvs + } + + public void testCanonicalFullCollectionExists() { + // XXX FIX ME XXX + // need to add a serialized form to cvs + } + + public void testEmptyListCompatibility() { + // XXX FIX ME XXX + // need to add a serialized form to cvs + } + + public void testFullListCompatibility() { + // XXX FIX ME XXX + // need to add a serialized form to cvs + } + + public void testAddGetLargeValues() { + DoubleList list = new ArrayDoubleList(); + for (int i = 0; i < 1000; i++) { + double value = ((double) (Double.MAX_VALUE)); + value -= i; + list.add(value); + } + for (int i = 0; i < 1000; i++) { + double value = ((double) (Double.MAX_VALUE)); + value -= i; + assertEquals(value, list.get(i), 0f); + } + } + + public void testZeroInitialCapacityIsValid() { + ArrayDoubleList list = new ArrayDoubleList(0); + } + + public void testNegativeInitialCapacityIsInvalid() { + try { + ArrayDoubleList list = new ArrayDoubleList(-1); + fail("Expected IllegalArgumentException"); + } catch(IllegalArgumentException e) { + // expected + } + } + + public void testCopyConstructor() { + ArrayDoubleList expected = new ArrayDoubleList(); + for(int i=0;i<10;i++) { + expected.add((double)i); + } + ArrayDoubleList list = new ArrayDoubleList(expected); + assertEquals(10,list.size()); + assertEquals(expected,list); + } + + public void testCopyConstructorWithNull() { + try { + ArrayDoubleList list = new ArrayDoubleList(null); + fail("Expected NullPointerException"); + } catch(NullPointerException e) { + // expected + } + } + + + public void testTrimToSize() { + ArrayDoubleList list = new ArrayDoubleList(); + for(int j=0;j<3;j++) { + assertTrue(list.isEmpty()); + + list.trimToSize(); + + assertTrue(list.isEmpty()); + + for(int i=0;i<10;i++) { + list.add((double)i); + } + + for(int i=0;i<10;i++) { + assertEquals((double)i,list.get(i), 0f); + } + + list.trimToSize(); + + for(int i=0;i<10;i++) { + assertEquals((double)i,list.get(i), 0f); + } + + for(int i=0;i<10;i+=2) { + list.removeElement((double)i); + } + + for(int i=0;i<5;i++) { + assertEquals((double)(2*i)+1,list.get(i), 0f); + } + + list.trimToSize(); + + for(int i=0;i<5;i++) { + assertEquals((double)(2*i)+1,list.get(i), 0f); + } + + list.trimToSize(); + + for(int i=0;i<5;i++) { + assertEquals((double)(2*i)+1,list.get(i), 0f); + } + + list.clear(); + } + } + +} diff --git a/src/test/org/apache/commons/collections/primitives/TestDoubleIterator.java b/src/test/org/apache/commons/collections/primitives/TestDoubleIterator.java new file mode 100644 index 000000000..ffc921eaa --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/TestDoubleIterator.java @@ -0,0 +1,157 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestDoubleIterator.java,v 1.1 2003/04/15 00:11:20 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; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +import org.apache.commons.collections.iterators.TestIterator; +import org.apache.commons.collections.primitives.adapters.DoubleIteratorIterator; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +public abstract class TestDoubleIterator extends TestIterator { + + // conventional + // ------------------------------------------------------------------------ + + public TestDoubleIterator(String testName) { + super(testName); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + protected Object makeObject() { + return makeFullIterator(); + } + + public Iterator makeEmptyIterator() { + return DoubleIteratorIterator.wrap(makeEmptyDoubleIterator()); + } + + public Iterator makeFullIterator() { + return DoubleIteratorIterator.wrap(makeFullDoubleIterator()); + } + + + protected abstract DoubleIterator makeEmptyDoubleIterator(); + protected abstract DoubleIterator makeFullDoubleIterator(); + protected abstract double[] getFullElements(); + + // tests + // ------------------------------------------------------------------------ + + public void testNextHasNextRemove() { + double[] elements = getFullElements(); + DoubleIterator iter = makeFullDoubleIterator(); + for(int i=0;i. + * + */ + +package org.apache.commons.collections.primitives; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.collections.TestList; +import org.apache.commons.collections.primitives.adapters.DoubleListList; +import org.apache.commons.collections.primitives.adapters.ListDoubleList; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +public abstract class TestDoubleList extends TestList { + + // conventional + // ------------------------------------------------------------------------ + + public TestDoubleList(String testName) { + super(testName); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + // collections testing framework: double list + // ------------------------------------------------------------------------ + + protected abstract DoubleList makeEmptyDoubleList(); + + protected DoubleList makeFullDoubleList() { + DoubleList list = makeEmptyDoubleList(); + double[] values = getFullDoubles(); + for(int i=0;i>> 32))); + } + assertEquals(hash,list.hashCode()); + } + + public void testEqualsWithTwoDoubleLists() { + DoubleList one = makeEmptyDoubleList(); + assertEquals("Equals is reflexive on empty list",one,one); + DoubleList two = makeEmptyDoubleList(); + assertEquals("Empty lists are equal",one,two); + assertEquals("Equals is symmetric on empty lists",two,one); + + one.add((double)1); + assertEquals("Equals is reflexive on non empty list",one,one); + assertTrue(!one.equals(two)); + assertTrue(!two.equals(one)); + + two.add((double)1); + assertEquals("Non empty lists are equal",one,two); + assertEquals("Equals is symmetric on non empty list",one,two); + + one.add((double)1); one.add((double)2); one.add((double)3); one.add((double)5); one.add((double)8); + assertEquals("Equals is reflexive on larger non empty list",one,one); + assertTrue(!one.equals(two)); + assertTrue(!two.equals(one)); + + two.add((double)1); two.add((double)2); two.add((double)3); two.add((double)5); two.add((double)8); + assertEquals("Larger non empty lists are equal",one,two); + assertEquals("Equals is symmetric on larger non empty list",two,one); + + one.add((double)9); + two.add((double)10); + assertTrue(!one.equals(two)); + assertTrue(!two.equals(one)); + + } + + public void testDoubleSubListEquals() { + DoubleList one = makeEmptyDoubleList(); + assertEquals(one,one.subList(0,0)); + assertEquals(one.subList(0,0),one); + + one.add((double)1); + assertEquals(one,one.subList(0,1)); + assertEquals(one.subList(0,1),one); + + one.add((double)1); one.add((double)2); one.add((double)3); one.add((double)5); one.add((double)8); + assertEquals(one.subList(0,4),one.subList(0,4)); + assertEquals(one.subList(3,5),one.subList(3,5)); + } + + public void testEqualsWithDoubleListAndList() { + DoubleList ilist = makeEmptyDoubleList(); + List list = new ArrayList(); + + assertTrue("Unwrapped, empty List should not be equal to empty DoubleList.",!ilist.equals(list)); + assertTrue("Unwrapped, empty DoubleList should not be equal to empty List.",!list.equals(ilist)); + + assertEquals(new ListDoubleList(list),ilist); + assertEquals(ilist,new ListDoubleList(list)); + assertEquals(new DoubleListList(ilist),list); + assertEquals(list,new DoubleListList(ilist)); + + ilist.add((double)1); + list.add(new Double((double)1)); + + assertTrue("Unwrapped, non-empty List is not equal to non-empty DoubleList.",!ilist.equals(list)); + assertTrue("Unwrapped, non-empty DoubleList is not equal to non-empty List.",!list.equals(ilist)); + + assertEquals(new ListDoubleList(list),ilist); + assertEquals(ilist,new ListDoubleList(list)); + assertEquals(new DoubleListList(ilist),list); + assertEquals(list,new DoubleListList(ilist)); + + ilist.add((double)1); ilist.add((double)2); ilist.add((double)3); ilist.add((double)5); ilist.add((double)8); + list.add(new Double((double)1)); list.add(new Double((double)2)); list.add(new Double((double)3)); list.add(new Double((double)5)); list.add(new Double((double)8)); + + assertTrue("Unwrapped, non-empty List is not equal to non-empty DoubleList.",!ilist.equals(list)); + assertTrue("Unwrapped, non-empty DoubleList is not equal to non-empty List.",!list.equals(ilist)); + + assertEquals(new ListDoubleList(list),ilist); + assertEquals(ilist,new ListDoubleList(list)); + assertEquals(new DoubleListList(ilist),list); + assertEquals(list,new DoubleListList(ilist)); + + } + + public void testClearAndSize() { + DoubleList list = makeEmptyDoubleList(); + assertEquals(0, list.size()); + for(int i = 0; i < 100; i++) { + list.add((double)i); + } + assertEquals(100, list.size()); + list.clear(); + assertEquals(0, list.size()); + } + + public void testRemoveViaSubList() { + DoubleList list = makeEmptyDoubleList(); + for(int i = 0; i < 100; i++) { + list.add((double)i); + } + DoubleList sub = list.subList(25,75); + assertEquals(50,sub.size()); + for(int i = 0; i < 50; i++) { + assertEquals(100-i,list.size()); + assertEquals(50-i,sub.size()); + assertEquals((double)(25+i),sub.removeElementAt(0), 0f); + assertEquals(50-i-1,sub.size()); + assertEquals(100-i-1,list.size()); + } + assertEquals(0,sub.size()); + assertEquals(50,list.size()); + } + + public void testAddGet() { + DoubleList list = makeEmptyDoubleList(); + for (int i = 0; i < 255; i++) { + list.add((double)i); + } + for (int i = 0; i < 255; i++) { + assertEquals((double)i, list.get(i), 0f); + } + } + + public void testAddAndShift() { + DoubleList list = makeEmptyDoubleList(); + list.add(0, (double)1); + assertEquals("Should have one entry", 1, list.size()); + list.add((double)3); + list.add((double)4); + list.add(1, (double)2); + for(int i = 0; i < 4; i++) { + assertEquals("Should get entry back", (double)(i + 1), list.get(i), 0f); + } + list.add(0, (double)0); + for (int i = 0; i < 5; i++) { + assertEquals("Should get entry back", (double)i, list.get(i), 0f); + } + } + + public void testIsSerializable() throws Exception { + DoubleList list = makeFullDoubleList(); + assertTrue(list instanceof Serializable); + byte[] ser = writeExternalFormToBytes((Serializable)list); + DoubleList deser = (DoubleList)(readExternalFormFromBytes(ser)); + assertEquals(list,deser); + assertEquals(deser,list); + } + + public void testDoubleListSerializeDeserializeThenCompare() throws Exception { + DoubleList list = makeFullDoubleList(); + if(list instanceof Serializable) { + byte[] ser = writeExternalFormToBytes((Serializable)list); + DoubleList deser = (DoubleList)(readExternalFormFromBytes(ser)); + assertEquals("obj != deserialize(serialize(obj))",list,deser); + } + } + + public void testSubListsAreNotSerializable() throws Exception { + DoubleList list = makeFullDoubleList().subList(2,3); + assertTrue( ! (list instanceof Serializable) ); + } + + public void testSubListOutOfBounds() throws Exception { + try { + makeEmptyDoubleList().subList(2,3); + fail("Expected IndexOutOfBoundsException"); + } catch(IndexOutOfBoundsException e) { + // expected + } + + try { + makeFullDoubleList().subList(-1,3); + fail("Expected IndexOutOfBoundsException"); + } catch(IndexOutOfBoundsException e) { + // expected + } + + + try { + makeFullDoubleList().subList(5,2); + fail("Expected IllegalArgumentException"); + } catch(IllegalArgumentException e) { + // expected + } + + try { + makeFullDoubleList().subList(2,makeFullDoubleList().size()+2); + fail("Expected IndexOutOfBoundsException"); + } catch(IndexOutOfBoundsException e) { + // expected + } + } + + public void testListIteratorOutOfBounds() throws Exception { + try { + makeEmptyDoubleList().listIterator(2); + fail("Expected IndexOutOfBoundsException"); + } catch(IndexOutOfBoundsException e) { + // expected + } + + try { + makeFullDoubleList().listIterator(-1); + fail("Expected IndexOutOfBoundsException"); + } catch(IndexOutOfBoundsException e) { + // expected + } + + try { + makeFullDoubleList().listIterator(makeFullDoubleList().size()+2); + fail("Expected IndexOutOfBoundsException"); + } catch(IndexOutOfBoundsException e) { + // expected + } + } + + public void testListIteratorSetWithoutNext() throws Exception { + DoubleListIterator iter = makeFullDoubleList().listIterator(); + try { + iter.set((double)3); + fail("Expected IllegalStateException"); + } catch(IllegalStateException e) { + // expected + } + } + + public void testListIteratorSetAfterRemove() throws Exception { + DoubleListIterator iter = makeFullDoubleList().listIterator(); + iter.next(); + iter.remove(); + try { + iter.set((double)3); + fail("Expected IllegalStateException"); + } catch(IllegalStateException e) { + // expected + } + } + +} diff --git a/src/test/org/apache/commons/collections/primitives/TestDoubleListIterator.java b/src/test/org/apache/commons/collections/primitives/TestDoubleListIterator.java new file mode 100644 index 000000000..5204d3e3c --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/TestDoubleListIterator.java @@ -0,0 +1,91 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestDoubleListIterator.java,v 1.1 2003/04/15 00:11:20 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; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +public abstract class TestDoubleListIterator extends TestDoubleIterator { + + // conventional + // ------------------------------------------------------------------------ + + public TestDoubleListIterator(String testName) { + super(testName); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + public DoubleIterator makeEmptyDoubleIterator() { + return makeEmptyDoubleListIterator(); + } + + public DoubleIterator makeFullDoubleIterator() { + return makeFullDoubleListIterator(); + } + + public abstract DoubleListIterator makeEmptyDoubleListIterator(); + public abstract DoubleListIterator makeFullDoubleListIterator(); + + // tests + // ------------------------------------------------------------------------ + + +} diff --git a/src/test/org/apache/commons/collections/primitives/TestRandomAccessDoubleList.java b/src/test/org/apache/commons/collections/primitives/TestRandomAccessDoubleList.java new file mode 100644 index 000000000..1cd78c33c --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/TestRandomAccessDoubleList.java @@ -0,0 +1,155 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestRandomAccessDoubleList.java,v 1.1 2003/04/15 00:11:20 rwaldhoff Exp $ + * ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002-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; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:20 $ + * @author Rodney Waldhoff + */ +public class TestRandomAccessDoubleList extends TestCase { + + // conventional + // ------------------------------------------------------------------------ + + public TestRandomAccessDoubleList(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestRandomAccessDoubleList.class); + } + + // tests + // ------------------------------------------------------------------------ + + public void testAddIsUnsupportedByDefault() { + RandomAccessDoubleList list = new AbstractRandomAccessDoubleListImpl(); + try { + list.add((double)1); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) { + // expected + } + try { + list.set(0,(double)1); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) { + // expected + } + } + + public void testAddAllIsUnsupportedByDefault() { + RandomAccessDoubleList list = new AbstractRandomAccessDoubleListImpl(); + DoubleList list2 = new ArrayDoubleList(); + list2.add((double)3); + try { + list.addAll(list2); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) { + // expected + } + } + + public void testSetIsUnsupportedByDefault() { + RandomAccessDoubleList list = new AbstractRandomAccessDoubleListImpl(); + try { + list.set(0,(double)1); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) { + // expected + } + } + + public void testRemoveElementIsUnsupportedByDefault() { + RandomAccessDoubleList list = new AbstractRandomAccessDoubleListImpl(); + try { + list.removeElementAt(0); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) { + // expected + } + } + + // inner classes + // ------------------------------------------------------------------------ + + + static class AbstractRandomAccessDoubleListImpl extends RandomAccessDoubleList { + public AbstractRandomAccessDoubleListImpl() { + } + + /** + * @see org.apache.commons.collections.primitives.DoubleList#get(int) + */ + public double get(int index) { + throw new IndexOutOfBoundsException(); + } + + /** + * @see org.apache.commons.collections.primitives.DoubleCollection#size() + */ + public int size() { + return 0; + } + + } +} diff --git a/src/test/org/apache/commons/collections/primitives/adapters/TestAll.java b/src/test/org/apache/commons/collections/primitives/adapters/TestAll.java index 2c61311a8..857e8880a 100644 --- a/src/test/org/apache/commons/collections/primitives/adapters/TestAll.java +++ b/src/test/org/apache/commons/collections/primitives/adapters/TestAll.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/TestAll.java,v 1.5 2003/04/13 22:08:07 rwaldhoff Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/adapters/Attic/TestAll.java,v 1.6 2003/04/15 00:11:19 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * @@ -62,7 +62,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; /** - * @version $Revision: 1.5 $ $Date: 2003/04/13 22:08:07 $ + * @version $Revision: 1.6 $ $Date: 2003/04/15 00:11:19 $ * @author Rodney Waldhoff */ public class TestAll extends TestCase { @@ -114,6 +114,15 @@ public class TestAll extends TestCase { suite.addTest(TestFloatIteratorIterator.suite()); suite.addTest(TestFloatListIteratorListIterator.suite()); + suite.addTest(TestCollectionDoubleCollection.suite()); + suite.addTest(TestDoubleCollectionCollection.suite()); + suite.addTest(TestDoubleListList.suite()); + suite.addTest(TestListDoubleList.suite()); + suite.addTest(TestIteratorDoubleIterator.suite()); + suite.addTest(TestListIteratorDoubleListIterator.suite()); + suite.addTest(TestDoubleIteratorIterator.suite()); + suite.addTest(TestDoubleListIteratorListIterator.suite()); + return suite; } } diff --git a/src/test/org/apache/commons/collections/primitives/adapters/TestCollectionDoubleCollection.java b/src/test/org/apache/commons/collections/primitives/adapters/TestCollectionDoubleCollection.java new file mode 100644 index 000000000..c4c7fd74e --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/adapters/TestCollectionDoubleCollection.java @@ -0,0 +1,136 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/adapters/Attic/TestCollectionDoubleCollection.java,v 1.1 2003/04/15 00:11:19 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.io.Serializable; +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.collections.TestObject; +import org.apache.commons.collections.primitives.DoubleCollection; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:19 $ + * @author Rodney Waldhoff + */ +public class TestCollectionDoubleCollection extends TestObject { + + // conventional + // ------------------------------------------------------------------------ + + public TestCollectionDoubleCollection(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestCollectionDoubleCollection.class); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + protected Object makeObject() { + List list = new ArrayList(); + for(int i=0;i<10;i++) { + list.add(new Double((double)i)); + } + return new CollectionDoubleCollection(list); + } + + public void testSerializeDeserializeThenCompare() { + // Collection.equal contract doesn't work that way + } + + /** @TODO need to add serialized form to cvs */ + public void testCanonicalEmptyCollectionExists() { + // XXX FIX ME XXX + // need to add a serialized form to cvs + } + + public void testCanonicalFullCollectionExists() { + // XXX FIX ME XXX + // need to add a serialized form to cvs + } + + // tests + // ------------------------------------------------------------------------ + + public void testWrapNull() { + assertNull(CollectionDoubleCollection.wrap(null)); + } + + public void testWrapSerializable() { + DoubleCollection collection = CollectionDoubleCollection.wrap(new ArrayList()); + assertNotNull(collection); + assertTrue(collection instanceof Serializable); + } + + public void testWrapNonSerializable() { + DoubleCollection collection = CollectionDoubleCollection.wrap(new AbstractList() { + public Object get(int i) { throw new IndexOutOfBoundsException(); } + public int size() { return 0; } + }); + assertNotNull(collection); + assertTrue(!(collection instanceof Serializable)); + } + +} diff --git a/src/test/org/apache/commons/collections/primitives/adapters/TestDoubleCollectionCollection.java b/src/test/org/apache/commons/collections/primitives/adapters/TestDoubleCollectionCollection.java new file mode 100644 index 000000000..c8ff0c25c --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/adapters/TestDoubleCollectionCollection.java @@ -0,0 +1,136 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/adapters/Attic/TestDoubleCollectionCollection.java,v 1.1 2003/04/15 00:11:19 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.io.Serializable; +import java.util.Collection; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.collections.TestObject; +import org.apache.commons.collections.primitives.RandomAccessDoubleList; +import org.apache.commons.collections.primitives.ArrayDoubleList; +import org.apache.commons.collections.primitives.DoubleList; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:19 $ + * @author Rodney Waldhoff + */ +public class TestDoubleCollectionCollection extends TestObject { + + // conventional + // ------------------------------------------------------------------------ + + public TestDoubleCollectionCollection(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestDoubleCollectionCollection.class); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + protected Object makeObject() { + DoubleList list = new ArrayDoubleList(); + for(int i=0;i<10;i++) { + list.add((double)i); + } + return new DoubleCollectionCollection(list); + } + + public void testSerializeDeserializeThenCompare() { + // Collection.equal contract doesn't work that way + } + + /** @TODO need to add serialized form to cvs */ + public void testCanonicalEmptyCollectionExists() { + // XXX FIX ME XXX + // need to add a serialized form to cvs + } + + public void testCanonicalFullCollectionExists() { + // XXX FIX ME XXX + // need to add a serialized form to cvs + } + + // tests + // ------------------------------------------------------------------------ + + public void testWrapNull() { + assertNull(DoubleCollectionCollection.wrap(null)); + } + + public void testWrapSerializable() { + Collection collection = DoubleCollectionCollection.wrap(new ArrayDoubleList()); + assertNotNull(collection); + assertTrue(collection instanceof Serializable); + } + + public void testWrapNonSerializable() { + Collection collection = DoubleCollectionCollection.wrap(new RandomAccessDoubleList() { + public double get(int i) { throw new IndexOutOfBoundsException(); } + public int size() { return 0; } + }); + assertNotNull(collection); + assertTrue(!(collection instanceof Serializable)); + } + +} diff --git a/src/test/org/apache/commons/collections/primitives/adapters/TestDoubleIteratorIterator.java b/src/test/org/apache/commons/collections/primitives/adapters/TestDoubleIteratorIterator.java new file mode 100644 index 000000000..41679fadf --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/adapters/TestDoubleIteratorIterator.java @@ -0,0 +1,122 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/adapters/Attic/TestDoubleIteratorIterator.java,v 1.1 2003/04/15 00:11:19 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.Iterator; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.collections.iterators.TestIterator; +import org.apache.commons.collections.primitives.ArrayDoubleList; +import org.apache.commons.collections.primitives.DoubleList; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:19 $ + * @author Rodney Waldhoff + */ +public class TestDoubleIteratorIterator extends TestIterator { + + // conventional + // ------------------------------------------------------------------------ + + public TestDoubleIteratorIterator(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestDoubleIteratorIterator.class); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + public Object makeObject() { + return makeFullIterator(); + } + + public Iterator makeEmptyIterator() { + return DoubleIteratorIterator.wrap(makeEmptyDoubleList().iterator()); + } + + public Iterator makeFullIterator() { + return DoubleIteratorIterator.wrap(makeFullDoubleList().iterator()); + } + + protected DoubleList makeEmptyDoubleList() { + return new ArrayDoubleList(); + } + + protected DoubleList makeFullDoubleList() { + DoubleList list = makeEmptyDoubleList(); + double[] elts = getFullElements(); + for(int i=0;i. + * + */ + +package org.apache.commons.collections.primitives.adapters; + +import java.util.Iterator; +import java.util.ListIterator; +import java.util.NoSuchElementException; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.collections.iterators.TestListIterator; +import org.apache.commons.collections.primitives.ArrayDoubleList; +import org.apache.commons.collections.primitives.DoubleList; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:19 $ + * @author Rodney Waldhoff + */ +public class TestDoubleListIteratorListIterator extends TestListIterator { + + // conventional + // ------------------------------------------------------------------------ + + public TestDoubleListIteratorListIterator(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestDoubleListIteratorListIterator.class); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + public Object makeObject() { + return makeFullIterator(); + } + + public ListIterator makeEmptyListIterator() { + return DoubleListIteratorListIterator.wrap(makeEmptyDoubleList().listIterator()); + } + + public ListIterator makeFullListIterator() { + return DoubleListIteratorListIterator.wrap(makeFullDoubleList().listIterator()); + } + + protected DoubleList makeEmptyDoubleList() { + return new ArrayDoubleList(); + } + + protected DoubleList makeFullDoubleList() { + DoubleList list = makeEmptyDoubleList(); + double[] elts = getFullElements(); + for(int i=0;i. + * + */ + +package org.apache.commons.collections.primitives.adapters; + +import java.io.Serializable; +import java.util.List; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.collections.BulkTest; +import org.apache.commons.collections.TestList; +import org.apache.commons.collections.primitives.RandomAccessDoubleList; +import org.apache.commons.collections.primitives.ArrayDoubleList; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:19 $ + * @author Rodney Waldhoff + */ +public class TestDoubleListList extends TestList { + + // conventional + // ------------------------------------------------------------------------ + + public TestDoubleListList(String testName) { + super(testName); + } + + public static Test suite() { + TestSuite suite = BulkTest.makeSuite(TestDoubleListList.class); + return suite; + } + + // collections testing framework + // ------------------------------------------------------------------------ + + protected List makeEmptyList() { + return new DoubleListList(new ArrayDoubleList()); + } + + protected Object[] getFullElements() { + Double[] elts = new Double[10]; + for(int i=0;i. + * + */ + +package org.apache.commons.collections.primitives.adapters; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.collections.primitives.DoubleIterator; +import org.apache.commons.collections.primitives.TestDoubleIterator; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:19 $ + * @author Rodney Waldhoff + */ +public class TestIteratorDoubleIterator extends TestDoubleIterator { + + // conventional + // ------------------------------------------------------------------------ + + public TestIteratorDoubleIterator(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestIteratorDoubleIterator.class); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + public DoubleIterator makeEmptyDoubleIterator() { + return IteratorDoubleIterator.wrap(makeEmptyList().iterator()); + } + + public DoubleIterator makeFullDoubleIterator() { + return IteratorDoubleIterator.wrap(makeFullList().iterator()); + } + + protected List makeEmptyList() { + return new ArrayList(); + } + + protected List makeFullList() { + List list = makeEmptyList(); + double[] elts = getFullElements(); + for(int i=0;i. + * + */ + +package org.apache.commons.collections.primitives.adapters; + +import java.io.Serializable; +import java.util.AbstractList; +import java.util.ArrayList; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.collections.BulkTest; +import org.apache.commons.collections.primitives.DoubleList; +import org.apache.commons.collections.primitives.TestDoubleList; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:19 $ + * @author Rodney Waldhoff + */ +public class TestListDoubleList extends TestDoubleList { + + // conventional + // ------------------------------------------------------------------------ + + public TestListDoubleList(String testName) { + super(testName); + } + + public static Test suite() { + TestSuite suite = BulkTest.makeSuite(TestListDoubleList.class); + return suite; + } + + // collections testing framework + // ------------------------------------------------------------------------ + + /** + * @see org.apache.commons.collections.primitives.TestDoubleList#makeEmptyDoubleList() + */ + protected DoubleList makeEmptyDoubleList() { + return new ListDoubleList(new ArrayList()); + } + + public String[] ignoredSimpleTests() { + // sublists are not serializable + return new String[] { + "TestListDoubleList.bulkTestSubList.testFullListSerialization", + "TestListDoubleList.bulkTestSubList.testEmptyListSerialization", + "TestListDoubleList.bulkTestSubList.testCanonicalEmptyCollectionExists", + "TestListDoubleList.bulkTestSubList.testCanonicalFullCollectionExists", + "TestListDoubleList.bulkTestSubList.testEmptyListCompatibility", + "TestListDoubleList.bulkTestSubList.testFullListCompatibility", + "TestListDoubleList.bulkTestSubList.testSerializeDeserializeThenCompare", + "TestListDoubleList.bulkTestSubList.testSimpleSerialization" + }; + } + + // tests + // ------------------------------------------------------------------------ + + /** @TODO need to add serialized form to cvs */ + public void testCanonicalEmptyCollectionExists() { + // XXX FIX ME XXX + // need to add a serialized form to cvs + } + + public void testCanonicalFullCollectionExists() { + // XXX FIX ME XXX + // need to add a serialized form to cvs + } + + public void testEmptyListCompatibility() { + // XXX FIX ME XXX + // need to add a serialized form to cvs + } + + public void testFullListCompatibility() { + // XXX FIX ME XXX + // need to add a serialized form to cvs + } + public void testWrapNull() { + assertNull(ListDoubleList.wrap(null)); + } + + public void testWrapSerializable() { + DoubleList list = ListDoubleList.wrap(new ArrayList()); + assertNotNull(list); + assertTrue(list instanceof Serializable); + } + + public void testWrapNonSerializable() { + DoubleList list = ListDoubleList.wrap(new AbstractList() { + public Object get(int i) { throw new IndexOutOfBoundsException(); } + public int size() { return 0; } + }); + assertNotNull(list); + assertTrue(!(list instanceof Serializable)); + } + +} diff --git a/src/test/org/apache/commons/collections/primitives/adapters/TestListIteratorDoubleListIterator.java b/src/test/org/apache/commons/collections/primitives/adapters/TestListIteratorDoubleListIterator.java new file mode 100644 index 000000000..98e67a8e7 --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/adapters/TestListIteratorDoubleListIterator.java @@ -0,0 +1,118 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/adapters/Attic/TestListIteratorDoubleListIterator.java,v 1.1 2003/04/15 00:11:19 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.ArrayList; +import java.util.List; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.collections.primitives.DoubleListIterator; +import org.apache.commons.collections.primitives.TestDoubleListIterator; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/15 00:11:19 $ + * @author Rodney Waldhoff + */ +public class TestListIteratorDoubleListIterator extends TestDoubleListIterator { + + // conventional + // ------------------------------------------------------------------------ + + public TestListIteratorDoubleListIterator(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestListIteratorDoubleListIterator.class); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + public DoubleListIterator makeEmptyDoubleListIterator() { + return ListIteratorDoubleListIterator.wrap(makeEmptyList().listIterator()); + } + + public DoubleListIterator makeFullDoubleListIterator() { + return ListIteratorDoubleListIterator.wrap(makeFullList().listIterator()); + } + + protected List makeEmptyList() { + return new ArrayList(); + } + + protected List makeFullList() { + List list = makeEmptyList(); + double[] elts = getFullElements(); + for(int i=0;i