add byte collections and tests
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131012 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
71a2dba44e
commit
b2528188aa
|
@ -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/AbstractByteCollection.java,v 1.1 2003/04/15 01:55:23 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives;
|
||||
|
||||
/**
|
||||
* Abstract base class for {@link ByteCollection}s.
|
||||
* <p />
|
||||
* Read-only subclasses must override {@link #iterator}
|
||||
* and {@link #size}. Mutable subclasses
|
||||
* should also override {@link #add} and
|
||||
* {@link ByteIterator#remove ByteIterator.remove}.
|
||||
* All other methods have at least some base implementation
|
||||
* derived from these. Subclasses may choose to override
|
||||
* these methods to provide a more efficient implementation.
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:23 $
|
||||
*
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public abstract class AbstractByteCollection implements ByteCollection {
|
||||
public abstract ByteIterator iterator();
|
||||
public abstract int size();
|
||||
|
||||
protected AbstractByteCollection() { }
|
||||
|
||||
/** Unsupported in this base implementation. */
|
||||
public boolean add(byte element) {
|
||||
throw new UnsupportedOperationException("add(byte) is not supported.");
|
||||
}
|
||||
|
||||
public boolean addAll(ByteCollection c) {
|
||||
boolean modified = false;
|
||||
for(ByteIterator iter = c.iterator(); iter.hasNext(); ) {
|
||||
modified |= add(iter.next());
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
for(ByteIterator iter = iterator(); iter.hasNext();) {
|
||||
iter.next();
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(byte element) {
|
||||
for(ByteIterator iter = iterator(); iter.hasNext();) {
|
||||
if(iter.next() == element) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsAll(ByteCollection c) {
|
||||
for(ByteIterator iter = c.iterator(); iter.hasNext();) {
|
||||
if(!contains(iter.next())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return (0 == size());
|
||||
}
|
||||
|
||||
public boolean removeElement(byte element) {
|
||||
for(ByteIterator iter = iterator(); iter.hasNext();) {
|
||||
if(iter.next() == element) {
|
||||
iter.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removeAll(ByteCollection c) {
|
||||
boolean modified = false;
|
||||
for(ByteIterator iter = c.iterator(); iter.hasNext(); ) {
|
||||
modified |= removeElement(iter.next());
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
public boolean retainAll(ByteCollection c) {
|
||||
boolean modified = false;
|
||||
for(ByteIterator iter = iterator(); iter.hasNext();) {
|
||||
if(!c.contains(iter.next())) {
|
||||
iter.remove();
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
public byte[] toArray() {
|
||||
byte[] array = new byte[size()];
|
||||
int i = 0;
|
||||
for(ByteIterator iter = iterator(); iter.hasNext();) {
|
||||
array[i] = iter.next();
|
||||
i++;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public byte[] toArray(byte[] a) {
|
||||
if(a.length < size()) {
|
||||
return toArray();
|
||||
} else {
|
||||
int i = 0;
|
||||
for(ByteIterator iter = iterator(); iter.hasNext();) {
|
||||
a[i] = iter.next();
|
||||
i++;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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/ArrayByteList.java,v 1.1 2003/04/15 01:55:23 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* An {@link ByteList} backed by an array of <code>byte</code>s.
|
||||
* This implementation supports all optional methods.
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:23 $
|
||||
*
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class ArrayByteList extends RandomAccessByteList implements ByteList, Serializable {
|
||||
|
||||
// constructors
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Construct an empty list with the default
|
||||
* initial capacity.
|
||||
*/
|
||||
public ArrayByteList() {
|
||||
this(8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an empty list with the given
|
||||
* initial capacity.
|
||||
* @throws IllegalArgumentException when <i>initialCapacity</i> is negative
|
||||
*/
|
||||
public ArrayByteList(int initialCapacity) {
|
||||
if(initialCapacity < 0) {
|
||||
throw new IllegalArgumentException("capacity " + initialCapacity);
|
||||
}
|
||||
_data = new byte[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 ArrayByteList#addAll(org.apache.commons.collections.primitives.ByteCollection)
|
||||
* @param that the non-<code>null</code> collection of <code>byte</code>s
|
||||
* to add
|
||||
* @throws NullPointerException if <i>that</i> is <code>null</code>
|
||||
*/
|
||||
public ArrayByteList(ByteCollection that) {
|
||||
this(that.size());
|
||||
addAll(that);
|
||||
}
|
||||
|
||||
// ByteList methods
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
public byte 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 byte removeElementAt(int index) {
|
||||
checkRange(index);
|
||||
incrModCount();
|
||||
byte 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 byte set(int index, byte element) {
|
||||
checkRange(index);
|
||||
incrModCount();
|
||||
byte 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, byte 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;
|
||||
byte[] olddata = _data;
|
||||
_data = new byte[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) {
|
||||
byte[] olddata = _data;
|
||||
_data = new byte[_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.writeByte(_data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
_data = new byte[in.readInt()];
|
||||
for(int i=0;i<_size;i++) {
|
||||
_data[i] = in.readByte();
|
||||
}
|
||||
}
|
||||
|
||||
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 byte[] _data = null;
|
||||
private int _size = 0;
|
||||
|
||||
}
|
|
@ -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/ByteCollection.java,v 1.1 2003/04/15 01:55:23 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives;
|
||||
|
||||
/**
|
||||
* A collection of <code>byte</code> values.
|
||||
*
|
||||
* @see org.apache.commons.collections.primitives.adapters.ByteCollectionCollection
|
||||
* @see org.apache.commons.collections.primitives.adapters.CollectionByteCollection
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:23 $
|
||||
*
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public interface ByteCollection {
|
||||
/**
|
||||
* Ensures that I contain the specified element
|
||||
* (optional operation). Returns <code>true</code>
|
||||
* iff I changed as a result of this call.
|
||||
* <p/>
|
||||
* If a collection refuses to add the specified
|
||||
* element for any reason other than that it already contains
|
||||
* the element, it <i>must</i> throw an exception (rather than
|
||||
* simply returning <tt>false</tt>). 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 <code>true</code> 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(byte 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 <code>true</code> 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(ByteCollection 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 <code>true</code> iff I contain
|
||||
* the specified element.
|
||||
*
|
||||
* @param element the value whose presence within me is to be tested
|
||||
* @return <code>true</code> iff I contain the specified element
|
||||
*/
|
||||
boolean contains(byte element);
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> 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 <code>true</code> iff I contain the all the specified elements
|
||||
*/
|
||||
boolean containsAll(ByteCollection c);
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> iff I contain no elements.
|
||||
* @return <code>true</code> iff I contain no elements.
|
||||
*/
|
||||
boolean isEmpty();
|
||||
|
||||
/**
|
||||
* Returns an {@link ByteIterator 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 ByteIterator iterator} over all my elements.
|
||||
*/
|
||||
ByteIterator 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 <code>true</code> iff I contained the at least one of the
|
||||
* specified elements, in other words, returns <code>true</code>
|
||||
* iff I changed as a result of this call
|
||||
*
|
||||
* @throws UnsupportedOperationException when this operation is not
|
||||
* supported
|
||||
*/
|
||||
boolean removeAll(ByteCollection c);
|
||||
|
||||
/**
|
||||
* Removes a single occurrence of the specified element
|
||||
* (optional operation).
|
||||
*
|
||||
* @param element the element to remove, if present
|
||||
* @return <code>true</code> 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(byte element);
|
||||
|
||||
/**
|
||||
* Removes all of my elements that are <i>not</i> contained in the
|
||||
* specified collection (optional operation).
|
||||
* (In other words, retains <i>only</i> 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 <code>true</code> iff I changed as a result
|
||||
* of this call
|
||||
*
|
||||
* @throws UnsupportedOperationException when this operation is not
|
||||
* supported
|
||||
*/
|
||||
boolean retainAll(ByteCollection 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}.
|
||||
* <p/>
|
||||
* The returned array will be independent of me,
|
||||
* so that callers may modify that
|
||||
* returned array without modifying this collection.
|
||||
* <p/>
|
||||
* 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
|
||||
*/
|
||||
byte[] 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.
|
||||
* <p/>
|
||||
* The returned array will be independent of me,
|
||||
* so that callers may modify that
|
||||
* returned array without modifying this collection.
|
||||
* <p/>
|
||||
* 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
|
||||
*/
|
||||
byte[] toArray(byte[] a);
|
||||
}
|
|
@ -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/ByteIterator.java,v 1.1 2003/04/15 01:55:23 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives;
|
||||
|
||||
/**
|
||||
* An iterator over <code>byte</code> values.
|
||||
*
|
||||
* @see org.apache.commons.collections.primitives.adapters.ByteIteratorIterator
|
||||
* @see org.apache.commons.collections.primitives.adapters.IteratorByteIterator
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:23 $
|
||||
*
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public interface ByteIterator {
|
||||
/**
|
||||
* Returns <code>true</code> iff I have more elements.
|
||||
* (In other words, returns <code>true</code> iff
|
||||
* a subsequent call to {@link #next next} will return
|
||||
* an element rather than throwing an exception.)
|
||||
*
|
||||
* @return <code>true</code> 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
|
||||
*/
|
||||
byte 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();
|
||||
}
|
|
@ -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/ByteList.java,v 1.1 2003/04/15 01:55:23 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives;
|
||||
|
||||
/**
|
||||
* An ordered collection of <code>byte</code> values.
|
||||
*
|
||||
* @see org.apache.commons.collections.primitives.adapters.ByteListList
|
||||
* @see org.apache.commons.collections.primitives.adapters.ListByteList
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:23 $
|
||||
*
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public interface ByteList extends ByteCollection {
|
||||
/**
|
||||
* Appends the specified element to the end of me
|
||||
* (optional operation). Returns <code>true</code>
|
||||
* iff I changed as a result of this call.
|
||||
* <p/>
|
||||
* If a collection refuses to add the specified
|
||||
* element for any reason other than that it already contains
|
||||
* the element, it <i>must</i> throw an exception (rather than
|
||||
* simply returning <tt>false</tt>). 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 <code>true</code> 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(byte 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, byte 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 ByteCollection#iterator iterator}.
|
||||
*
|
||||
* @param index the index at which to insert the first element from
|
||||
* the specified collection
|
||||
* @param collection the {@link ByteCollection ByteCollection} of elements to add
|
||||
* @return <code>true</code> 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, ByteCollection collection);
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> iff <i>that</i> is an <code>ByteList</code>
|
||||
* that contains the same elements in the same order as me.
|
||||
* In other words, returns <code>true</code> iff <i>that</i> is
|
||||
* an <code>ByteList</code> that has the same {@link #size size} as me,
|
||||
* and for which the elements returned by its
|
||||
* {@link ByteList#iterator iterator} are equal (<code>==</code>) to
|
||||
* the corresponding elements within me.
|
||||
* (This contract ensures that this method works properly across
|
||||
* different implementations of the <code>ByteList</code> interface.)
|
||||
*
|
||||
* @param that the object to compare to me
|
||||
* @return <code>true</code> iff <i>that</i> is an <code>ByteList</code>
|
||||
* 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
|
||||
*/
|
||||
byte get(int index);
|
||||
|
||||
/**
|
||||
* Returns my hash code.
|
||||
* <p />
|
||||
* The hash code of an <code>ByteList</code> is defined to be the
|
||||
* result of the following calculation:
|
||||
* <pre> int hash = 1;
|
||||
* for(ByteIterator iter = iterator(); iter.hasNext(); ) {
|
||||
* byte value = iter.next();
|
||||
* hash = 31*hash + (int)(value ^ (value >>> 32));
|
||||
* }</pre>
|
||||
* <p />
|
||||
* 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 Byte}s.
|
||||
*
|
||||
* @return my hash code
|
||||
*/
|
||||
int hashCode();
|
||||
|
||||
/**
|
||||
* Returns the index of the first occurrence
|
||||
* of the specified element within me,
|
||||
* or <code>-1</code> 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 <code>-1</code> if no such matching element can be found
|
||||
*/
|
||||
int indexOf(byte element);
|
||||
|
||||
/**
|
||||
* Returns an {@link ByteIterator iterator} over all my elements,
|
||||
* in the appropriate sequence.
|
||||
* @return an {@link ByteIterator iterator} over all my elements.
|
||||
*/
|
||||
ByteIterator 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 <code>-1</code> if no such matching element can be found
|
||||
*/
|
||||
int lastIndexOf(byte element);
|
||||
|
||||
/**
|
||||
* Returns a
|
||||
* {@link ByteListIterator bidirectional iterator}
|
||||
* over all my elements, in the appropriate sequence.
|
||||
*/
|
||||
ByteListIterator listIterator();
|
||||
|
||||
/**
|
||||
* Returns a
|
||||
* {@link ByteListIterator bidirectional iterator}
|
||||
* over all my elements, in the appropriate sequence,
|
||||
* starting at the specified position. The
|
||||
* specified <i>index</i> indicates the first
|
||||
* element that would be returned by an initial
|
||||
* call to the
|
||||
* {@link ByteListIterator#next next}
|
||||
* method. An initial call to the
|
||||
* {@link ByteListIterator#previous previous}
|
||||
* method would return the element with the specified
|
||||
* <i>index</i> minus one.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException if the specified index is out of range
|
||||
*/
|
||||
ByteListIterator 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
|
||||
*/
|
||||
byte 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
|
||||
*/
|
||||
byte set(int index, byte element);
|
||||
|
||||
/**
|
||||
* Returns a view of the elements within me
|
||||
* between the specified <i>fromIndex</i>, inclusive, and
|
||||
* <i>toIndex</i>, exclusive. The returned <code>ByteList</code>
|
||||
* 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.
|
||||
* <p/>
|
||||
* Note that when <code><i>fromIndex</i> == <i>toIndex</i></code>,
|
||||
* the returned list is initially empty, and when
|
||||
* <code><i>fromIndex</i> == 0 && <i>toIndex</i> == {@link #size() size()}</code>
|
||||
* the returned list is my "improper" sublist, containing all my elements.
|
||||
* <p/>
|
||||
* 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 <i>fromIndex</i> (inclusive) to
|
||||
* <i>toIndex</i> (exclusive)
|
||||
*
|
||||
* @throws IndexOutOfBoundsException if either specified index is out of range
|
||||
*/
|
||||
ByteList subList(int fromIndex, int toIndex);
|
||||
|
||||
}
|
|
@ -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/ByteListIterator.java,v 1.1 2003/04/15 01:55:23 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives;
|
||||
|
||||
/**
|
||||
* A bi-directional iterator over <code>byte</code> values.
|
||||
*
|
||||
* @see org.apache.commons.collections.primitives.adapters.ByteListIteratorListIterator
|
||||
* @see org.apache.commons.collections.primitives.adapters.ListIteratorByteListIterator
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:23 $
|
||||
*
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public interface ByteListIterator extends ByteIterator {
|
||||
/**
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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(byte element);
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> iff I have more elements
|
||||
* when traversed in the forward direction.
|
||||
* (In other words, returns <code>true</code> iff
|
||||
* a call to {@link #next} will return an element
|
||||
* rather than throwing an exception.
|
||||
*
|
||||
* @return <code>true</code> iff I have more elements when
|
||||
* traversed in the forward direction
|
||||
*/
|
||||
boolean hasNext();
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> iff I have more elements
|
||||
* when traversed in the reverse direction.
|
||||
* (In other words, returns <code>true</code> iff
|
||||
* a call to {@link #previous} will return an element
|
||||
* rather than throwing an exception.
|
||||
*
|
||||
* @return <code>true</code> 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
|
||||
*/
|
||||
byte 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
|
||||
*/
|
||||
byte previous();
|
||||
|
||||
/**
|
||||
* Returns the index of the element that would be returned
|
||||
* by a subsequent call to {@link #previous}, or
|
||||
* <code>-1</code> 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(byte element);
|
||||
}
|
|
@ -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/RandomAccessByteList.java,v 1.1 2003/04/15 01:55:23 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives;
|
||||
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Abstract base class for {@link ByteList}s backed
|
||||
* by random access structures like arrays.
|
||||
* <p />
|
||||
* Read-only subclasses must override {@link #get}
|
||||
* and {@link #size}. Mutable subclasses
|
||||
* should also override {@link #set}. Variably-sized
|
||||
* subclasses should also override {@link #add}
|
||||
* and {@link #removeElementAt}. All other methods
|
||||
* have at least some base implementation derived from
|
||||
* these. Subclasses may choose to override these methods
|
||||
* to provide a more efficient implementation.
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:23 $
|
||||
*
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public abstract class RandomAccessByteList extends AbstractByteCollection implements ByteList {
|
||||
|
||||
// constructors
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
/** Constructs an empty list. */
|
||||
protected RandomAccessByteList() {
|
||||
}
|
||||
|
||||
// fully abstract methods
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
public abstract byte get(int index);
|
||||
public abstract int size();
|
||||
|
||||
// unsupported in base
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Unsupported in this implementation.
|
||||
* @throws UnsupportedOperationException since this method is not supported
|
||||
*/
|
||||
public byte removeElementAt(int index) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsupported in this implementation.
|
||||
* @throws UnsupportedOperationException since this method is not supported
|
||||
*/
|
||||
public byte set(int index, byte element) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsupported in this implementation.
|
||||
* @throws UnsupportedOperationException since this method is not supported
|
||||
*/
|
||||
public void add(int index, byte element) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
// javadocs here are inherited
|
||||
|
||||
public boolean add(byte element) {
|
||||
add(size(),element);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean addAll(int index, ByteCollection collection) {
|
||||
boolean modified = false;
|
||||
for(ByteIterator iter = collection.iterator(); iter.hasNext(); ) {
|
||||
add(index++,iter.next());
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
public int indexOf(byte element) {
|
||||
int i = 0;
|
||||
for(ByteIterator iter = iterator(); iter.hasNext(); ) {
|
||||
if(iter.next() == element) {
|
||||
return i;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int lastIndexOf(byte element) {
|
||||
for(ByteListIterator iter = listIterator(size()); iter.hasPrevious(); ) {
|
||||
if(iter.previous() == element) {
|
||||
return iter.nextIndex();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public ByteIterator iterator() {
|
||||
return listIterator();
|
||||
}
|
||||
|
||||
public ByteListIterator listIterator() {
|
||||
return listIterator(0);
|
||||
}
|
||||
|
||||
public ByteListIterator listIterator(int index) {
|
||||
return new RandomAccessByteListIterator(this,index);
|
||||
}
|
||||
|
||||
public ByteList subList(int fromIndex, int toIndex) {
|
||||
return new RandomAccessByteSubList(this,fromIndex,toIndex);
|
||||
}
|
||||
|
||||
public boolean equals(Object that) {
|
||||
if(this == that) {
|
||||
return true;
|
||||
} else if(that instanceof ByteList) {
|
||||
ByteList thatList = (ByteList)that;
|
||||
if(size() != thatList.size()) {
|
||||
return false;
|
||||
}
|
||||
for(ByteIterator 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(ByteIterator iter = iterator(); iter.hasNext(); ) {
|
||||
hash = 31*hash + ((int)(iter.next()));
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("[");
|
||||
for(ByteIterator 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(RandomAccessByteList source) {
|
||||
_source = source;
|
||||
resyncModCount();
|
||||
}
|
||||
|
||||
protected RandomAccessByteList getList() {
|
||||
return _source;
|
||||
}
|
||||
|
||||
protected void assertNotComodified() throws ConcurrentModificationException {
|
||||
if(_expectedModCount != getList().getModCount()) {
|
||||
throw new ConcurrentModificationException();
|
||||
}
|
||||
}
|
||||
|
||||
protected void resyncModCount() {
|
||||
_expectedModCount = getList().getModCount();
|
||||
}
|
||||
|
||||
private RandomAccessByteList _source = null;
|
||||
private int _expectedModCount = -1;
|
||||
}
|
||||
|
||||
protected static class RandomAccessByteListIterator extends ComodChecker implements ByteListIterator {
|
||||
RandomAccessByteListIterator(RandomAccessByteList 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 byte next() {
|
||||
assertNotComodified();
|
||||
if(!hasNext()) {
|
||||
throw new NoSuchElementException();
|
||||
} else {
|
||||
byte val = getList().get(_nextIndex);
|
||||
_lastReturnedIndex = _nextIndex;
|
||||
_nextIndex++;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
public byte previous() {
|
||||
assertNotComodified();
|
||||
if(!hasPrevious()) {
|
||||
throw new NoSuchElementException();
|
||||
} else {
|
||||
byte val = getList().get(_nextIndex-1);
|
||||
_lastReturnedIndex = _nextIndex-1;
|
||||
_nextIndex--;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
public void add(byte 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(byte 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 RandomAccessByteSubList extends RandomAccessByteList implements ByteList {
|
||||
RandomAccessByteSubList(RandomAccessByteList 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 byte get(int index) {
|
||||
checkRange(index);
|
||||
_comod.assertNotComodified();
|
||||
return _list.get(toUnderlyingIndex(index));
|
||||
}
|
||||
|
||||
public byte removeElementAt(int index) {
|
||||
checkRange(index);
|
||||
_comod.assertNotComodified();
|
||||
byte val = _list.removeElementAt(toUnderlyingIndex(index));
|
||||
_limit--;
|
||||
_comod.resyncModCount();
|
||||
incrModCount();
|
||||
return val;
|
||||
}
|
||||
|
||||
public byte set(int index, byte element) {
|
||||
checkRange(index);
|
||||
_comod.assertNotComodified();
|
||||
byte val = _list.set(toUnderlyingIndex(index),element);
|
||||
incrModCount();
|
||||
_comod.resyncModCount();
|
||||
return val;
|
||||
}
|
||||
|
||||
public void add(int index, byte 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 RandomAccessByteList _list = null;
|
||||
private ComodChecker _comod = null;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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/AbstractByteCollectionCollection.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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.ByteCollection;
|
||||
|
||||
/**
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
abstract class AbstractByteCollectionCollection implements Collection {
|
||||
|
||||
public boolean add(Object element) {
|
||||
return getByteCollection().add(((Number)element).byteValue());
|
||||
}
|
||||
|
||||
public boolean addAll(Collection c) {
|
||||
return getByteCollection().addAll(CollectionByteCollection.wrap(c));
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
getByteCollection().clear();
|
||||
}
|
||||
|
||||
public boolean contains(Object element) {
|
||||
return getByteCollection().contains(((Number)element).byteValue());
|
||||
}
|
||||
|
||||
|
||||
public boolean containsAll(Collection c) {
|
||||
return getByteCollection().containsAll(CollectionByteCollection.wrap(c));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getByteCollection().toString();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return getByteCollection().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ByteIteratorIterator#wrap wraps} the
|
||||
* {@link org.apache.commons.collections.primitives.ByteIterator ByteIterator}
|
||||
* returned by my underlying
|
||||
* {@link ByteCollection ByteCollection},
|
||||
* if any.
|
||||
*/
|
||||
public Iterator iterator() {
|
||||
return ByteIteratorIterator.wrap(getByteCollection().iterator());
|
||||
}
|
||||
|
||||
public boolean remove(Object element) {
|
||||
return getByteCollection().removeElement(((Number)element).byteValue());
|
||||
}
|
||||
|
||||
public boolean removeAll(Collection c) {
|
||||
return getByteCollection().removeAll(CollectionByteCollection.wrap(c));
|
||||
}
|
||||
|
||||
public boolean retainAll(Collection c) {
|
||||
return getByteCollection().retainAll(CollectionByteCollection.wrap(c));
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return getByteCollection().size();
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
byte[] a = getByteCollection().toArray();
|
||||
Object[] A = new Object[a.length];
|
||||
for(int i=0;i<a.length;i++) {
|
||||
A[i] = new Byte(a[i]);
|
||||
}
|
||||
return A;
|
||||
}
|
||||
|
||||
public Object[] toArray(Object[] A) {
|
||||
byte[] a = getByteCollection().toArray();
|
||||
if(A.length < a.length) {
|
||||
A = (Object[])(Array.newInstance(A.getClass().getComponentType(), a.length));
|
||||
}
|
||||
for(int i=0;i<a.length;i++) {
|
||||
A[i] = new Byte(a[i]);
|
||||
}
|
||||
if(A.length > a.length) {
|
||||
A[a.length] = null;
|
||||
}
|
||||
|
||||
return A;
|
||||
}
|
||||
|
||||
protected abstract ByteCollection getByteCollection();
|
||||
}
|
|
@ -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/AbstractByteListList.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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.ByteCollection;
|
||||
import org.apache.commons.collections.primitives.ByteList;
|
||||
|
||||
/**
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
abstract class AbstractByteListList extends AbstractByteCollectionCollection implements List {
|
||||
|
||||
public void add(int index, Object element) {
|
||||
getByteList().add(index,((Number)element).byteValue());
|
||||
}
|
||||
|
||||
public boolean addAll(int index, Collection c) {
|
||||
return getByteList().addAll(index,CollectionByteCollection.wrap(c));
|
||||
}
|
||||
|
||||
public Object get(int index) {
|
||||
return new Byte(getByteList().get(index));
|
||||
}
|
||||
|
||||
public int indexOf(Object element) {
|
||||
return getByteList().indexOf(((Number)element).byteValue());
|
||||
}
|
||||
|
||||
public int lastIndexOf(Object element) {
|
||||
return getByteList().lastIndexOf(((Number)element).byteValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ByteListIteratorListIterator#wrap wraps} the
|
||||
* {@link org.apache.commons.collections.primitives.ByteListIterator ByteListIterator}
|
||||
* returned by my underlying
|
||||
* {@link ByteList ByteList},
|
||||
* if any.
|
||||
*/
|
||||
public ListIterator listIterator() {
|
||||
return ByteListIteratorListIterator.wrap(getByteList().listIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ByteListIteratorListIterator#wrap wraps} the
|
||||
* {@link org.apache.commons.collections.primitives.ByteListIterator ByteListIterator}
|
||||
* returned by my underlying
|
||||
* {@link ByteList ByteList},
|
||||
* if any.
|
||||
*/
|
||||
public ListIterator listIterator(int index) {
|
||||
return ByteListIteratorListIterator.wrap(getByteList().listIterator(index));
|
||||
}
|
||||
|
||||
public Object remove(int index) {
|
||||
return new Byte(getByteList().removeElementAt(index));
|
||||
}
|
||||
|
||||
public Object set(int index, Object element) {
|
||||
return new Byte(getByteList().set(index, ((Number)element).byteValue() ));
|
||||
}
|
||||
|
||||
public List subList(int fromIndex, int toIndex) {
|
||||
return ByteListList.wrap(getByteList().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 getByteList().hashCode();
|
||||
}
|
||||
|
||||
protected final ByteCollection getByteCollection() {
|
||||
return getByteList();
|
||||
}
|
||||
|
||||
protected abstract ByteList getByteList();
|
||||
|
||||
|
||||
}
|
|
@ -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/AbstractCollectionByteCollection.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives.adapters;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.commons.collections.primitives.ByteCollection;
|
||||
import org.apache.commons.collections.primitives.ByteIterator;
|
||||
|
||||
/**
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
abstract class AbstractCollectionByteCollection implements ByteCollection {
|
||||
protected AbstractCollectionByteCollection() {
|
||||
}
|
||||
|
||||
public boolean add(byte element) {
|
||||
return getCollection().add(new Byte(element));
|
||||
}
|
||||
|
||||
public boolean addAll(ByteCollection c) {
|
||||
return getCollection().addAll(ByteCollectionCollection.wrap(c));
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
getCollection().clear();
|
||||
}
|
||||
|
||||
public boolean contains(byte element) {
|
||||
return getCollection().contains(new Byte(element));
|
||||
}
|
||||
|
||||
public boolean containsAll(ByteCollection c) {
|
||||
return getCollection().containsAll(ByteCollectionCollection.wrap(c));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getCollection().toString();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return getCollection().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link IteratorByteIterator#wrap wraps} the
|
||||
* {@link java.util.Iterator Iterator}
|
||||
* returned by my underlying
|
||||
* {@link Collection Collection},
|
||||
* if any.
|
||||
*/
|
||||
public ByteIterator iterator() {
|
||||
return IteratorByteIterator.wrap(getCollection().iterator());
|
||||
}
|
||||
|
||||
public boolean removeElement(byte element) {
|
||||
return getCollection().remove(new Byte(element));
|
||||
}
|
||||
|
||||
public boolean removeAll(ByteCollection c) {
|
||||
return getCollection().removeAll(ByteCollectionCollection.wrap(c));
|
||||
}
|
||||
|
||||
public boolean retainAll(ByteCollection c) {
|
||||
return getCollection().retainAll(ByteCollectionCollection.wrap(c));
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return getCollection().size();
|
||||
}
|
||||
|
||||
public byte[] toArray() {
|
||||
Object[] src = getCollection().toArray();
|
||||
byte[] dest = new byte[src.length];
|
||||
for(int i=0;i<src.length;i++) {
|
||||
dest[i] = ((Number)(src[i])).byteValue();
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
public byte[] toArray(byte[] dest) {
|
||||
Object[] src = getCollection().toArray();
|
||||
if(dest.length < src.length) {
|
||||
dest = new byte[src.length];
|
||||
}
|
||||
for(int i=0;i<src.length;i++) {
|
||||
dest[i] = ((Number)(src[i])).byteValue();
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
protected abstract Collection getCollection();
|
||||
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/adapters/Attic/AbstractListByteList.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives.adapters;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.primitives.ByteCollection;
|
||||
import org.apache.commons.collections.primitives.ByteIterator;
|
||||
import org.apache.commons.collections.primitives.ByteList;
|
||||
import org.apache.commons.collections.primitives.ByteListIterator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
abstract class AbstractListByteList extends AbstractCollectionByteCollection implements ByteList {
|
||||
|
||||
public void add(int index, byte element) {
|
||||
getList().add(index,new Byte(element));
|
||||
}
|
||||
|
||||
public boolean addAll(int index, ByteCollection collection) {
|
||||
return getList().addAll(index,ByteCollectionCollection.wrap(collection));
|
||||
}
|
||||
|
||||
public byte get(int index) {
|
||||
return ((Number)getList().get(index)).byteValue();
|
||||
}
|
||||
|
||||
public int indexOf(byte element) {
|
||||
return getList().indexOf(new Byte(element));
|
||||
}
|
||||
|
||||
public int lastIndexOf(byte element) {
|
||||
return getList().lastIndexOf(new Byte(element));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ListIteratorByteListIterator#wrap wraps} the
|
||||
* {@link ByteList ByteList}
|
||||
* returned by my underlying
|
||||
* {@link ByteListIterator ByteListIterator},
|
||||
* if any.
|
||||
*/
|
||||
public ByteListIterator listIterator() {
|
||||
return ListIteratorByteListIterator.wrap(getList().listIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ListIteratorByteListIterator#wrap wraps} the
|
||||
* {@link ByteList ByteList}
|
||||
* returned by my underlying
|
||||
* {@link ByteListIterator ByteListIterator},
|
||||
* if any.
|
||||
*/
|
||||
public ByteListIterator listIterator(int index) {
|
||||
return ListIteratorByteListIterator.wrap(getList().listIterator(index));
|
||||
}
|
||||
|
||||
public byte removeElementAt(int index) {
|
||||
return ((Number)getList().remove(index)).byteValue();
|
||||
}
|
||||
|
||||
public byte set(int index, byte element) {
|
||||
return ((Number)getList().set(index,new Byte(element))).byteValue();
|
||||
}
|
||||
|
||||
public ByteList subList(int fromIndex, int toIndex) {
|
||||
return ListByteList.wrap(getList().subList(fromIndex,toIndex));
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof ByteList) {
|
||||
ByteList that = (ByteList)obj;
|
||||
if(this == that) {
|
||||
return true;
|
||||
} else if(this.size() != that.size()) {
|
||||
return false;
|
||||
} else {
|
||||
ByteIterator thisiter = iterator();
|
||||
ByteIterator 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();
|
||||
}
|
|
@ -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/ByteCollectionCollection.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives.adapters;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.commons.collections.primitives.ByteCollection;
|
||||
|
||||
/**
|
||||
* Adapts an {@link ByteCollection ByteCollection}
|
||||
* to the {@link java.util.Collection Collection}
|
||||
* interface.
|
||||
* <p />
|
||||
* This implementation delegates most methods
|
||||
* to the provided {@link ByteCollection ByteCollection}
|
||||
* implementation in the "obvious" way.
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
final public class ByteCollectionCollection extends AbstractByteCollectionCollection implements Serializable {
|
||||
|
||||
/**
|
||||
* Create a {@link Collection Collection} wrapping
|
||||
* the specified {@link ByteCollection ByteCollection}. When
|
||||
* the given <i>collection</i> is <code>null</code>,
|
||||
* returns <code>null</code>.
|
||||
*
|
||||
* @param collection the (possibly <code>null</code>)
|
||||
* {@link ByteCollection ByteCollection} to wrap
|
||||
* @return a {@link Collection Collection} wrapping the given
|
||||
* <i>collection</i>, or <code>null</code> when <i>collection</i> is
|
||||
* <code>null</code>.
|
||||
*/
|
||||
public static Collection wrap(ByteCollection collection) {
|
||||
if(null == collection) {
|
||||
return null;
|
||||
} else if(collection instanceof Serializable) {
|
||||
return new ByteCollectionCollection(collection);
|
||||
} else {
|
||||
return new NonSerializableByteCollectionCollection(collection);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Collection Collection} wrapping
|
||||
* the specified {@link ByteCollection ByteCollection}.
|
||||
* @see #wrap
|
||||
*/
|
||||
public ByteCollectionCollection(ByteCollection collection) {
|
||||
_collection = collection;
|
||||
}
|
||||
|
||||
|
||||
protected ByteCollection getByteCollection() {
|
||||
return _collection;
|
||||
}
|
||||
|
||||
private ByteCollection _collection = null;
|
||||
}
|
|
@ -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/ByteIteratorIterator.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives.adapters;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.commons.collections.primitives.ByteIterator;
|
||||
|
||||
/**
|
||||
* Adapts an {@link ByteIterator ByteIterator} to the
|
||||
* {@link java.util.Iterator Iterator} interface.
|
||||
* <p />
|
||||
* This implementation delegates most methods
|
||||
* to the provided {@link ByteIterator ByteIterator}
|
||||
* implementation in the "obvious" way.
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class ByteIteratorIterator implements Iterator {
|
||||
|
||||
/**
|
||||
* Create an {@link Iterator Iterator} wrapping
|
||||
* the specified {@link ByteIterator ByteIterator}. When
|
||||
* the given <i>iterator</i> is <code>null</code>,
|
||||
* returns <code>null</code>.
|
||||
*
|
||||
* @param iterator the (possibly <code>null</code>)
|
||||
* {@link ByteIterator ByteIterator} to wrap
|
||||
* @return an {@link Iterator Iterator} wrapping the given
|
||||
* <i>iterator</i>, or <code>null</code> when <i>iterator</i> is
|
||||
* <code>null</code>.
|
||||
*/
|
||||
public static Iterator wrap(ByteIterator iterator) {
|
||||
return null == iterator ? null : new ByteIteratorIterator(iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@link Iterator Iterator} wrapping
|
||||
* the specified {@link ByteIterator ByteIterator}.
|
||||
* @see #wrap
|
||||
*/
|
||||
public ByteIteratorIterator(ByteIterator iterator) {
|
||||
_iterator = iterator;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return _iterator.hasNext();
|
||||
}
|
||||
|
||||
public Object next() {
|
||||
return new Byte(_iterator.next());
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
_iterator.remove();
|
||||
}
|
||||
|
||||
private ByteIterator _iterator = null;
|
||||
|
||||
}
|
|
@ -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/ByteListIteratorListIterator.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives.adapters;
|
||||
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.apache.commons.collections.primitives.ByteListIterator;
|
||||
|
||||
/**
|
||||
* Adapts an {@link ByteListIterator ByteListIterator} to the
|
||||
* {@link ListIterator ListIterator} interface.
|
||||
* <p />
|
||||
* This implementation delegates most methods
|
||||
* to the provided {@link ByteListIterator ByteListIterator}
|
||||
* implementation in the "obvious" way.
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class ByteListIteratorListIterator implements ListIterator {
|
||||
|
||||
/**
|
||||
* Create a {@link ListIterator ListIterator} wrapping
|
||||
* the specified {@link ByteListIterator ByteListIterator}. When
|
||||
* the given <i>iterator</i> is <code>null</code>,
|
||||
* returns <code>null</code>.
|
||||
*
|
||||
* @param iterator the (possibly <code>null</code>)
|
||||
* {@link ByteListIterator ByteListIterator} to wrap
|
||||
* @return a {@link ListIterator ListIterator} wrapping the given
|
||||
* <i>iterator</i>, or <code>null</code> when <i>iterator</i> is
|
||||
* <code>null</code>.
|
||||
*/
|
||||
public static ListIterator wrap(ByteListIterator iterator) {
|
||||
return null == iterator ? null : new ByteListIteratorListIterator(iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@link ListIterator ListIterator} wrapping
|
||||
* the specified {@link ByteListIterator ByteListIterator}.
|
||||
* @see #wrap
|
||||
*/
|
||||
public ByteListIteratorListIterator(ByteListIterator 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 Byte(_iterator.next());
|
||||
}
|
||||
|
||||
public Object previous() {
|
||||
return new Byte(_iterator.previous());
|
||||
}
|
||||
|
||||
public void add(Object obj) {
|
||||
_iterator.add(((Number)obj).byteValue());
|
||||
}
|
||||
|
||||
public void set(Object obj) {
|
||||
_iterator.set(((Number)obj).byteValue());
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
_iterator.remove();
|
||||
}
|
||||
|
||||
private ByteListIterator _iterator = null;
|
||||
|
||||
}
|
|
@ -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/ByteListList.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives.adapters;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.primitives.ByteList;
|
||||
|
||||
/**
|
||||
* Adapts an {@link ByteList ByteList} to the
|
||||
* {@link List List} interface.
|
||||
* <p />
|
||||
* This implementation delegates most methods
|
||||
* to the provided {@link ByteList ByteList}
|
||||
* implementation in the "obvious" way.
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
final public class ByteListList extends AbstractByteListList implements Serializable {
|
||||
|
||||
/**
|
||||
* Create a {@link List List} wrapping
|
||||
* the specified {@link ByteList ByteList}. When
|
||||
* the given <i>list</i> is <code>null</code>,
|
||||
* returns <code>null</code>.
|
||||
*
|
||||
* @param list the (possibly <code>null</code>)
|
||||
* {@link ByteList ByteList} to wrap
|
||||
* @return a {@link List List} wrapping the given
|
||||
* <i>list</i>, or <code>null</code> when <i>list</i> is
|
||||
* <code>null</code>.
|
||||
*/
|
||||
public static List wrap(ByteList list) {
|
||||
if(null == list) {
|
||||
return null;
|
||||
} else if(list instanceof Serializable) {
|
||||
return new ByteListList(list);
|
||||
} else {
|
||||
return new NonSerializableByteListList(list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link List List} wrapping
|
||||
* the specified {@link ByteList ByteList}.
|
||||
* @see #wrap
|
||||
*/
|
||||
public ByteListList(ByteList list) {
|
||||
_list = list;
|
||||
}
|
||||
|
||||
protected ByteList getByteList() {
|
||||
return _list;
|
||||
}
|
||||
|
||||
private ByteList _list = null;
|
||||
}
|
|
@ -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/CollectionByteCollection.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives.adapters;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.commons.collections.primitives.ByteCollection;
|
||||
|
||||
/**
|
||||
* Adapts a {@link java.lang.Number Number}-valued
|
||||
* {@link java.util.Collection Collection} to the
|
||||
* {@link ByteCollection ByteCollection} interface.
|
||||
* <p />
|
||||
* This implementation delegates most methods
|
||||
* to the provided {@link Collection Collection}
|
||||
* implementation in the "obvious" way.
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
final public class CollectionByteCollection extends AbstractCollectionByteCollection implements Serializable {
|
||||
/**
|
||||
* Create an {@link ByteCollection ByteCollection} wrapping
|
||||
* the specified {@link Collection Collection}. When
|
||||
* the given <i>collection</i> is <code>null</code>,
|
||||
* returns <code>null</code>.
|
||||
*
|
||||
* @param collection the (possibly <code>null</code>) {@link Collection} to wrap
|
||||
* @return an {@link ByteCollection ByteCollection} wrapping the given
|
||||
* <i>collection</i>, or <code>null</code> when <i>collection</i> is
|
||||
* <code>null</code>.
|
||||
*/
|
||||
public static ByteCollection wrap(Collection collection) {
|
||||
if(null == collection) {
|
||||
return null;
|
||||
} else if(collection instanceof Serializable) {
|
||||
return new CollectionByteCollection(collection);
|
||||
} else {
|
||||
return new NonSerializableCollectionByteCollection(collection);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@link ByteCollection ByteCollection} wrapping
|
||||
* the specified {@link Collection Collection}.
|
||||
* @see #wrap
|
||||
*/
|
||||
public CollectionByteCollection(Collection collection) {
|
||||
_collection = collection;
|
||||
}
|
||||
|
||||
protected Collection getCollection() {
|
||||
return _collection;
|
||||
}
|
||||
|
||||
private Collection _collection = null;
|
||||
}
|
|
@ -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/IteratorByteIterator.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives.adapters;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.commons.collections.primitives.ByteIterator;
|
||||
|
||||
/**
|
||||
* Adapts a {@link java.lang.Number Number}-valued
|
||||
* {@link Iterator Iterator}
|
||||
* to the {@link ByteIterator ByteIterator}
|
||||
* interface.
|
||||
* <p />
|
||||
* This implementation delegates most methods
|
||||
* to the provided {@link Iterator Iterator}
|
||||
* implementation in the "obvious" way.
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class IteratorByteIterator implements ByteIterator {
|
||||
|
||||
/**
|
||||
* Create an {@link ByteIterator ByteIterator} wrapping
|
||||
* the specified {@link Iterator Iterator}. When
|
||||
* the given <i>iterator</i> is <code>null</code>,
|
||||
* returns <code>null</code>.
|
||||
*
|
||||
* @param iterator the (possibly <code>null</code>)
|
||||
* {@link Iterator Iterator} to wrap
|
||||
* @return an {@link ByteIterator ByteIterator} wrapping the given
|
||||
* <i>iterator</i>, or <code>null</code> when <i>iterator</i> is
|
||||
* <code>null</code>.
|
||||
*/
|
||||
public static ByteIterator wrap(Iterator iterator) {
|
||||
return null == iterator ? null : new IteratorByteIterator(iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@link ByteIterator ByteIterator} wrapping
|
||||
* the specified {@link Iterator Iterator}.
|
||||
* @see #wrap
|
||||
*/
|
||||
public IteratorByteIterator(Iterator iterator) {
|
||||
_iterator = iterator;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return _iterator.hasNext();
|
||||
}
|
||||
|
||||
public byte next() {
|
||||
return ((Number)(_iterator.next())).byteValue();
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
_iterator.remove();
|
||||
}
|
||||
|
||||
private Iterator _iterator = null;
|
||||
|
||||
}
|
|
@ -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/ListByteList.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives.adapters;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.primitives.ByteList;
|
||||
|
||||
/**
|
||||
* Adapts a {@link Number}-valued {@link List List}
|
||||
* to the {@link ByteList ByteList} interface.
|
||||
* <p />
|
||||
* This implementation delegates most methods
|
||||
* to the provided {@link List List}
|
||||
* implementation in the "obvious" way.
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class ListByteList extends AbstractListByteList implements Serializable {
|
||||
|
||||
/**
|
||||
* Create an {@link ByteList ByteList} wrapping
|
||||
* the specified {@link List List}. When
|
||||
* the given <i>list</i> is <code>null</code>,
|
||||
* returns <code>null</code>.
|
||||
*
|
||||
* @param list the (possibly <code>null</code>)
|
||||
* {@link List List} to wrap
|
||||
* @return a {@link ByteList ByteList} wrapping the given
|
||||
* <i>list</i>, or <code>null</code> when <i>list</i> is
|
||||
* <code>null</code>.
|
||||
*/
|
||||
public static ByteList wrap(List list) {
|
||||
if(null == list) {
|
||||
return null;
|
||||
} else if(list instanceof Serializable) {
|
||||
return new ListByteList(list);
|
||||
} else {
|
||||
return new NonSerializableListByteList(list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@link ByteList ByteList} wrapping
|
||||
* the specified {@link List List}.
|
||||
* @see #wrap
|
||||
*/
|
||||
public ListByteList(List list) {
|
||||
_list = list;
|
||||
}
|
||||
|
||||
protected List getList() {
|
||||
return _list;
|
||||
}
|
||||
|
||||
private List _list = null;
|
||||
|
||||
}
|
|
@ -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/ListIteratorByteListIterator.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives.adapters;
|
||||
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.apache.commons.collections.primitives.ByteListIterator;
|
||||
|
||||
/**
|
||||
* Adapts a {@link Number}-valued {@link ListIterator ListIterator}
|
||||
* to the {@link ByteListIterator ByteListIterator} interface.
|
||||
* <p />
|
||||
* This implementation delegates most methods
|
||||
* to the provided {@link ByteListIterator ByteListIterator}
|
||||
* implementation in the "obvious" way.
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class ListIteratorByteListIterator implements ByteListIterator {
|
||||
|
||||
/**
|
||||
* Create an {@link ByteListIterator ByteListIterator} wrapping
|
||||
* the specified {@link ListIterator ListIterator}. When
|
||||
* the given <i>iterator</i> is <code>null</code>,
|
||||
* returns <code>null</code>.
|
||||
*
|
||||
* @param iterator the (possibly <code>null</code>)
|
||||
* {@link ListIterator ListIterator} to wrap
|
||||
* @return an {@link ByteListIterator ByteListIterator} wrapping the given
|
||||
* <i>iterator</i>, or <code>null</code> when <i>iterator</i> is
|
||||
* <code>null</code>.
|
||||
*/
|
||||
public static ByteListIterator wrap(ListIterator iterator) {
|
||||
return null == iterator ? null : new ListIteratorByteListIterator(iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@link ByteListIterator ByteListIterator} wrapping
|
||||
* the specified {@link ListIterator ListIterator}.
|
||||
* @see #wrap
|
||||
*/
|
||||
public ListIteratorByteListIterator(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 byte next() {
|
||||
return ((Number)_iterator.next()).byteValue();
|
||||
}
|
||||
|
||||
public byte previous() {
|
||||
return ((Number)_iterator.previous()).byteValue();
|
||||
}
|
||||
|
||||
public void add(byte element) {
|
||||
_iterator.add(new Byte(element));
|
||||
}
|
||||
|
||||
public void set(byte element) {
|
||||
_iterator.set(new Byte(element));
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
_iterator.remove();
|
||||
}
|
||||
|
||||
private ListIterator _iterator = null;
|
||||
|
||||
}
|
|
@ -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/NonSerializableByteCollectionCollection.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives.adapters;
|
||||
|
||||
import org.apache.commons.collections.primitives.ByteCollection;
|
||||
|
||||
/**
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
final class NonSerializableByteCollectionCollection extends AbstractByteCollectionCollection {
|
||||
|
||||
/**
|
||||
* Creates a {@link Collection Collection} wrapping
|
||||
* the specified {@link ByteCollection ByteCollection}.
|
||||
*/
|
||||
public NonSerializableByteCollectionCollection(ByteCollection collection) {
|
||||
_collection = collection;
|
||||
}
|
||||
|
||||
protected ByteCollection getByteCollection() {
|
||||
return _collection;
|
||||
}
|
||||
|
||||
private ByteCollection _collection = null;
|
||||
}
|
|
@ -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/NonSerializableByteListList.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives.adapters;
|
||||
|
||||
import org.apache.commons.collections.primitives.ByteList;
|
||||
|
||||
/**
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
final class NonSerializableByteListList extends AbstractByteListList {
|
||||
|
||||
/**
|
||||
* Creates a {@link List List} wrapping
|
||||
* the specified {@link ByteList ByteList}.
|
||||
*/
|
||||
public NonSerializableByteListList(ByteList list) {
|
||||
_list = list;
|
||||
}
|
||||
|
||||
protected ByteList getByteList() {
|
||||
return _list;
|
||||
}
|
||||
|
||||
private ByteList _list = null;
|
||||
|
||||
}
|
|
@ -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/NonSerializableCollectionByteCollection.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives.adapters;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
final class NonSerializableCollectionByteCollection extends AbstractCollectionByteCollection {
|
||||
public NonSerializableCollectionByteCollection(Collection collection) {
|
||||
_collection = collection;
|
||||
}
|
||||
|
||||
protected Collection getCollection() {
|
||||
return _collection;
|
||||
}
|
||||
|
||||
private Collection _collection = null;
|
||||
|
||||
}
|
|
@ -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/NonSerializableListByteList.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives.adapters;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @since Commons Collections 2.2
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
final class NonSerializableListByteList extends AbstractListByteList {
|
||||
|
||||
protected NonSerializableListByteList(List list) {
|
||||
_list = list;
|
||||
}
|
||||
|
||||
protected List getList() {
|
||||
return _list;
|
||||
}
|
||||
|
||||
private List _list = null;
|
||||
|
||||
}
|
|
@ -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/TestAbstractByteCollection.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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.IteratorByteIterator;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class TestAbstractByteCollection extends TestCase {
|
||||
|
||||
// conventional
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public TestAbstractByteCollection(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestAbstractByteCollection.class);
|
||||
}
|
||||
|
||||
// tests
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public void testAddIsUnsupportedByDefault() {
|
||||
ByteCollection col = new ByteCollectionImpl();
|
||||
try {
|
||||
col.add((byte)1);
|
||||
fail("Expected UnsupportedOperationException");
|
||||
} catch(UnsupportedOperationException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
// inner classes
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
static class ByteCollectionImpl extends AbstractByteCollection {
|
||||
public ByteCollectionImpl() {
|
||||
}
|
||||
|
||||
public ByteIterator iterator() {
|
||||
return new IteratorByteIterator(Collections.EMPTY_LIST.iterator());
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.16 2003/04/15 00:11:20 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.17 2003/04/15 01:55:22 rwaldhoff Exp $
|
||||
* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
*
|
||||
|
@ -62,7 +62,7 @@ import junit.framework.TestCase;
|
|||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.16 $ $Date: 2003/04/15 00:11:20 $
|
||||
* @version $Revision: 1.17 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class TestAll extends TestCase {
|
||||
|
@ -78,6 +78,10 @@ public class TestAll extends TestCase {
|
|||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
|
||||
suite.addTest(TestAbstractByteCollection.suite());
|
||||
suite.addTest(TestRandomAccessByteList.suite());
|
||||
suite.addTest(TestArrayByteList.suite());
|
||||
|
||||
suite.addTest(TestAbstractShortCollection.suite());
|
||||
suite.addTest(TestRandomAccessShortList.suite());
|
||||
suite.addTest(TestArrayShortList.suite());
|
||||
|
|
|
@ -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/TestArrayByteList.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.apache.commons.collections.BulkTest;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class TestArrayByteList extends TestByteList {
|
||||
|
||||
// conventional
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public TestArrayByteList(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = BulkTest.makeSuite(TestArrayByteList.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
// collections testing framework
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
protected ByteList makeEmptyByteList() {
|
||||
return new ArrayByteList();
|
||||
}
|
||||
|
||||
public String[] ignoredSimpleTests() {
|
||||
// sublists are not serializable
|
||||
return new String[] {
|
||||
"TestArrayByteList.bulkTestSubList.testFullListSerialization",
|
||||
"TestArrayByteList.bulkTestSubList.testEmptyListSerialization",
|
||||
"TestArrayByteList.bulkTestSubList.testCanonicalEmptyCollectionExists",
|
||||
"TestArrayByteList.bulkTestSubList.testCanonicalFullCollectionExists",
|
||||
"TestArrayByteList.bulkTestSubList.testEmptyListCompatibility",
|
||||
"TestArrayByteList.bulkTestSubList.testFullListCompatibility",
|
||||
"TestArrayByteList.bulkTestSubList.testSerializeDeserializeThenCompare",
|
||||
"TestArrayByteList.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() {
|
||||
ByteList list = new ArrayByteList();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
byte value = ((byte) (Byte.MAX_VALUE));
|
||||
value -= i;
|
||||
list.add(value);
|
||||
}
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
byte value = ((byte) (Byte.MAX_VALUE));
|
||||
value -= i;
|
||||
assertEquals(value, list.get(i), 0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void testZeroInitialCapacityIsValid() {
|
||||
ArrayByteList list = new ArrayByteList(0);
|
||||
}
|
||||
|
||||
public void testNegativeInitialCapacityIsInvalid() {
|
||||
try {
|
||||
ArrayByteList list = new ArrayByteList(-1);
|
||||
fail("Expected IllegalArgumentException");
|
||||
} catch(IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testCopyConstructor() {
|
||||
ArrayByteList expected = new ArrayByteList();
|
||||
for(int i=0;i<10;i++) {
|
||||
expected.add((byte)i);
|
||||
}
|
||||
ArrayByteList list = new ArrayByteList(expected);
|
||||
assertEquals(10,list.size());
|
||||
assertEquals(expected,list);
|
||||
}
|
||||
|
||||
public void testCopyConstructorWithNull() {
|
||||
try {
|
||||
ArrayByteList list = new ArrayByteList(null);
|
||||
fail("Expected NullPointerException");
|
||||
} catch(NullPointerException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testTrimToSize() {
|
||||
ArrayByteList list = new ArrayByteList();
|
||||
for(int j=0;j<3;j++) {
|
||||
assertTrue(list.isEmpty());
|
||||
|
||||
list.trimToSize();
|
||||
|
||||
assertTrue(list.isEmpty());
|
||||
|
||||
for(int i=0;i<10;i++) {
|
||||
list.add((byte)i);
|
||||
}
|
||||
|
||||
for(int i=0;i<10;i++) {
|
||||
assertEquals((byte)i,list.get(i), 0f);
|
||||
}
|
||||
|
||||
list.trimToSize();
|
||||
|
||||
for(int i=0;i<10;i++) {
|
||||
assertEquals((byte)i,list.get(i), 0f);
|
||||
}
|
||||
|
||||
for(int i=0;i<10;i+=2) {
|
||||
list.removeElement((byte)i);
|
||||
}
|
||||
|
||||
for(int i=0;i<5;i++) {
|
||||
assertEquals((byte)(2*i)+1,list.get(i), 0f);
|
||||
}
|
||||
|
||||
list.trimToSize();
|
||||
|
||||
for(int i=0;i<5;i++) {
|
||||
assertEquals((byte)(2*i)+1,list.get(i), 0f);
|
||||
}
|
||||
|
||||
list.trimToSize();
|
||||
|
||||
for(int i=0;i<5;i++) {
|
||||
assertEquals((byte)(2*i)+1,list.get(i), 0f);
|
||||
}
|
||||
|
||||
list.clear();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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/TestByteIterator.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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.ByteIteratorIterator;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public abstract class TestByteIterator extends TestIterator {
|
||||
|
||||
// conventional
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public TestByteIterator(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
// collections testing framework
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
protected Object makeObject() {
|
||||
return makeFullIterator();
|
||||
}
|
||||
|
||||
public Iterator makeEmptyIterator() {
|
||||
return ByteIteratorIterator.wrap(makeEmptyByteIterator());
|
||||
}
|
||||
|
||||
public Iterator makeFullIterator() {
|
||||
return ByteIteratorIterator.wrap(makeFullByteIterator());
|
||||
}
|
||||
|
||||
|
||||
protected abstract ByteIterator makeEmptyByteIterator();
|
||||
protected abstract ByteIterator makeFullByteIterator();
|
||||
protected abstract byte[] getFullElements();
|
||||
|
||||
// tests
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public void testNextHasNextRemove() {
|
||||
byte[] elements = getFullElements();
|
||||
ByteIterator iter = makeFullByteIterator();
|
||||
for(int i=0;i<elements.length;i++) {
|
||||
assertTrue(iter.hasNext());
|
||||
assertEquals(elements[i],iter.next(),0f);
|
||||
if(supportsRemove()) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
assertTrue(! iter.hasNext() );
|
||||
}
|
||||
|
||||
public void testEmptyByteIterator() {
|
||||
assertTrue( ! makeEmptyByteIterator().hasNext() );
|
||||
try {
|
||||
makeEmptyByteIterator().next();
|
||||
fail("Expected NoSuchElementException");
|
||||
} catch(NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
if(supportsRemove()) {
|
||||
try {
|
||||
makeEmptyByteIterator().remove();
|
||||
fail("Expected IllegalStateException");
|
||||
} catch(IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testRemoveBeforeNext() {
|
||||
if(supportsRemove()) {
|
||||
try {
|
||||
makeFullByteIterator().remove();
|
||||
fail("Expected IllegalStateException");
|
||||
} catch(IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testRemoveAfterRemove() {
|
||||
if(supportsRemove()) {
|
||||
ByteIterator iter = makeFullByteIterator();
|
||||
iter.next();
|
||||
iter.remove();
|
||||
try {
|
||||
iter.remove();
|
||||
fail("Expected IllegalStateException");
|
||||
} catch(IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,425 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestByteList.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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.ByteListList;
|
||||
import org.apache.commons.collections.primitives.adapters.ListByteList;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public abstract class TestByteList extends TestList {
|
||||
|
||||
// conventional
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public TestByteList(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
// collections testing framework
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// collections testing framework: byte list
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
protected abstract ByteList makeEmptyByteList();
|
||||
|
||||
protected ByteList makeFullByteList() {
|
||||
ByteList list = makeEmptyByteList();
|
||||
byte[] values = getFullBytes();
|
||||
for(int i=0;i<values.length;i++) {
|
||||
list.add(values[i]);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
protected byte[] getFullBytes() {
|
||||
byte[] result = new byte[19];
|
||||
for(int i = 0; i < result.length; i++) {
|
||||
result[i] = (byte)(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected byte[] getOtherBytes() {
|
||||
byte[] result = new byte[16];
|
||||
for(int i = 0; i < result.length; i++) {
|
||||
result[i] = (byte)(i + 43);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// collections testing framework: inherited
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
protected List makeEmptyList() {
|
||||
return new ByteListList(makeEmptyByteList());
|
||||
}
|
||||
|
||||
protected Object[] getFullElements() {
|
||||
return wrapArray(getFullBytes());
|
||||
}
|
||||
|
||||
protected Object[] getOtherElements() {
|
||||
return wrapArray(getOtherBytes());
|
||||
}
|
||||
|
||||
// private utils
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
private Byte[] wrapArray(byte[] primitives) {
|
||||
Byte[] result = new Byte[primitives.length];
|
||||
for(int i=0;i<result.length;i++) {
|
||||
result[i] = new Byte(primitives[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// tests
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public void testToJustBigEnoughByteArray() {
|
||||
ByteList list = makeFullByteList();
|
||||
byte[] dest = new byte[list.size()];
|
||||
assertSame(dest,list.toArray(dest));
|
||||
int i=0;
|
||||
for(ByteIterator iter = list.iterator(); iter.hasNext();i++) {
|
||||
assertEquals(iter.next(),dest[i], 0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void testToLargerThanNeededByteArray() {
|
||||
ByteList list = makeFullByteList();
|
||||
byte[] dest = new byte[list.size()*2];
|
||||
for(int i=0;i<dest.length;i++) {
|
||||
dest[i] = Byte.MAX_VALUE;
|
||||
}
|
||||
assertSame(dest,list.toArray(dest));
|
||||
int i=0;
|
||||
for(ByteIterator iter = list.iterator(); iter.hasNext();i++) {
|
||||
assertEquals(iter.next(),dest[i], 0f);
|
||||
}
|
||||
for(;i<dest.length;i++) {
|
||||
assertEquals(Byte.MAX_VALUE,dest[i], 0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void testToSmallerThanNeededByteArray() {
|
||||
ByteList list = makeFullByteList();
|
||||
byte[] dest = new byte[list.size()/2];
|
||||
byte[] dest2 = list.toArray(dest);
|
||||
assertTrue(dest != dest2);
|
||||
int i=0;
|
||||
for(ByteIterator iter = list.iterator(); iter.hasNext();i++) {
|
||||
assertEquals(iter.next(),dest2[i], 0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void testHashCodeSpecification() {
|
||||
ByteList list = makeFullByteList();
|
||||
int hash = 1;
|
||||
for(ByteIterator iter = list.iterator(); iter.hasNext(); ) {
|
||||
hash = 31*hash + ((int)iter.next());
|
||||
}
|
||||
assertEquals(hash,list.hashCode());
|
||||
}
|
||||
|
||||
public void testEqualsWithTwoByteLists() {
|
||||
ByteList one = makeEmptyByteList();
|
||||
assertEquals("Equals is reflexive on empty list",one,one);
|
||||
ByteList two = makeEmptyByteList();
|
||||
assertEquals("Empty lists are equal",one,two);
|
||||
assertEquals("Equals is symmetric on empty lists",two,one);
|
||||
|
||||
one.add((byte)1);
|
||||
assertEquals("Equals is reflexive on non empty list",one,one);
|
||||
assertTrue(!one.equals(two));
|
||||
assertTrue(!two.equals(one));
|
||||
|
||||
two.add((byte)1);
|
||||
assertEquals("Non empty lists are equal",one,two);
|
||||
assertEquals("Equals is symmetric on non empty list",one,two);
|
||||
|
||||
one.add((byte)1); one.add((byte)2); one.add((byte)3); one.add((byte)5); one.add((byte)8);
|
||||
assertEquals("Equals is reflexive on larger non empty list",one,one);
|
||||
assertTrue(!one.equals(two));
|
||||
assertTrue(!two.equals(one));
|
||||
|
||||
two.add((byte)1); two.add((byte)2); two.add((byte)3); two.add((byte)5); two.add((byte)8);
|
||||
assertEquals("Larger non empty lists are equal",one,two);
|
||||
assertEquals("Equals is symmetric on larger non empty list",two,one);
|
||||
|
||||
one.add((byte)9);
|
||||
two.add((byte)10);
|
||||
assertTrue(!one.equals(two));
|
||||
assertTrue(!two.equals(one));
|
||||
|
||||
}
|
||||
|
||||
public void testByteSubListEquals() {
|
||||
ByteList one = makeEmptyByteList();
|
||||
assertEquals(one,one.subList(0,0));
|
||||
assertEquals(one.subList(0,0),one);
|
||||
|
||||
one.add((byte)1);
|
||||
assertEquals(one,one.subList(0,1));
|
||||
assertEquals(one.subList(0,1),one);
|
||||
|
||||
one.add((byte)1); one.add((byte)2); one.add((byte)3); one.add((byte)5); one.add((byte)8);
|
||||
assertEquals(one.subList(0,4),one.subList(0,4));
|
||||
assertEquals(one.subList(3,5),one.subList(3,5));
|
||||
}
|
||||
|
||||
public void testEqualsWithByteListAndList() {
|
||||
ByteList ilist = makeEmptyByteList();
|
||||
List list = new ArrayList();
|
||||
|
||||
assertTrue("Unwrapped, empty List should not be equal to empty ByteList.",!ilist.equals(list));
|
||||
assertTrue("Unwrapped, empty ByteList should not be equal to empty List.",!list.equals(ilist));
|
||||
|
||||
assertEquals(new ListByteList(list),ilist);
|
||||
assertEquals(ilist,new ListByteList(list));
|
||||
assertEquals(new ByteListList(ilist),list);
|
||||
assertEquals(list,new ByteListList(ilist));
|
||||
|
||||
ilist.add((byte)1);
|
||||
list.add(new Byte((byte)1));
|
||||
|
||||
assertTrue("Unwrapped, non-empty List is not equal to non-empty ByteList.",!ilist.equals(list));
|
||||
assertTrue("Unwrapped, non-empty ByteList is not equal to non-empty List.",!list.equals(ilist));
|
||||
|
||||
assertEquals(new ListByteList(list),ilist);
|
||||
assertEquals(ilist,new ListByteList(list));
|
||||
assertEquals(new ByteListList(ilist),list);
|
||||
assertEquals(list,new ByteListList(ilist));
|
||||
|
||||
ilist.add((byte)1); ilist.add((byte)2); ilist.add((byte)3); ilist.add((byte)5); ilist.add((byte)8);
|
||||
list.add(new Byte((byte)1)); list.add(new Byte((byte)2)); list.add(new Byte((byte)3)); list.add(new Byte((byte)5)); list.add(new Byte((byte)8));
|
||||
|
||||
assertTrue("Unwrapped, non-empty List is not equal to non-empty ByteList.",!ilist.equals(list));
|
||||
assertTrue("Unwrapped, non-empty ByteList is not equal to non-empty List.",!list.equals(ilist));
|
||||
|
||||
assertEquals(new ListByteList(list),ilist);
|
||||
assertEquals(ilist,new ListByteList(list));
|
||||
assertEquals(new ByteListList(ilist),list);
|
||||
assertEquals(list,new ByteListList(ilist));
|
||||
|
||||
}
|
||||
|
||||
public void testClearAndSize() {
|
||||
ByteList list = makeEmptyByteList();
|
||||
assertEquals(0, list.size());
|
||||
for(int i = 0; i < 100; i++) {
|
||||
list.add((byte)i);
|
||||
}
|
||||
assertEquals(100, list.size());
|
||||
list.clear();
|
||||
assertEquals(0, list.size());
|
||||
}
|
||||
|
||||
public void testRemoveViaSubList() {
|
||||
ByteList list = makeEmptyByteList();
|
||||
for(int i = 0; i < 100; i++) {
|
||||
list.add((byte)i);
|
||||
}
|
||||
ByteList sub = list.subList(25,75);
|
||||
assertEquals(50,sub.size());
|
||||
for(int i = 0; i < 50; i++) {
|
||||
assertEquals(100-i,list.size());
|
||||
assertEquals(50-i,sub.size());
|
||||
assertEquals((byte)(25+i),sub.removeElementAt(0), 0f);
|
||||
assertEquals(50-i-1,sub.size());
|
||||
assertEquals(100-i-1,list.size());
|
||||
}
|
||||
assertEquals(0,sub.size());
|
||||
assertEquals(50,list.size());
|
||||
}
|
||||
|
||||
public void testAddGet() {
|
||||
ByteList list = makeEmptyByteList();
|
||||
for (int i = 0; i < 255; i++) {
|
||||
list.add((byte)i);
|
||||
}
|
||||
for (int i = 0; i < 255; i++) {
|
||||
assertEquals((byte)i, list.get(i), 0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void testAddAndShift() {
|
||||
ByteList list = makeEmptyByteList();
|
||||
list.add(0, (byte)1);
|
||||
assertEquals("Should have one entry", 1, list.size());
|
||||
list.add((byte)3);
|
||||
list.add((byte)4);
|
||||
list.add(1, (byte)2);
|
||||
for(int i = 0; i < 4; i++) {
|
||||
assertEquals("Should get entry back", (byte)(i + 1), list.get(i), 0f);
|
||||
}
|
||||
list.add(0, (byte)0);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertEquals("Should get entry back", (byte)i, list.get(i), 0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsSerializable() throws Exception {
|
||||
ByteList list = makeFullByteList();
|
||||
assertTrue(list instanceof Serializable);
|
||||
byte[] ser = writeExternalFormToBytes((Serializable)list);
|
||||
ByteList deser = (ByteList)(readExternalFormFromBytes(ser));
|
||||
assertEquals(list,deser);
|
||||
assertEquals(deser,list);
|
||||
}
|
||||
|
||||
public void testByteListSerializeDeserializeThenCompare() throws Exception {
|
||||
ByteList list = makeFullByteList();
|
||||
if(list instanceof Serializable) {
|
||||
byte[] ser = writeExternalFormToBytes((Serializable)list);
|
||||
ByteList deser = (ByteList)(readExternalFormFromBytes(ser));
|
||||
assertEquals("obj != deserialize(serialize(obj))",list,deser);
|
||||
}
|
||||
}
|
||||
|
||||
public void testSubListsAreNotSerializable() throws Exception {
|
||||
ByteList list = makeFullByteList().subList(2,3);
|
||||
assertTrue( ! (list instanceof Serializable) );
|
||||
}
|
||||
|
||||
public void testSubListOutOfBounds() throws Exception {
|
||||
try {
|
||||
makeEmptyByteList().subList(2,3);
|
||||
fail("Expected IndexOutOfBoundsException");
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
makeFullByteList().subList(-1,3);
|
||||
fail("Expected IndexOutOfBoundsException");
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
makeFullByteList().subList(5,2);
|
||||
fail("Expected IllegalArgumentException");
|
||||
} catch(IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
makeFullByteList().subList(2,makeFullByteList().size()+2);
|
||||
fail("Expected IndexOutOfBoundsException");
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testListIteratorOutOfBounds() throws Exception {
|
||||
try {
|
||||
makeEmptyByteList().listIterator(2);
|
||||
fail("Expected IndexOutOfBoundsException");
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
makeFullByteList().listIterator(-1);
|
||||
fail("Expected IndexOutOfBoundsException");
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
makeFullByteList().listIterator(makeFullByteList().size()+2);
|
||||
fail("Expected IndexOutOfBoundsException");
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testListIteratorSetWithoutNext() throws Exception {
|
||||
ByteListIterator iter = makeFullByteList().listIterator();
|
||||
try {
|
||||
iter.set((byte)3);
|
||||
fail("Expected IllegalStateException");
|
||||
} catch(IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testListIteratorSetAfterRemove() throws Exception {
|
||||
ByteListIterator iter = makeFullByteList().listIterator();
|
||||
iter.next();
|
||||
iter.remove();
|
||||
try {
|
||||
iter.set((byte)3);
|
||||
fail("Expected IllegalStateException");
|
||||
} catch(IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestByteListIterator.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public abstract class TestByteListIterator extends TestByteIterator {
|
||||
|
||||
// conventional
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public TestByteListIterator(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
// collections testing framework
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public ByteIterator makeEmptyByteIterator() {
|
||||
return makeEmptyByteListIterator();
|
||||
}
|
||||
|
||||
public ByteIterator makeFullByteIterator() {
|
||||
return makeFullByteListIterator();
|
||||
}
|
||||
|
||||
public abstract ByteListIterator makeEmptyByteListIterator();
|
||||
public abstract ByteListIterator makeFullByteListIterator();
|
||||
|
||||
// tests
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
}
|
|
@ -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/TestRandomAccessByteList.java,v 1.1 2003/04/15 01:55:22 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections.primitives;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:22 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class TestRandomAccessByteList extends TestCase {
|
||||
|
||||
// conventional
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public TestRandomAccessByteList(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestRandomAccessByteList.class);
|
||||
}
|
||||
|
||||
// tests
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public void testAddIsUnsupportedByDefault() {
|
||||
RandomAccessByteList list = new AbstractRandomAccessByteListImpl();
|
||||
try {
|
||||
list.add((byte)1);
|
||||
fail("Expected UnsupportedOperationException");
|
||||
} catch(UnsupportedOperationException e) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
list.set(0,(byte)1);
|
||||
fail("Expected UnsupportedOperationException");
|
||||
} catch(UnsupportedOperationException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testAddAllIsUnsupportedByDefault() {
|
||||
RandomAccessByteList list = new AbstractRandomAccessByteListImpl();
|
||||
ByteList list2 = new ArrayByteList();
|
||||
list2.add((byte)3);
|
||||
try {
|
||||
list.addAll(list2);
|
||||
fail("Expected UnsupportedOperationException");
|
||||
} catch(UnsupportedOperationException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testSetIsUnsupportedByDefault() {
|
||||
RandomAccessByteList list = new AbstractRandomAccessByteListImpl();
|
||||
try {
|
||||
list.set(0,(byte)1);
|
||||
fail("Expected UnsupportedOperationException");
|
||||
} catch(UnsupportedOperationException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testRemoveElementIsUnsupportedByDefault() {
|
||||
RandomAccessByteList list = new AbstractRandomAccessByteListImpl();
|
||||
try {
|
||||
list.removeElementAt(0);
|
||||
fail("Expected UnsupportedOperationException");
|
||||
} catch(UnsupportedOperationException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
// inner classes
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
static class AbstractRandomAccessByteListImpl extends RandomAccessByteList {
|
||||
public AbstractRandomAccessByteListImpl() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.commons.collections.primitives.ByteList#get(int)
|
||||
*/
|
||||
public byte get(int index) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.commons.collections.primitives.ByteCollection#size()
|
||||
*/
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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.6 2003/04/15 00:11:19 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.7 2003/04/15 01:55:21 rwaldhoff Exp $
|
||||
* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
*
|
||||
|
@ -62,7 +62,7 @@ import junit.framework.TestCase;
|
|||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.6 $ $Date: 2003/04/15 00:11:19 $
|
||||
* @version $Revision: 1.7 $ $Date: 2003/04/15 01:55:21 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class TestAll extends TestCase {
|
||||
|
@ -78,6 +78,15 @@ public class TestAll extends TestCase {
|
|||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
|
||||
suite.addTest(TestCollectionByteCollection.suite());
|
||||
suite.addTest(TestByteCollectionCollection.suite());
|
||||
suite.addTest(TestByteListList.suite());
|
||||
suite.addTest(TestListByteList.suite());
|
||||
suite.addTest(TestIteratorByteIterator.suite());
|
||||
suite.addTest(TestListIteratorByteListIterator.suite());
|
||||
suite.addTest(TestByteIteratorIterator.suite());
|
||||
suite.addTest(TestByteListIteratorListIterator.suite());
|
||||
|
||||
suite.addTest(TestCollectionShortCollection.suite());
|
||||
suite.addTest(TestShortCollectionCollection.suite());
|
||||
suite.addTest(TestShortListList.suite());
|
||||
|
|
|
@ -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/TestByteCollectionCollection.java,v 1.1 2003/04/15 01:55:21 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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.RandomAccessByteList;
|
||||
import org.apache.commons.collections.primitives.ArrayByteList;
|
||||
import org.apache.commons.collections.primitives.ByteList;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:21 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class TestByteCollectionCollection extends TestObject {
|
||||
|
||||
// conventional
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public TestByteCollectionCollection(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestByteCollectionCollection.class);
|
||||
}
|
||||
|
||||
// collections testing framework
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
protected Object makeObject() {
|
||||
ByteList list = new ArrayByteList();
|
||||
for(int i=0;i<10;i++) {
|
||||
list.add((byte)i);
|
||||
}
|
||||
return new ByteCollectionCollection(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(ByteCollectionCollection.wrap(null));
|
||||
}
|
||||
|
||||
public void testWrapSerializable() {
|
||||
Collection collection = ByteCollectionCollection.wrap(new ArrayByteList());
|
||||
assertNotNull(collection);
|
||||
assertTrue(collection instanceof Serializable);
|
||||
}
|
||||
|
||||
public void testWrapNonSerializable() {
|
||||
Collection collection = ByteCollectionCollection.wrap(new RandomAccessByteList() {
|
||||
public byte get(int i) { throw new IndexOutOfBoundsException(); }
|
||||
public int size() { return 0; }
|
||||
});
|
||||
assertNotNull(collection);
|
||||
assertTrue(!(collection instanceof Serializable));
|
||||
}
|
||||
|
||||
}
|
|
@ -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/TestByteIteratorIterator.java,v 1.1 2003/04/15 01:55:21 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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.ArrayByteList;
|
||||
import org.apache.commons.collections.primitives.ByteList;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:21 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class TestByteIteratorIterator extends TestIterator {
|
||||
|
||||
// conventional
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public TestByteIteratorIterator(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestByteIteratorIterator.class);
|
||||
}
|
||||
|
||||
// collections testing framework
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public Object makeObject() {
|
||||
return makeFullIterator();
|
||||
}
|
||||
|
||||
public Iterator makeEmptyIterator() {
|
||||
return ByteIteratorIterator.wrap(makeEmptyByteList().iterator());
|
||||
}
|
||||
|
||||
public Iterator makeFullIterator() {
|
||||
return ByteIteratorIterator.wrap(makeFullByteList().iterator());
|
||||
}
|
||||
|
||||
protected ByteList makeEmptyByteList() {
|
||||
return new ArrayByteList();
|
||||
}
|
||||
|
||||
protected ByteList makeFullByteList() {
|
||||
ByteList list = makeEmptyByteList();
|
||||
byte[] elts = getFullElements();
|
||||
for(int i=0;i<elts.length;i++) {
|
||||
list.add((byte)elts[i]);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public byte[] getFullElements() {
|
||||
return new byte[] { (byte)0, (byte)1, (byte)2, (byte)3, (byte)4, (byte)5, (byte)6, (byte)7, (byte)8, (byte)9 };
|
||||
}
|
||||
|
||||
// tests
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/adapters/Attic/TestByteListIteratorListIterator.java,v 1.1 2003/04/15 01:55:21 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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.ArrayByteList;
|
||||
import org.apache.commons.collections.primitives.ByteList;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:21 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class TestByteListIteratorListIterator extends TestListIterator {
|
||||
|
||||
// conventional
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public TestByteListIteratorListIterator(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestByteListIteratorListIterator.class);
|
||||
}
|
||||
|
||||
// collections testing framework
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public Object makeObject() {
|
||||
return makeFullIterator();
|
||||
}
|
||||
|
||||
public ListIterator makeEmptyListIterator() {
|
||||
return ByteListIteratorListIterator.wrap(makeEmptyByteList().listIterator());
|
||||
}
|
||||
|
||||
public ListIterator makeFullListIterator() {
|
||||
return ByteListIteratorListIterator.wrap(makeFullByteList().listIterator());
|
||||
}
|
||||
|
||||
protected ByteList makeEmptyByteList() {
|
||||
return new ArrayByteList();
|
||||
}
|
||||
|
||||
protected ByteList makeFullByteList() {
|
||||
ByteList list = makeEmptyByteList();
|
||||
byte[] elts = getFullElements();
|
||||
for(int i=0;i<elts.length;i++) {
|
||||
list.add((byte)elts[i]);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public byte[] getFullElements() {
|
||||
return new byte[] { (byte)0, (byte)1, (byte)2, (byte)3, (byte)4, (byte)5, (byte)6, (byte)7, (byte)8, (byte)9 };
|
||||
}
|
||||
|
||||
// tests
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
public void testNextHasNextRemove() {
|
||||
byte[] elements = getFullElements();
|
||||
Iterator iter = makeFullIterator();
|
||||
for(int i=0;i<elements.length;i++) {
|
||||
assertTrue(iter.hasNext());
|
||||
assertEquals(new Byte(elements[i]),iter.next());
|
||||
if(supportsRemove()) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
assertTrue(! iter.hasNext() );
|
||||
}
|
||||
|
||||
public void testEmptyIterator() {
|
||||
assertTrue( ! makeEmptyIterator().hasNext() );
|
||||
try {
|
||||
makeEmptyIterator().next();
|
||||
fail("Expected NoSuchElementException");
|
||||
} catch(NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
if(supportsRemove()) {
|
||||
try {
|
||||
makeEmptyIterator().remove();
|
||||
fail("Expected IllegalStateException");
|
||||
} catch(IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testRemoveBeforeNext() {
|
||||
if(supportsRemove()) {
|
||||
try {
|
||||
makeFullIterator().remove();
|
||||
fail("Expected IllegalStateException");
|
||||
} catch(IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testRemoveAfterRemove() {
|
||||
if(supportsRemove()) {
|
||||
Iterator iter = makeFullIterator();
|
||||
iter.next();
|
||||
iter.remove();
|
||||
try {
|
||||
iter.remove();
|
||||
fail("Expected IllegalStateException");
|
||||
} catch(IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/adapters/Attic/TestByteListList.java,v 1.1 2003/04/15 01:55:21 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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.RandomAccessByteList;
|
||||
import org.apache.commons.collections.primitives.ArrayByteList;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:21 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class TestByteListList extends TestList {
|
||||
|
||||
// conventional
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public TestByteListList(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = BulkTest.makeSuite(TestByteListList.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
// collections testing framework
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
protected List makeEmptyList() {
|
||||
return new ByteListList(new ArrayByteList());
|
||||
}
|
||||
|
||||
protected Object[] getFullElements() {
|
||||
Byte[] elts = new Byte[10];
|
||||
for(int i=0;i<elts.length;i++) {
|
||||
elts[i] = new Byte((byte)i);
|
||||
}
|
||||
return elts;
|
||||
}
|
||||
|
||||
protected Object[] getOtherElements() {
|
||||
Byte[] elts = new Byte[10];
|
||||
for(int i=0;i<elts.length;i++) {
|
||||
elts[i] = new Byte((byte)(10 + i));
|
||||
}
|
||||
return elts;
|
||||
}
|
||||
|
||||
// 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(ByteListList.wrap(null));
|
||||
}
|
||||
|
||||
public void testWrapSerializable() {
|
||||
List list = ByteListList.wrap(new ArrayByteList());
|
||||
assertNotNull(list);
|
||||
assertTrue(list instanceof Serializable);
|
||||
}
|
||||
|
||||
public void testWrapNonSerializable() {
|
||||
List list = ByteListList.wrap(new RandomAccessByteList() {
|
||||
public byte get(int i) { throw new IndexOutOfBoundsException(); }
|
||||
public int size() { return 0; }
|
||||
});
|
||||
assertNotNull(list);
|
||||
assertTrue(!(list instanceof Serializable));
|
||||
}
|
||||
}
|
|
@ -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/TestCollectionByteCollection.java,v 1.1 2003/04/15 01:55:21 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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.ByteCollection;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:21 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class TestCollectionByteCollection extends TestObject {
|
||||
|
||||
// conventional
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public TestCollectionByteCollection(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestCollectionByteCollection.class);
|
||||
}
|
||||
|
||||
// collections testing framework
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
protected Object makeObject() {
|
||||
List list = new ArrayList();
|
||||
for(int i=0;i<10;i++) {
|
||||
list.add(new Byte((byte)i));
|
||||
}
|
||||
return new CollectionByteCollection(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(CollectionByteCollection.wrap(null));
|
||||
}
|
||||
|
||||
public void testWrapSerializable() {
|
||||
ByteCollection collection = CollectionByteCollection.wrap(new ArrayList());
|
||||
assertNotNull(collection);
|
||||
assertTrue(collection instanceof Serializable);
|
||||
}
|
||||
|
||||
public void testWrapNonSerializable() {
|
||||
ByteCollection collection = CollectionByteCollection.wrap(new AbstractList() {
|
||||
public Object get(int i) { throw new IndexOutOfBoundsException(); }
|
||||
public int size() { return 0; }
|
||||
});
|
||||
assertNotNull(collection);
|
||||
assertTrue(!(collection instanceof Serializable));
|
||||
}
|
||||
|
||||
}
|
|
@ -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/TestIteratorByteIterator.java,v 1.1 2003/04/15 01:55:21 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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.ByteIterator;
|
||||
import org.apache.commons.collections.primitives.TestByteIterator;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:21 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class TestIteratorByteIterator extends TestByteIterator {
|
||||
|
||||
// conventional
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public TestIteratorByteIterator(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestIteratorByteIterator.class);
|
||||
}
|
||||
|
||||
// collections testing framework
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public ByteIterator makeEmptyByteIterator() {
|
||||
return IteratorByteIterator.wrap(makeEmptyList().iterator());
|
||||
}
|
||||
|
||||
public ByteIterator makeFullByteIterator() {
|
||||
return IteratorByteIterator.wrap(makeFullList().iterator());
|
||||
}
|
||||
|
||||
protected List makeEmptyList() {
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
protected List makeFullList() {
|
||||
List list = makeEmptyList();
|
||||
byte[] elts = getFullElements();
|
||||
for(int i=0;i<elts.length;i++) {
|
||||
list.add(new Byte(elts[i]));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public byte[] getFullElements() {
|
||||
return new byte[] { (byte)0, (byte)1, (byte)2, (byte)3, (byte)4, (byte)5, (byte)6, (byte)7, (byte)8, (byte)9 };
|
||||
}
|
||||
|
||||
// tests
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/adapters/Attic/TestListByteList.java,v 1.1 2003/04/15 01:55:21 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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.ByteList;
|
||||
import org.apache.commons.collections.primitives.TestByteList;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:21 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class TestListByteList extends TestByteList {
|
||||
|
||||
// conventional
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public TestListByteList(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = BulkTest.makeSuite(TestListByteList.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
// collections testing framework
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @see org.apache.commons.collections.primitives.TestByteList#makeEmptyByteList()
|
||||
*/
|
||||
protected ByteList makeEmptyByteList() {
|
||||
return new ListByteList(new ArrayList());
|
||||
}
|
||||
|
||||
public String[] ignoredSimpleTests() {
|
||||
// sublists are not serializable
|
||||
return new String[] {
|
||||
"TestListByteList.bulkTestSubList.testFullListSerialization",
|
||||
"TestListByteList.bulkTestSubList.testEmptyListSerialization",
|
||||
"TestListByteList.bulkTestSubList.testCanonicalEmptyCollectionExists",
|
||||
"TestListByteList.bulkTestSubList.testCanonicalFullCollectionExists",
|
||||
"TestListByteList.bulkTestSubList.testEmptyListCompatibility",
|
||||
"TestListByteList.bulkTestSubList.testFullListCompatibility",
|
||||
"TestListByteList.bulkTestSubList.testSerializeDeserializeThenCompare",
|
||||
"TestListByteList.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(ListByteList.wrap(null));
|
||||
}
|
||||
|
||||
public void testWrapSerializable() {
|
||||
ByteList list = ListByteList.wrap(new ArrayList());
|
||||
assertNotNull(list);
|
||||
assertTrue(list instanceof Serializable);
|
||||
}
|
||||
|
||||
public void testWrapNonSerializable() {
|
||||
ByteList list = ListByteList.wrap(new AbstractList() {
|
||||
public Object get(int i) { throw new IndexOutOfBoundsException(); }
|
||||
public int size() { return 0; }
|
||||
});
|
||||
assertNotNull(list);
|
||||
assertTrue(!(list instanceof Serializable));
|
||||
}
|
||||
|
||||
}
|
|
@ -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/TestListIteratorByteListIterator.java,v 1.1 2003/04/15 01:55:21 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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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.ByteListIterator;
|
||||
import org.apache.commons.collections.primitives.TestByteListIterator;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/15 01:55:21 $
|
||||
* @author Rodney Waldhoff
|
||||
*/
|
||||
public class TestListIteratorByteListIterator extends TestByteListIterator {
|
||||
|
||||
// conventional
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public TestListIteratorByteListIterator(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestListIteratorByteListIterator.class);
|
||||
}
|
||||
|
||||
// collections testing framework
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public ByteListIterator makeEmptyByteListIterator() {
|
||||
return ListIteratorByteListIterator.wrap(makeEmptyList().listIterator());
|
||||
}
|
||||
|
||||
public ByteListIterator makeFullByteListIterator() {
|
||||
return ListIteratorByteListIterator.wrap(makeFullList().listIterator());
|
||||
}
|
||||
|
||||
protected List makeEmptyList() {
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
protected List makeFullList() {
|
||||
List list = makeEmptyList();
|
||||
byte[] elts = getFullElements();
|
||||
for(int i=0;i<elts.length;i++) {
|
||||
list.add(new Byte(elts[i]));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public byte[] getFullElements() {
|
||||
return new byte[] { (byte)0, (byte)1, (byte)2, (byte)3, (byte)4, (byte)5, (byte)6, (byte)7, (byte)8, (byte)9 };
|
||||
}
|
||||
|
||||
// tests
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue