From 1da41c0b711e178acd3e8843ac3d12fb33828350 Mon Sep 17 00:00:00 2001 From: Rodney Waldhoff Date: Wed, 16 Apr 2003 18:32:40 +0000 Subject: [PATCH] add char based primitive collections and tests git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131016 13f79535-47bb-0310-9956-ffa450edef68 --- .../primitives/AbstractCharCollection.java | 175 +++++++ .../collections/primitives/ArrayCharList.java | 265 +++++++++++ .../primitives/CharCollection.java | 246 ++++++++++ .../collections/primitives/CharIterator.java | 101 +++++ .../collections/primitives/CharList.java | 291 ++++++++++++ .../primitives/CharListIterator.java | 186 ++++++++ .../primitives/RandomAccessCharList.java | 429 ++++++++++++++++++ .../AbstractCharCollectionCollection.java | 154 +++++++ .../adapters/AbstractCharListList.java | 164 +++++++ .../AbstractCollectionCharCollection.java | 151 ++++++ .../adapters/AbstractListCharList.java | 161 +++++++ .../adapters/CharCollectionCollection.java | 117 +++++ .../adapters/CharIteratorIterator.java | 117 +++++ .../CharListIteratorListIterator.java | 141 ++++++ .../primitives/adapters/CharListList.java | 115 +++++ .../adapters/CollectionCharCollection.java | 114 +++++ .../adapters/IteratorCharIterator.java | 119 +++++ .../primitives/adapters/ListCharList.java | 116 +++++ .../ListIteratorCharListIterator.java | 141 ++++++ ...nSerializableCharCollectionCollection.java | 82 ++++ .../adapters/NonSerializableCharListList.java | 83 ++++ ...nSerializableCollectionCharCollection.java | 78 ++++ .../adapters/NonSerializableListCharList.java | 80 ++++ .../TestAbstractCharCollection.java | 113 +++++ .../collections/primitives/TestAll.java | 8 +- .../primitives/TestArrayCharList.java | 222 +++++++++ .../primitives/TestCharIterator.java | 157 +++++++ .../collections/primitives/TestCharList.java | 425 +++++++++++++++++ .../primitives/TestCharListIterator.java | 91 ++++ .../primitives/TestRandomAccessCharList.java | 155 +++++++ .../primitives/adapters/TestAll.java | 13 +- .../TestCharCollectionCollection.java | 136 ++++++ .../adapters/TestCharIteratorIterator.java | 122 +++++ .../TestCharListIteratorListIterator.java | 180 ++++++++ .../primitives/adapters/TestCharListList.java | 155 +++++++ .../TestCollectionCharCollection.java | 136 ++++++ .../adapters/TestIteratorCharIterator.java | 118 +++++ .../primitives/adapters/TestListCharList.java | 155 +++++++ .../TestListIteratorCharListIterator.java | 118 +++++ 39 files changed, 5926 insertions(+), 4 deletions(-) create mode 100644 src/java/org/apache/commons/collections/primitives/AbstractCharCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/ArrayCharList.java create mode 100644 src/java/org/apache/commons/collections/primitives/CharCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/CharIterator.java create mode 100644 src/java/org/apache/commons/collections/primitives/CharList.java create mode 100644 src/java/org/apache/commons/collections/primitives/CharListIterator.java create mode 100644 src/java/org/apache/commons/collections/primitives/RandomAccessCharList.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/AbstractCharCollectionCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/AbstractCharListList.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/AbstractCollectionCharCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/AbstractListCharList.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/CharCollectionCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/CharIteratorIterator.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/CharListIteratorListIterator.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/CharListList.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/CollectionCharCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/IteratorCharIterator.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/ListCharList.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/ListIteratorCharListIterator.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCharCollectionCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCharListList.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCollectionCharCollection.java create mode 100644 src/java/org/apache/commons/collections/primitives/adapters/NonSerializableListCharList.java create mode 100644 src/test/org/apache/commons/collections/primitives/TestAbstractCharCollection.java create mode 100644 src/test/org/apache/commons/collections/primitives/TestArrayCharList.java create mode 100644 src/test/org/apache/commons/collections/primitives/TestCharIterator.java create mode 100644 src/test/org/apache/commons/collections/primitives/TestCharList.java create mode 100644 src/test/org/apache/commons/collections/primitives/TestCharListIterator.java create mode 100644 src/test/org/apache/commons/collections/primitives/TestRandomAccessCharList.java create mode 100644 src/test/org/apache/commons/collections/primitives/adapters/TestCharCollectionCollection.java create mode 100644 src/test/org/apache/commons/collections/primitives/adapters/TestCharIteratorIterator.java create mode 100644 src/test/org/apache/commons/collections/primitives/adapters/TestCharListIteratorListIterator.java create mode 100644 src/test/org/apache/commons/collections/primitives/adapters/TestCharListList.java create mode 100644 src/test/org/apache/commons/collections/primitives/adapters/TestCollectionCharCollection.java create mode 100644 src/test/org/apache/commons/collections/primitives/adapters/TestIteratorCharIterator.java create mode 100644 src/test/org/apache/commons/collections/primitives/adapters/TestListCharList.java create mode 100644 src/test/org/apache/commons/collections/primitives/adapters/TestListIteratorCharListIterator.java diff --git a/src/java/org/apache/commons/collections/primitives/AbstractCharCollection.java b/src/java/org/apache/commons/collections/primitives/AbstractCharCollection.java new file mode 100644 index 000000000..ecf35aa62 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/AbstractCharCollection.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/AbstractCharCollection.java,v 1.1 2003/04/16 18:32:39 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 CharCollection}s. + *

+ * Read-only subclasses must override {@link #iterator} + * and {@link #size}. Mutable subclasses + * should also override {@link #add} and + * {@link CharIterator#remove CharIterator.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/16 18:32:39 $ + * + * @author Rodney Waldhoff + */ +public abstract class AbstractCharCollection implements CharCollection { + public abstract CharIterator iterator(); + public abstract int size(); + + protected AbstractCharCollection() { } + + /** Unsupported in this base implementation. */ + public boolean add(char element) { + throw new UnsupportedOperationException("add(char) is not supported."); + } + + public boolean addAll(CharCollection c) { + boolean modified = false; + for(CharIterator iter = c.iterator(); iter.hasNext(); ) { + modified |= add(iter.next()); + } + return modified; + } + + public void clear() { + for(CharIterator iter = iterator(); iter.hasNext();) { + iter.next(); + iter.remove(); + } + } + + public boolean contains(char element) { + for(CharIterator iter = iterator(); iter.hasNext();) { + if(iter.next() == element) { + return true; + } + } + return false; + } + + public boolean containsAll(CharCollection c) { + for(CharIterator iter = c.iterator(); iter.hasNext();) { + if(!contains(iter.next())) { + return false; + } + } + return true; + } + + public boolean isEmpty() { + return (0 == size()); + } + + public boolean removeElement(char element) { + for(CharIterator iter = iterator(); iter.hasNext();) { + if(iter.next() == element) { + iter.remove(); + return true; + } + } + return false; + } + + public boolean removeAll(CharCollection c) { + boolean modified = false; + for(CharIterator iter = c.iterator(); iter.hasNext(); ) { + modified |= removeElement(iter.next()); + } + return modified; + } + + public boolean retainAll(CharCollection c) { + boolean modified = false; + for(CharIterator iter = iterator(); iter.hasNext();) { + if(!c.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + public char[] toArray() { + char[] array = new char[size()]; + int i = 0; + for(CharIterator iter = iterator(); iter.hasNext();) { + array[i] = iter.next(); + i++; + } + return array; + } + + public char[] toArray(char[] a) { + if(a.length < size()) { + return toArray(); + } else { + int i = 0; + for(CharIterator iter = iterator(); iter.hasNext();) { + a[i] = iter.next(); + i++; + } + return a; + } + } +} diff --git a/src/java/org/apache/commons/collections/primitives/ArrayCharList.java b/src/java/org/apache/commons/collections/primitives/ArrayCharList.java new file mode 100644 index 000000000..ce80f1954 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/ArrayCharList.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/ArrayCharList.java,v 1.1 2003/04/16 18:32:39 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 CharList} backed by an array of chars. + * This implementation supports all optional methods. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:39 $ + * + * @author Rodney Waldhoff + */ +public class ArrayCharList extends RandomAccessCharList implements CharList, Serializable { + + // constructors + //------------------------------------------------------------------------- + + /** + * Construct an empty list with the default + * initial capacity. + */ + public ArrayCharList() { + this(8); + } + + /** + * Construct an empty list with the given + * initial capacity. + * @throws IllegalArgumentException when initialCapacity is negative + */ + public ArrayCharList(int initialCapacity) { + if(initialCapacity < 0) { + throw new IllegalArgumentException("capacity " + initialCapacity); + } + _data = new char[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 ArrayCharList#addAll(org.apache.commons.collections.primitives.CharCollection) + * @param that the non-null collection of chars + * to add + * @throws NullPointerException if that is null + */ + public ArrayCharList(CharCollection that) { + this(that.size()); + addAll(that); + } + + // CharList methods + //------------------------------------------------------------------------- + + public char 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 char removeElementAt(int index) { + checkRange(index); + incrModCount(); + char 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 char set(int index, char element) { + checkRange(index); + incrModCount(); + char 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, char 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; + char[] olddata = _data; + _data = new char[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) { + char[] olddata = _data; + _data = new char[_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.writeChar(_data[i]); + } + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + _data = new char[in.readInt()]; + for(int i=0;i<_size;i++) { + _data[i] = in.readChar(); + } + } + + 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 char[] _data = null; + private int _size = 0; + +} diff --git a/src/java/org/apache/commons/collections/primitives/CharCollection.java b/src/java/org/apache/commons/collections/primitives/CharCollection.java new file mode 100644 index 000000000..35ca69949 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/CharCollection.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/CharCollection.java,v 1.1 2003/04/16 18:32:39 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 char values. + * + * @see org.apache.commons.collections.primitives.adapters.CharCollectionCollection + * @see org.apache.commons.collections.primitives.adapters.CollectionCharCollection + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:39 $ + * + * @author Rodney Waldhoff + */ +public interface CharCollection { + /** + * 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(char 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(CharCollection 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(char 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(CharCollection c); + + /** + * Returns true iff I contain no elements. + * @return true iff I contain no elements. + */ + boolean isEmpty(); + + /** + * Returns an {@link CharIterator 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 CharIterator iterator} over all my elements. + */ + CharIterator 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(CharCollection 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(char 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(CharCollection 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 + */ + char[] 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 + */ + char[] toArray(char[] a); +} diff --git a/src/java/org/apache/commons/collections/primitives/CharIterator.java b/src/java/org/apache/commons/collections/primitives/CharIterator.java new file mode 100644 index 000000000..c75559359 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/CharIterator.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/CharIterator.java,v 1.1 2003/04/16 18:32:39 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 char values. + * + * @see org.apache.commons.collections.primitives.adapters.CharIteratorIterator + * @see org.apache.commons.collections.primitives.adapters.IteratorCharIterator + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:39 $ + * + * @author Rodney Waldhoff + */ +public interface CharIterator { + /** + * 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 + */ + char 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/CharList.java b/src/java/org/apache/commons/collections/primitives/CharList.java new file mode 100644 index 000000000..ade9161d5 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/CharList.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/CharList.java,v 1.1 2003/04/16 18:32:39 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 char values. + * + * @see org.apache.commons.collections.primitives.adapters.CharListList + * @see org.apache.commons.collections.primitives.adapters.ListCharList + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:39 $ + * + * @author Rodney Waldhoff + */ +public interface CharList extends CharCollection { + /** + * 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(char 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, char 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 CharCollection#iterator iterator}. + * + * @param index the index at which to insert the first element from + * the specified collection + * @param collection the {@link CharCollection CharCollection} 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, CharCollection collection); + + /** + * Returns true iff that is an CharList + * that contains the same elements in the same order as me. + * In other words, returns true iff that is + * an CharList that has the same {@link #size size} as me, + * and for which the elements returned by its + * {@link CharList#iterator iterator} are equal (==) to + * the corresponding elements within me. + * (This contract ensures that this method works properly across + * different implementations of the CharList interface.) + * + * @param that the object to compare to me + * @return true iff that is an CharList + * 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 + */ + char get(int index); + + /** + * Returns my hash code. + *

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

 int hash = 1;
+     * for(CharIterator iter = iterator(); iter.hasNext(); ) {
+     *   char 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 Char}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(char element); + + /** + * Returns an {@link CharIterator iterator} over all my elements, + * in the appropriate sequence. + * @return an {@link CharIterator iterator} over all my elements. + */ + CharIterator 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(char element); + + /** + * Returns a + * {@link CharListIterator bidirectional iterator} + * over all my elements, in the appropriate sequence. + */ + CharListIterator listIterator(); + + /** + * Returns a + * {@link CharListIterator 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 CharListIterator#next next} + * method. An initial call to the + * {@link CharListIterator#previous previous} + * method would return the element with the specified + * index minus one. + * + * @throws IndexOutOfBoundsException if the specified index is out of range + */ + CharListIterator 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 + */ + char 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 + */ + char set(int index, char element); + + /** + * Returns a view of the elements within me + * between the specified fromIndex, inclusive, and + * toIndex, exclusive. The returned CharList + * 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 + */ + CharList subList(int fromIndex, int toIndex); + +} diff --git a/src/java/org/apache/commons/collections/primitives/CharListIterator.java b/src/java/org/apache/commons/collections/primitives/CharListIterator.java new file mode 100644 index 000000000..956248c0c --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/CharListIterator.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/CharListIterator.java,v 1.1 2003/04/16 18:32:40 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 char values. + * + * @see org.apache.commons.collections.primitives.adapters.CharListIteratorListIterator + * @see org.apache.commons.collections.primitives.adapters.ListIteratorCharListIterator + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:40 $ + * + * @author Rodney Waldhoff + */ +public interface CharListIterator extends CharIterator { + /** + * 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(char 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 + */ + char 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 + */ + char 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(char element); +} diff --git a/src/java/org/apache/commons/collections/primitives/RandomAccessCharList.java b/src/java/org/apache/commons/collections/primitives/RandomAccessCharList.java new file mode 100644 index 000000000..bef26aa90 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/RandomAccessCharList.java @@ -0,0 +1,429 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/RandomAccessCharList.java,v 1.1 2003/04/16 18:32:39 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 CharList}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/16 18:32:39 $ + * + * @author Rodney Waldhoff + */ +public abstract class RandomAccessCharList extends AbstractCharCollection implements CharList { + + // constructors + //------------------------------------------------------------------------- + + /** Constructs an empty list. */ + protected RandomAccessCharList() { + } + + // fully abstract methods + //------------------------------------------------------------------------- + + public abstract char get(int index); + public abstract int size(); + + // unsupported in base + //------------------------------------------------------------------------- + + /** + * Unsupported in this implementation. + * @throws UnsupportedOperationException since this method is not supported + */ + public char removeElementAt(int index) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported in this implementation. + * @throws UnsupportedOperationException since this method is not supported + */ + public char set(int index, char element) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported in this implementation. + * @throws UnsupportedOperationException since this method is not supported + */ + public void add(int index, char element) { + throw new UnsupportedOperationException(); + } + + //------------------------------------------------------------------------- + + // javadocs here are inherited + + public boolean add(char element) { + add(size(),element); + return true; + } + + public boolean addAll(int index, CharCollection collection) { + boolean modified = false; + for(CharIterator iter = collection.iterator(); iter.hasNext(); ) { + add(index++,iter.next()); + modified = true; + } + return modified; + } + + public int indexOf(char element) { + int i = 0; + for(CharIterator iter = iterator(); iter.hasNext(); ) { + if(iter.next() == element) { + return i; + } else { + i++; + } + } + return -1; + } + + public int lastIndexOf(char element) { + for(CharListIterator iter = listIterator(size()); iter.hasPrevious(); ) { + if(iter.previous() == element) { + return iter.nextIndex(); + } + } + return -1; + } + + public CharIterator iterator() { + return listIterator(); + } + + public CharListIterator listIterator() { + return listIterator(0); + } + + public CharListIterator listIterator(int index) { + return new RandomAccessCharListIterator(this,index); + } + + public CharList subList(int fromIndex, int toIndex) { + return new RandomAccessCharSubList(this,fromIndex,toIndex); + } + + public boolean equals(Object that) { + if(this == that) { + return true; + } else if(that instanceof CharList) { + CharList thatList = (CharList)that; + if(size() != thatList.size()) { + return false; + } + for(CharIterator 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(CharIterator iter = iterator(); iter.hasNext(); ) { + hash = 31*hash + ((int)(iter.next())); + } + return hash; + } + + public String toString() { + StringBuffer buf = new StringBuffer(); + buf.append("["); + for(CharIterator 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(RandomAccessCharList source) { + _source = source; + resyncModCount(); + } + + protected RandomAccessCharList getList() { + return _source; + } + + protected void assertNotComodified() throws ConcurrentModificationException { + if(_expectedModCount != getList().getModCount()) { + throw new ConcurrentModificationException(); + } + } + + protected void resyncModCount() { + _expectedModCount = getList().getModCount(); + } + + private RandomAccessCharList _source = null; + private int _expectedModCount = -1; + } + + protected static class RandomAccessCharListIterator extends ComodChecker implements CharListIterator { + RandomAccessCharListIterator(RandomAccessCharList 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 char next() { + assertNotComodified(); + if(!hasNext()) { + throw new NoSuchElementException(); + } else { + char val = getList().get(_nextIndex); + _lastReturnedIndex = _nextIndex; + _nextIndex++; + return val; + } + } + + public char previous() { + assertNotComodified(); + if(!hasPrevious()) { + throw new NoSuchElementException(); + } else { + char val = getList().get(_nextIndex-1); + _lastReturnedIndex = _nextIndex-1; + _nextIndex--; + return val; + } + } + + public void add(char 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(char 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 RandomAccessCharSubList extends RandomAccessCharList implements CharList { + RandomAccessCharSubList(RandomAccessCharList 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 char get(int index) { + checkRange(index); + _comod.assertNotComodified(); + return _list.get(toUnderlyingIndex(index)); + } + + public char removeElementAt(int index) { + checkRange(index); + _comod.assertNotComodified(); + char val = _list.removeElementAt(toUnderlyingIndex(index)); + _limit--; + _comod.resyncModCount(); + incrModCount(); + return val; + } + + public char set(int index, char element) { + checkRange(index); + _comod.assertNotComodified(); + char val = _list.set(toUnderlyingIndex(index),element); + incrModCount(); + _comod.resyncModCount(); + return val; + } + + public void add(int index, char 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 RandomAccessCharList _list = null; + private ComodChecker _comod = null; + + } +} + diff --git a/src/java/org/apache/commons/collections/primitives/adapters/AbstractCharCollectionCollection.java b/src/java/org/apache/commons/collections/primitives/adapters/AbstractCharCollectionCollection.java new file mode 100644 index 000000000..2047ff695 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/AbstractCharCollectionCollection.java @@ -0,0 +1,154 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/AbstractCharCollectionCollection.java,v 1.1 2003/04/16 18:32:39 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.lang.reflect.Array; +import java.util.Collection; +import java.util.Iterator; + +import org.apache.commons.collections.primitives.CharCollection; + +/** + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:39 $ + * @author Rodney Waldhoff + */ +abstract class AbstractCharCollectionCollection implements Collection { + + public boolean add(Object element) { + return getCharCollection().add(((Character)element).charValue()); + } + + public boolean addAll(Collection c) { + return getCharCollection().addAll(CollectionCharCollection.wrap(c)); + } + + public void clear() { + getCharCollection().clear(); + } + + public boolean contains(Object element) { + return getCharCollection().contains(((Character)element).charValue()); + } + + + public boolean containsAll(Collection c) { + return getCharCollection().containsAll(CollectionCharCollection.wrap(c)); + } + + public String toString() { + return getCharCollection().toString(); + } + + public boolean isEmpty() { + return getCharCollection().isEmpty(); + } + + /** + * {@link CharIteratorIterator#wrap wraps} the + * {@link org.apache.commons.collections.primitives.CharIterator CharIterator} + * returned by my underlying + * {@link CharCollection CharCollection}, + * if any. + */ + public Iterator iterator() { + return CharIteratorIterator.wrap(getCharCollection().iterator()); + } + + public boolean remove(Object element) { + return getCharCollection().removeElement(((Character)element).charValue()); + } + + public boolean removeAll(Collection c) { + return getCharCollection().removeAll(CollectionCharCollection.wrap(c)); + } + + public boolean retainAll(Collection c) { + return getCharCollection().retainAll(CollectionCharCollection.wrap(c)); + } + + public int size() { + return getCharCollection().size(); + } + + public Object[] toArray() { + char[] a = getCharCollection().toArray(); + Object[] A = new Object[a.length]; + for(int i=0;i a.length) { + A[a.length] = null; + } + + return A; + } + + protected abstract CharCollection getCharCollection(); +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/AbstractCharListList.java b/src/java/org/apache/commons/collections/primitives/adapters/AbstractCharListList.java new file mode 100644 index 000000000..702c2d149 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/AbstractCharListList.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/AbstractCharListList.java,v 1.1 2003/04/16 18:32:39 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.CharCollection; +import org.apache.commons.collections.primitives.CharList; + +/** + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:39 $ + * @author Rodney Waldhoff + */ +abstract class AbstractCharListList extends AbstractCharCollectionCollection implements List { + + public void add(int index, Object element) { + getCharList().add(index,((Character)element).charValue()); + } + + public boolean addAll(int index, Collection c) { + return getCharList().addAll(index,CollectionCharCollection.wrap(c)); + } + + public Object get(int index) { + return new Character(getCharList().get(index)); + } + + public int indexOf(Object element) { + return getCharList().indexOf(((Character)element).charValue()); + } + + public int lastIndexOf(Object element) { + return getCharList().lastIndexOf(((Character)element).charValue()); + } + + /** + * {@link CharListIteratorListIterator#wrap wraps} the + * {@link org.apache.commons.collections.primitives.CharListIterator CharListIterator} + * returned by my underlying + * {@link CharList CharList}, + * if any. + */ + public ListIterator listIterator() { + return CharListIteratorListIterator.wrap(getCharList().listIterator()); + } + + /** + * {@link CharListIteratorListIterator#wrap wraps} the + * {@link org.apache.commons.collections.primitives.CharListIterator CharListIterator} + * returned by my underlying + * {@link CharList CharList}, + * if any. + */ + public ListIterator listIterator(int index) { + return CharListIteratorListIterator.wrap(getCharList().listIterator(index)); + } + + public Object remove(int index) { + return new Character(getCharList().removeElementAt(index)); + } + + public Object set(int index, Object element) { + return new Character(getCharList().set(index, ((Character)element).charValue() )); + } + + public List subList(int fromIndex, int toIndex) { + return CharListList.wrap(getCharList().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 getCharList().hashCode(); + } + + protected final CharCollection getCharCollection() { + return getCharList(); + } + + protected abstract CharList getCharList(); + + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/AbstractCollectionCharCollection.java b/src/java/org/apache/commons/collections/primitives/adapters/AbstractCollectionCharCollection.java new file mode 100644 index 000000000..1d6b64851 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/AbstractCollectionCharCollection.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/AbstractCollectionCharCollection.java,v 1.1 2003/04/16 18:32:39 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.CharCollection; +import org.apache.commons.collections.primitives.CharIterator; + +/** + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:39 $ + * @author Rodney Waldhoff + */ +abstract class AbstractCollectionCharCollection implements CharCollection { + protected AbstractCollectionCharCollection() { + } + + public boolean add(char element) { + return getCollection().add(new Character(element)); + } + + public boolean addAll(CharCollection c) { + return getCollection().addAll(CharCollectionCollection.wrap(c)); + } + + public void clear() { + getCollection().clear(); + } + + public boolean contains(char element) { + return getCollection().contains(new Character(element)); + } + + public boolean containsAll(CharCollection c) { + return getCollection().containsAll(CharCollectionCollection.wrap(c)); + } + + public String toString() { + return getCollection().toString(); + } + + public boolean isEmpty() { + return getCollection().isEmpty(); + } + + /** + * {@link IteratorCharIterator#wrap wraps} the + * {@link java.util.Iterator Iterator} + * returned by my underlying + * {@link Collection Collection}, + * if any. + */ + public CharIterator iterator() { + return IteratorCharIterator.wrap(getCollection().iterator()); + } + + public boolean removeElement(char element) { + return getCollection().remove(new Character(element)); + } + + public boolean removeAll(CharCollection c) { + return getCollection().removeAll(CharCollectionCollection.wrap(c)); + } + + public boolean retainAll(CharCollection c) { + return getCollection().retainAll(CharCollectionCollection.wrap(c)); + } + + public int size() { + return getCollection().size(); + } + + public char[] toArray() { + Object[] src = getCollection().toArray(); + char[] dest = new char[src.length]; + for(int i=0;i. + * + */ + +package org.apache.commons.collections.primitives.adapters; + +import java.util.Collection; +import java.util.List; + +import org.apache.commons.collections.primitives.CharCollection; +import org.apache.commons.collections.primitives.CharIterator; +import org.apache.commons.collections.primitives.CharList; +import org.apache.commons.collections.primitives.CharListIterator; + +/** + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:39 $ + * @author Rodney Waldhoff + */ +abstract class AbstractListCharList extends AbstractCollectionCharCollection implements CharList { + + public void add(int index, char element) { + getList().add(index,new Character(element)); + } + + public boolean addAll(int index, CharCollection collection) { + return getList().addAll(index,CharCollectionCollection.wrap(collection)); + } + + public char get(int index) { + return ((Character)getList().get(index)).charValue(); + } + + public int indexOf(char element) { + return getList().indexOf(new Character(element)); + } + + public int lastIndexOf(char element) { + return getList().lastIndexOf(new Character(element)); + } + + /** + * {@link ListIteratorCharListIterator#wrap wraps} the + * {@link CharList CharList} + * returned by my underlying + * {@link CharListIterator CharListIterator}, + * if any. + */ + public CharListIterator listIterator() { + return ListIteratorCharListIterator.wrap(getList().listIterator()); + } + + /** + * {@link ListIteratorCharListIterator#wrap wraps} the + * {@link CharList CharList} + * returned by my underlying + * {@link CharListIterator CharListIterator}, + * if any. + */ + public CharListIterator listIterator(int index) { + return ListIteratorCharListIterator.wrap(getList().listIterator(index)); + } + + public char removeElementAt(int index) { + return ((Character)getList().remove(index)).charValue(); + } + + public char set(int index, char element) { + return ((Character)getList().set(index,new Character(element))).charValue(); + } + + public CharList subList(int fromIndex, int toIndex) { + return ListCharList.wrap(getList().subList(fromIndex,toIndex)); + } + + public boolean equals(Object obj) { + if(obj instanceof CharList) { + CharList that = (CharList)obj; + if(this == that) { + return true; + } else if(this.size() != that.size()) { + return false; + } else { + CharIterator thisiter = iterator(); + CharIterator 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/CharCollectionCollection.java b/src/java/org/apache/commons/collections/primitives/adapters/CharCollectionCollection.java new file mode 100644 index 000000000..be7fd17c7 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/CharCollectionCollection.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/CharCollectionCollection.java,v 1.1 2003/04/16 18:32:39 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.CharCollection; + +/** + * Adapts an {@link CharCollection CharCollection} + * to the {@link java.util.Collection Collection} + * interface. + *

+ * This implementation delegates most methods + * to the provided {@link CharCollection CharCollection} + * implementation in the "obvious" way. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:39 $ + * @author Rodney Waldhoff + */ +final public class CharCollectionCollection extends AbstractCharCollectionCollection implements Serializable { + + /** + * Create a {@link Collection Collection} wrapping + * the specified {@link CharCollection CharCollection}. When + * the given collection is null, + * returns null. + * + * @param collection the (possibly null) + * {@link CharCollection CharCollection} to wrap + * @return a {@link Collection Collection} wrapping the given + * collection, or null when collection is + * null. + */ + public static Collection wrap(CharCollection collection) { + if(null == collection) { + return null; + } else if(collection instanceof Serializable) { + return new CharCollectionCollection(collection); + } else { + return new NonSerializableCharCollectionCollection(collection); + } + } + + /** + * Creates a {@link Collection Collection} wrapping + * the specified {@link CharCollection CharCollection}. + * @see #wrap + */ + public CharCollectionCollection(CharCollection collection) { + _collection = collection; + } + + + protected CharCollection getCharCollection() { + return _collection; + } + + private CharCollection _collection = null; +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/CharIteratorIterator.java b/src/java/org/apache/commons/collections/primitives/adapters/CharIteratorIterator.java new file mode 100644 index 000000000..d8cec76c8 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/CharIteratorIterator.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/CharIteratorIterator.java,v 1.1 2003/04/16 18:32:39 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.CharIterator; + +/** + * Adapts an {@link CharIterator CharIterator} to the + * {@link java.util.Iterator Iterator} interface. + *

+ * This implementation delegates most methods + * to the provided {@link CharIterator CharIterator} + * implementation in the "obvious" way. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:39 $ + * @author Rodney Waldhoff + */ +public class CharIteratorIterator implements Iterator { + + /** + * Create an {@link Iterator Iterator} wrapping + * the specified {@link CharIterator CharIterator}. When + * the given iterator is null, + * returns null. + * + * @param iterator the (possibly null) + * {@link CharIterator CharIterator} to wrap + * @return an {@link Iterator Iterator} wrapping the given + * iterator, or null when iterator is + * null. + */ + public static Iterator wrap(CharIterator iterator) { + return null == iterator ? null : new CharIteratorIterator(iterator); + } + + /** + * Creates an {@link Iterator Iterator} wrapping + * the specified {@link CharIterator CharIterator}. + * @see #wrap + */ + public CharIteratorIterator(CharIterator iterator) { + _iterator = iterator; + } + + public boolean hasNext() { + return _iterator.hasNext(); + } + + public Object next() { + return new Character(_iterator.next()); + } + + public void remove() { + _iterator.remove(); + } + + private CharIterator _iterator = null; + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/CharListIteratorListIterator.java b/src/java/org/apache/commons/collections/primitives/adapters/CharListIteratorListIterator.java new file mode 100644 index 000000000..4f7519325 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/CharListIteratorListIterator.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/CharListIteratorListIterator.java,v 1.1 2003/04/16 18:32:39 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.CharListIterator; + +/** + * Adapts an {@link CharListIterator CharListIterator} to the + * {@link ListIterator ListIterator} interface. + *

+ * This implementation delegates most methods + * to the provided {@link CharListIterator CharListIterator} + * implementation in the "obvious" way. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:39 $ + * @author Rodney Waldhoff + */ +public class CharListIteratorListIterator implements ListIterator { + + /** + * Create a {@link ListIterator ListIterator} wrapping + * the specified {@link CharListIterator CharListIterator}. When + * the given iterator is null, + * returns null. + * + * @param iterator the (possibly null) + * {@link CharListIterator CharListIterator} to wrap + * @return a {@link ListIterator ListIterator} wrapping the given + * iterator, or null when iterator is + * null. + */ + public static ListIterator wrap(CharListIterator iterator) { + return null == iterator ? null : new CharListIteratorListIterator(iterator); + } + + /** + * Creates an {@link ListIterator ListIterator} wrapping + * the specified {@link CharListIterator CharListIterator}. + * @see #wrap + */ + public CharListIteratorListIterator(CharListIterator 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 Character(_iterator.next()); + } + + public Object previous() { + return new Character(_iterator.previous()); + } + + public void add(Object obj) { + _iterator.add(((Character)obj).charValue()); + } + + public void set(Object obj) { + _iterator.set(((Character)obj).charValue()); + } + + public void remove() { + _iterator.remove(); + } + + private CharListIterator _iterator = null; + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/CharListList.java b/src/java/org/apache/commons/collections/primitives/adapters/CharListList.java new file mode 100644 index 000000000..ce4e84a1c --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/CharListList.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/CharListList.java,v 1.1 2003/04/16 18:32:39 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.CharList; + +/** + * Adapts an {@link CharList CharList} to the + * {@link List List} interface. + *

+ * This implementation delegates most methods + * to the provided {@link CharList CharList} + * implementation in the "obvious" way. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:39 $ + * @author Rodney Waldhoff + */ +final public class CharListList extends AbstractCharListList implements Serializable { + + /** + * Create a {@link List List} wrapping + * the specified {@link CharList CharList}. When + * the given list is null, + * returns null. + * + * @param list the (possibly null) + * {@link CharList CharList} to wrap + * @return a {@link List List} wrapping the given + * list, or null when list is + * null. + */ + public static List wrap(CharList list) { + if(null == list) { + return null; + } else if(list instanceof Serializable) { + return new CharListList(list); + } else { + return new NonSerializableCharListList(list); + } + } + + /** + * Creates a {@link List List} wrapping + * the specified {@link CharList CharList}. + * @see #wrap + */ + public CharListList(CharList list) { + _list = list; + } + + protected CharList getCharList() { + return _list; + } + + private CharList _list = null; +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/CollectionCharCollection.java b/src/java/org/apache/commons/collections/primitives/adapters/CollectionCharCollection.java new file mode 100644 index 000000000..7990b5193 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/CollectionCharCollection.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/CollectionCharCollection.java,v 1.1 2003/04/16 18:32:39 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.CharCollection; + +/** + * Adapts a {@link java.lang.Number Number}-valued + * {@link java.util.Collection Collection} to the + * {@link CharCollection CharCollection} 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/16 18:32:39 $ + * @author Rodney Waldhoff + */ +final public class CollectionCharCollection extends AbstractCollectionCharCollection implements Serializable { + /** + * Create an {@link CharCollection CharCollection} 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 CharCollection CharCollection} wrapping the given + * collection, or null when collection is + * null. + */ + public static CharCollection wrap(Collection collection) { + if(null == collection) { + return null; + } else if(collection instanceof Serializable) { + return new CollectionCharCollection(collection); + } else { + return new NonSerializableCollectionCharCollection(collection); + } + } + + /** + * Creates an {@link CharCollection CharCollection} wrapping + * the specified {@link Collection Collection}. + * @see #wrap + */ + public CollectionCharCollection(Collection collection) { + _collection = collection; + } + + protected Collection getCollection() { + return _collection; + } + + private Collection _collection = null; +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/IteratorCharIterator.java b/src/java/org/apache/commons/collections/primitives/adapters/IteratorCharIterator.java new file mode 100644 index 000000000..941ad5eb9 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/IteratorCharIterator.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/IteratorCharIterator.java,v 1.1 2003/04/16 18:32:39 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.CharIterator; + +/** + * Adapts a {@link java.lang.Number Number}-valued + * {@link Iterator Iterator} + * to the {@link CharIterator CharIterator} + * 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/16 18:32:39 $ + * @author Rodney Waldhoff + */ +public class IteratorCharIterator implements CharIterator { + + /** + * Create an {@link CharIterator CharIterator} 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 CharIterator CharIterator} wrapping the given + * iterator, or null when iterator is + * null. + */ + public static CharIterator wrap(Iterator iterator) { + return null == iterator ? null : new IteratorCharIterator(iterator); + } + + /** + * Creates an {@link CharIterator CharIterator} wrapping + * the specified {@link Iterator Iterator}. + * @see #wrap + */ + public IteratorCharIterator(Iterator iterator) { + _iterator = iterator; + } + + public boolean hasNext() { + return _iterator.hasNext(); + } + + public char next() { + return ((Character)(_iterator.next())).charValue(); + } + + public void remove() { + _iterator.remove(); + } + + private Iterator _iterator = null; + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/ListCharList.java b/src/java/org/apache/commons/collections/primitives/adapters/ListCharList.java new file mode 100644 index 000000000..accf1a5f0 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/ListCharList.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/ListCharList.java,v 1.1 2003/04/16 18:32:39 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.CharList; + +/** + * Adapts a {@link Number}-valued {@link List List} + * to the {@link CharList CharList} 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/16 18:32:39 $ + * @author Rodney Waldhoff + */ +public class ListCharList extends AbstractListCharList implements Serializable { + + /** + * Create an {@link CharList CharList} 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 CharList CharList} wrapping the given + * list, or null when list is + * null. + */ + public static CharList wrap(List list) { + if(null == list) { + return null; + } else if(list instanceof Serializable) { + return new ListCharList(list); + } else { + return new NonSerializableListCharList(list); + } + } + + /** + * Creates an {@link CharList CharList} wrapping + * the specified {@link List List}. + * @see #wrap + */ + public ListCharList(List list) { + _list = list; + } + + protected List getList() { + return _list; + } + + private List _list = null; + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/ListIteratorCharListIterator.java b/src/java/org/apache/commons/collections/primitives/adapters/ListIteratorCharListIterator.java new file mode 100644 index 000000000..5877d3ed9 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/ListIteratorCharListIterator.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/ListIteratorCharListIterator.java,v 1.1 2003/04/16 18:32:39 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.CharListIterator; + +/** + * Adapts a {@link Number}-valued {@link ListIterator ListIterator} + * to the {@link CharListIterator CharListIterator} interface. + *

+ * This implementation delegates most methods + * to the provided {@link CharListIterator CharListIterator} + * implementation in the "obvious" way. + * + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:39 $ + * @author Rodney Waldhoff + */ +public class ListIteratorCharListIterator implements CharListIterator { + + /** + * Create an {@link CharListIterator CharListIterator} 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 CharListIterator CharListIterator} wrapping the given + * iterator, or null when iterator is + * null. + */ + public static CharListIterator wrap(ListIterator iterator) { + return null == iterator ? null : new ListIteratorCharListIterator(iterator); + } + + /** + * Creates an {@link CharListIterator CharListIterator} wrapping + * the specified {@link ListIterator ListIterator}. + * @see #wrap + */ + public ListIteratorCharListIterator(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 char next() { + return ((Character)_iterator.next()).charValue(); + } + + public char previous() { + return ((Character)_iterator.previous()).charValue(); + } + + public void add(char element) { + _iterator.add(new Character(element)); + } + + public void set(char element) { + _iterator.set(new Character(element)); + } + + public void remove() { + _iterator.remove(); + } + + private ListIterator _iterator = null; + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCharCollectionCollection.java b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCharCollectionCollection.java new file mode 100644 index 000000000..1966df5c0 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCharCollectionCollection.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/NonSerializableCharCollectionCollection.java,v 1.1 2003/04/16 18:32:39 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.CharCollection; + +/** + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:39 $ + * @author Rodney Waldhoff + */ +final class NonSerializableCharCollectionCollection extends AbstractCharCollectionCollection { + + /** + * Creates a {@link Collection Collection} wrapping + * the specified {@link CharCollection CharCollection}. + */ + public NonSerializableCharCollectionCollection(CharCollection collection) { + _collection = collection; + } + + protected CharCollection getCharCollection() { + return _collection; + } + + private CharCollection _collection = null; +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCharListList.java b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCharListList.java new file mode 100644 index 000000000..726c67b36 --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCharListList.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/NonSerializableCharListList.java,v 1.1 2003/04/16 18:32:39 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.CharList; + +/** + * @since Commons Collections 2.2 + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:39 $ + * @author Rodney Waldhoff + */ +final class NonSerializableCharListList extends AbstractCharListList { + + /** + * Creates a {@link List List} wrapping + * the specified {@link CharList CharList}. + */ + public NonSerializableCharListList(CharList list) { + _list = list; + } + + protected CharList getCharList() { + return _list; + } + + private CharList _list = null; + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCollectionCharCollection.java b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCollectionCharCollection.java new file mode 100644 index 000000000..56e6ab49a --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableCollectionCharCollection.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/NonSerializableCollectionCharCollection.java,v 1.1 2003/04/16 18:32:39 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/16 18:32:39 $ + * @author Rodney Waldhoff + */ +final class NonSerializableCollectionCharCollection extends AbstractCollectionCharCollection { + public NonSerializableCollectionCharCollection(Collection collection) { + _collection = collection; + } + + protected Collection getCollection() { + return _collection; + } + + private Collection _collection = null; + +} diff --git a/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableListCharList.java b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableListCharList.java new file mode 100644 index 000000000..f78009e8c --- /dev/null +++ b/src/java/org/apache/commons/collections/primitives/adapters/NonSerializableListCharList.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/NonSerializableListCharList.java,v 1.1 2003/04/16 18:32:39 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/16 18:32:39 $ + * @author Rodney Waldhoff + */ +final class NonSerializableListCharList extends AbstractListCharList { + + protected NonSerializableListCharList(List list) { + _list = list; + } + + protected List getList() { + return _list; + } + + private List _list = null; + +} diff --git a/src/test/org/apache/commons/collections/primitives/TestAbstractCharCollection.java b/src/test/org/apache/commons/collections/primitives/TestAbstractCharCollection.java new file mode 100644 index 000000000..d7f2d52da --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/TestAbstractCharCollection.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/TestAbstractCharCollection.java,v 1.1 2003/04/16 18:32:40 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.IteratorCharIterator; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:40 $ + * @author Rodney Waldhoff + */ +public class TestAbstractCharCollection extends TestCase { + + // conventional + // ------------------------------------------------------------------------ + + public TestAbstractCharCollection(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestAbstractCharCollection.class); + } + + // tests + // ------------------------------------------------------------------------ + + public void testAddIsUnsupportedByDefault() { + CharCollection col = new CharCollectionImpl(); + try { + col.add((char)1); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) { + // expected + } + } + // inner classes + // ------------------------------------------------------------------------ + + + static class CharCollectionImpl extends AbstractCharCollection { + public CharCollectionImpl() { + } + + public CharIterator iterator() { + return new IteratorCharIterator(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 83d0ae233..b9de497e7 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.17 2003/04/15 01:55:22 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.18 2003/04/16 18:32:40 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * @@ -62,7 +62,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; /** - * @version $Revision: 1.17 $ $Date: 2003/04/15 01:55:22 $ + * @version $Revision: 1.18 $ $Date: 2003/04/16 18:32:40 $ * @author Rodney Waldhoff */ public class TestAll extends TestCase { @@ -87,6 +87,10 @@ public class TestAll extends TestCase { suite.addTest(TestArrayShortList.suite()); suite.addTest(TestArrayUnsignedByteList.suite()); + suite.addTest(TestAbstractCharCollection.suite()); + suite.addTest(TestRandomAccessCharList.suite()); + suite.addTest(TestArrayCharList.suite()); + suite.addTest(TestAbstractIntCollection.suite()); suite.addTest(TestRandomAccessIntList.suite()); suite.addTest(TestArrayIntList.suite()); diff --git a/src/test/org/apache/commons/collections/primitives/TestArrayCharList.java b/src/test/org/apache/commons/collections/primitives/TestArrayCharList.java new file mode 100644 index 000000000..03104b3ec --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/TestArrayCharList.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/TestArrayCharList.java,v 1.1 2003/04/16 18:32:40 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/16 18:32:40 $ + * @author Rodney Waldhoff + */ +public class TestArrayCharList extends TestCharList { + + // conventional + // ------------------------------------------------------------------------ + + public TestArrayCharList(String testName) { + super(testName); + } + + public static Test suite() { + TestSuite suite = BulkTest.makeSuite(TestArrayCharList.class); + return suite; + } + + // collections testing framework + // ------------------------------------------------------------------------ + + protected CharList makeEmptyCharList() { + return new ArrayCharList(); + } + + public String[] ignoredSimpleTests() { + // sublists are not serializable + return new String[] { + "TestArrayCharList.bulkTestSubList.testFullListSerialization", + "TestArrayCharList.bulkTestSubList.testEmptyListSerialization", + "TestArrayCharList.bulkTestSubList.testCanonicalEmptyCollectionExists", + "TestArrayCharList.bulkTestSubList.testCanonicalFullCollectionExists", + "TestArrayCharList.bulkTestSubList.testEmptyListCompatibility", + "TestArrayCharList.bulkTestSubList.testFullListCompatibility", + "TestArrayCharList.bulkTestSubList.testSerializeDeserializeThenCompare", + "TestArrayCharList.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() { + CharList list = new ArrayCharList(); + for (int i = 0; i < 1000; i++) { + char value = ((char) (Character.MAX_VALUE)); + value -= i; + list.add(value); + } + for (int i = 0; i < 1000; i++) { + char value = ((char) (Character.MAX_VALUE)); + value -= i; + assertEquals(value, list.get(i)); + } + } + + public void testZeroInitialCapacityIsValid() { + ArrayCharList list = new ArrayCharList(0); + } + + public void testNegativeInitialCapacityIsInvalid() { + try { + ArrayCharList list = new ArrayCharList(-1); + fail("Expected IllegalArgumentException"); + } catch(IllegalArgumentException e) { + // expected + } + } + + public void testCopyConstructor() { + ArrayCharList expected = new ArrayCharList(); + for(int i=0;i<10;i++) { + expected.add((char)i); + } + ArrayCharList list = new ArrayCharList(expected); + assertEquals(10,list.size()); + assertEquals(expected,list); + } + + public void testCopyConstructorWithNull() { + try { + ArrayCharList list = new ArrayCharList(null); + fail("Expected NullPointerException"); + } catch(NullPointerException e) { + // expected + } + } + + + public void testTrimToSize() { + ArrayCharList list = new ArrayCharList(); + for(int j=0;j<3;j++) { + assertTrue(list.isEmpty()); + + list.trimToSize(); + + assertTrue(list.isEmpty()); + + for(int i=0;i<10;i++) { + list.add((char)i); + } + + for(int i=0;i<10;i++) { + assertEquals((char)i,list.get(i), 0f); + } + + list.trimToSize(); + + for(int i=0;i<10;i++) { + assertEquals((char)i,list.get(i), 0f); + } + + for(int i=0;i<10;i+=2) { + list.removeElement((char)i); + } + + for(int i=0;i<5;i++) { + assertEquals((char)(2*i)+1,list.get(i), 0f); + } + + list.trimToSize(); + + for(int i=0;i<5;i++) { + assertEquals((char)(2*i)+1,list.get(i), 0f); + } + + list.trimToSize(); + + for(int i=0;i<5;i++) { + assertEquals((char)(2*i)+1,list.get(i), 0f); + } + + list.clear(); + } + } + +} diff --git a/src/test/org/apache/commons/collections/primitives/TestCharIterator.java b/src/test/org/apache/commons/collections/primitives/TestCharIterator.java new file mode 100644 index 000000000..587ddce54 --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/TestCharIterator.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/TestCharIterator.java,v 1.1 2003/04/16 18:32:40 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.CharIteratorIterator; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:40 $ + * @author Rodney Waldhoff + */ +public abstract class TestCharIterator extends TestIterator { + + // conventional + // ------------------------------------------------------------------------ + + public TestCharIterator(String testName) { + super(testName); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + protected Object makeObject() { + return makeFullIterator(); + } + + public Iterator makeEmptyIterator() { + return CharIteratorIterator.wrap(makeEmptyCharIterator()); + } + + public Iterator makeFullIterator() { + return CharIteratorIterator.wrap(makeFullCharIterator()); + } + + + protected abstract CharIterator makeEmptyCharIterator(); + protected abstract CharIterator makeFullCharIterator(); + protected abstract char[] getFullElements(); + + // tests + // ------------------------------------------------------------------------ + + public void testNextHasNextRemove() { + char[] elements = getFullElements(); + CharIterator iter = makeFullCharIterator(); + 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.CharListList; +import org.apache.commons.collections.primitives.adapters.ListCharList; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:40 $ + * @author Rodney Waldhoff + */ +public abstract class TestCharList extends TestList { + + // conventional + // ------------------------------------------------------------------------ + + public TestCharList(String testName) { + super(testName); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + // collections testing framework: char list + // ------------------------------------------------------------------------ + + protected abstract CharList makeEmptyCharList(); + + protected CharList makeFullCharList() { + CharList list = makeEmptyCharList(); + char[] values = getFullChars(); + for(int i=0;i. + * + */ + +package org.apache.commons.collections.primitives; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:40 $ + * @author Rodney Waldhoff + */ +public abstract class TestCharListIterator extends TestCharIterator { + + // conventional + // ------------------------------------------------------------------------ + + public TestCharListIterator(String testName) { + super(testName); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + public CharIterator makeEmptyCharIterator() { + return makeEmptyCharListIterator(); + } + + public CharIterator makeFullCharIterator() { + return makeFullCharListIterator(); + } + + public abstract CharListIterator makeEmptyCharListIterator(); + public abstract CharListIterator makeFullCharListIterator(); + + // tests + // ------------------------------------------------------------------------ + + +} diff --git a/src/test/org/apache/commons/collections/primitives/TestRandomAccessCharList.java b/src/test/org/apache/commons/collections/primitives/TestRandomAccessCharList.java new file mode 100644 index 000000000..55b668352 --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/TestRandomAccessCharList.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/TestRandomAccessCharList.java,v 1.1 2003/04/16 18:32:40 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/16 18:32:40 $ + * @author Rodney Waldhoff + */ +public class TestRandomAccessCharList extends TestCase { + + // conventional + // ------------------------------------------------------------------------ + + public TestRandomAccessCharList(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestRandomAccessCharList.class); + } + + // tests + // ------------------------------------------------------------------------ + + public void testAddIsUnsupportedByDefault() { + RandomAccessCharList list = new AbstractRandomAccessCharListImpl(); + try { + list.add((char)1); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) { + // expected + } + try { + list.set(0,(char)1); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) { + // expected + } + } + + public void testAddAllIsUnsupportedByDefault() { + RandomAccessCharList list = new AbstractRandomAccessCharListImpl(); + CharList list2 = new ArrayCharList(); + list2.add((char)3); + try { + list.addAll(list2); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) { + // expected + } + } + + public void testSetIsUnsupportedByDefault() { + RandomAccessCharList list = new AbstractRandomAccessCharListImpl(); + try { + list.set(0,(char)1); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) { + // expected + } + } + + public void testRemoveElementIsUnsupportedByDefault() { + RandomAccessCharList list = new AbstractRandomAccessCharListImpl(); + try { + list.removeElementAt(0); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) { + // expected + } + } + + // inner classes + // ------------------------------------------------------------------------ + + + static class AbstractRandomAccessCharListImpl extends RandomAccessCharList { + public AbstractRandomAccessCharListImpl() { + } + + /** + * @see org.apache.commons.collections.primitives.CharList#get(int) + */ + public char get(int index) { + throw new IndexOutOfBoundsException(); + } + + /** + * @see org.apache.commons.collections.primitives.CharCollection#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 e7709af16..dd04bf46f 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.8 2003/04/15 03:07:50 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.9 2003/04/16 18:32:38 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * @@ -62,7 +62,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; /** - * @version $Revision: 1.8 $ $Date: 2003/04/15 03:07:50 $ + * @version $Revision: 1.9 $ $Date: 2003/04/16 18:32:38 $ * @author Rodney Waldhoff */ public class TestAll extends TestCase { @@ -96,6 +96,15 @@ public class TestAll extends TestCase { suite.addTest(TestShortIteratorIterator.suite()); suite.addTest(TestShortListIteratorListIterator.suite()); + suite.addTest(TestCollectionCharCollection.suite()); + suite.addTest(TestCharCollectionCollection.suite()); + suite.addTest(TestCharListList.suite()); + suite.addTest(TestListCharList.suite()); + suite.addTest(TestIteratorCharIterator.suite()); + suite.addTest(TestListIteratorCharListIterator.suite()); + suite.addTest(TestCharIteratorIterator.suite()); + suite.addTest(TestCharListIteratorListIterator.suite()); + suite.addTest(TestCollectionIntCollection.suite()); suite.addTest(TestIntCollectionCollection.suite()); suite.addTest(TestIntListList.suite()); diff --git a/src/test/org/apache/commons/collections/primitives/adapters/TestCharCollectionCollection.java b/src/test/org/apache/commons/collections/primitives/adapters/TestCharCollectionCollection.java new file mode 100644 index 000000000..63920407b --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/adapters/TestCharCollectionCollection.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/TestCharCollectionCollection.java,v 1.1 2003/04/16 18:32:38 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.RandomAccessCharList; +import org.apache.commons.collections.primitives.ArrayCharList; +import org.apache.commons.collections.primitives.CharList; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:38 $ + * @author Rodney Waldhoff + */ +public class TestCharCollectionCollection extends TestObject { + + // conventional + // ------------------------------------------------------------------------ + + public TestCharCollectionCollection(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestCharCollectionCollection.class); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + protected Object makeObject() { + CharList list = new ArrayCharList(); + for(int i=0;i<10;i++) { + list.add((char)i); + } + return new CharCollectionCollection(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(CharCollectionCollection.wrap(null)); + } + + public void testWrapSerializable() { + Collection collection = CharCollectionCollection.wrap(new ArrayCharList()); + assertNotNull(collection); + assertTrue(collection instanceof Serializable); + } + + public void testWrapNonSerializable() { + Collection collection = CharCollectionCollection.wrap(new RandomAccessCharList() { + public char 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/TestCharIteratorIterator.java b/src/test/org/apache/commons/collections/primitives/adapters/TestCharIteratorIterator.java new file mode 100644 index 000000000..66206438d --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/adapters/TestCharIteratorIterator.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/TestCharIteratorIterator.java,v 1.1 2003/04/16 18:32:38 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.ArrayCharList; +import org.apache.commons.collections.primitives.CharList; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:38 $ + * @author Rodney Waldhoff + */ +public class TestCharIteratorIterator extends TestIterator { + + // conventional + // ------------------------------------------------------------------------ + + public TestCharIteratorIterator(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestCharIteratorIterator.class); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + public Object makeObject() { + return makeFullIterator(); + } + + public Iterator makeEmptyIterator() { + return CharIteratorIterator.wrap(makeEmptyCharList().iterator()); + } + + public Iterator makeFullIterator() { + return CharIteratorIterator.wrap(makeFullCharList().iterator()); + } + + protected CharList makeEmptyCharList() { + return new ArrayCharList(); + } + + protected CharList makeFullCharList() { + CharList list = makeEmptyCharList(); + char[] 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.ArrayCharList; +import org.apache.commons.collections.primitives.CharList; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:38 $ + * @author Rodney Waldhoff + */ +public class TestCharListIteratorListIterator extends TestListIterator { + + // conventional + // ------------------------------------------------------------------------ + + public TestCharListIteratorListIterator(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestCharListIteratorListIterator.class); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + public Object makeObject() { + return makeFullIterator(); + } + + public ListIterator makeEmptyListIterator() { + return CharListIteratorListIterator.wrap(makeEmptyCharList().listIterator()); + } + + public ListIterator makeFullListIterator() { + return CharListIteratorListIterator.wrap(makeFullCharList().listIterator()); + } + + protected CharList makeEmptyCharList() { + return new ArrayCharList(); + } + + protected CharList makeFullCharList() { + CharList list = makeEmptyCharList(); + char[] 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.RandomAccessCharList; +import org.apache.commons.collections.primitives.ArrayCharList; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:38 $ + * @author Rodney Waldhoff + */ +public class TestCharListList extends TestList { + + // conventional + // ------------------------------------------------------------------------ + + public TestCharListList(String testName) { + super(testName); + } + + public static Test suite() { + TestSuite suite = BulkTest.makeSuite(TestCharListList.class); + return suite; + } + + // collections testing framework + // ------------------------------------------------------------------------ + + protected List makeEmptyList() { + return new CharListList(new ArrayCharList()); + } + + protected Object[] getFullElements() { + Character[] elts = new Character[10]; + 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 java.util.List; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.collections.TestObject; +import org.apache.commons.collections.primitives.CharCollection; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:38 $ + * @author Rodney Waldhoff + */ +public class TestCollectionCharCollection extends TestObject { + + // conventional + // ------------------------------------------------------------------------ + + public TestCollectionCharCollection(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestCollectionCharCollection.class); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + protected Object makeObject() { + List list = new ArrayList(); + for(int i=0;i<10;i++) { + list.add(new Character((char)i)); + } + return new CollectionCharCollection(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(CollectionCharCollection.wrap(null)); + } + + public void testWrapSerializable() { + CharCollection collection = CollectionCharCollection.wrap(new ArrayList()); + assertNotNull(collection); + assertTrue(collection instanceof Serializable); + } + + public void testWrapNonSerializable() { + CharCollection collection = CollectionCharCollection.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/TestIteratorCharIterator.java b/src/test/org/apache/commons/collections/primitives/adapters/TestIteratorCharIterator.java new file mode 100644 index 000000000..7153d7fc1 --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/adapters/TestIteratorCharIterator.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/TestIteratorCharIterator.java,v 1.1 2003/04/16 18:32:38 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.CharIterator; +import org.apache.commons.collections.primitives.TestCharIterator; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:38 $ + * @author Rodney Waldhoff + */ +public class TestIteratorCharIterator extends TestCharIterator { + + // conventional + // ------------------------------------------------------------------------ + + public TestIteratorCharIterator(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestIteratorCharIterator.class); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + public CharIterator makeEmptyCharIterator() { + return IteratorCharIterator.wrap(makeEmptyList().iterator()); + } + + public CharIterator makeFullCharIterator() { + return IteratorCharIterator.wrap(makeFullList().iterator()); + } + + protected List makeEmptyList() { + return new ArrayList(); + } + + protected List makeFullList() { + List list = makeEmptyList(); + char[] 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.CharList; +import org.apache.commons.collections.primitives.TestCharList; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:38 $ + * @author Rodney Waldhoff + */ +public class TestListCharList extends TestCharList { + + // conventional + // ------------------------------------------------------------------------ + + public TestListCharList(String testName) { + super(testName); + } + + public static Test suite() { + TestSuite suite = BulkTest.makeSuite(TestListCharList.class); + return suite; + } + + // collections testing framework + // ------------------------------------------------------------------------ + + /** + * @see org.apache.commons.collections.primitives.TestCharList#makeEmptyCharList() + */ + protected CharList makeEmptyCharList() { + return new ListCharList(new ArrayList()); + } + + public String[] ignoredSimpleTests() { + // sublists are not serializable + return new String[] { + "TestListCharList.bulkTestSubList.testFullListSerialization", + "TestListCharList.bulkTestSubList.testEmptyListSerialization", + "TestListCharList.bulkTestSubList.testCanonicalEmptyCollectionExists", + "TestListCharList.bulkTestSubList.testCanonicalFullCollectionExists", + "TestListCharList.bulkTestSubList.testEmptyListCompatibility", + "TestListCharList.bulkTestSubList.testFullListCompatibility", + "TestListCharList.bulkTestSubList.testSerializeDeserializeThenCompare", + "TestListCharList.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(ListCharList.wrap(null)); + } + + public void testWrapSerializable() { + CharList list = ListCharList.wrap(new ArrayList()); + assertNotNull(list); + assertTrue(list instanceof Serializable); + } + + public void testWrapNonSerializable() { + CharList list = ListCharList.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/TestListIteratorCharListIterator.java b/src/test/org/apache/commons/collections/primitives/adapters/TestListIteratorCharListIterator.java new file mode 100644 index 000000000..1a0f62988 --- /dev/null +++ b/src/test/org/apache/commons/collections/primitives/adapters/TestListIteratorCharListIterator.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/TestListIteratorCharListIterator.java,v 1.1 2003/04/16 18:32:38 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.CharListIterator; +import org.apache.commons.collections.primitives.TestCharListIterator; + +/** + * @version $Revision: 1.1 $ $Date: 2003/04/16 18:32:38 $ + * @author Rodney Waldhoff + */ +public class TestListIteratorCharListIterator extends TestCharListIterator { + + // conventional + // ------------------------------------------------------------------------ + + public TestListIteratorCharListIterator(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestListIteratorCharListIterator.class); + } + + // collections testing framework + // ------------------------------------------------------------------------ + + public CharListIterator makeEmptyCharListIterator() { + return ListIteratorCharListIterator.wrap(makeEmptyList().listIterator()); + } + + public CharListIterator makeFullCharListIterator() { + return ListIteratorCharListIterator.wrap(makeFullList().listIterator()); + } + + protected List makeEmptyList() { + return new ArrayList(); + } + + protected List makeFullList() { + List list = makeEmptyList(); + char[] elts = getFullElements(); + for(int i=0;i