removed obsolete classes

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1706740 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2015-10-05 00:26:45 +00:00
parent d9c0fb9ce5
commit 8aec6ba738
5 changed files with 0 additions and 5962 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,638 +0,0 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.util;
/**
* A List of short's; as full an implementation of the java.util.List
* interface as possible, with an eye toward minimal creation of
* objects
*
* the mimicry of List is as follows:
* <ul>
* <li> if possible, operations designated 'optional' in the List
* interface are attempted
* <li> wherever the List interface refers to an Object, substitute
* short
* <li> wherever the List interface refers to a Collection or List,
* substitute ShortList
* </ul>
*
* the mimicry is not perfect, however:
* <ul>
* <li> operations involving Iterators or ListIterators are not
* supported
* <li> remove(Object) becomes removeValue to distinguish it from
* remove(short index)
* <li> subList is not supported
* </ul>
*
* @author Marc Johnson
*/
public class ShortList
{
private short[] _array;
private int _limit;
private static final int _default_size = 128;
/**
* create an ShortList of default size
*/
public ShortList()
{
this(_default_size);
}
/**
* create a copy of an existing ShortList
*
* @param list the existing ShortList
*/
public ShortList(final ShortList list)
{
this(list._array.length);
System.arraycopy(list._array, 0, _array, 0, _array.length);
_limit = list._limit;
}
/**
* create an ShortList with a predefined initial size
*
* @param initialCapacity the size for the internal array
*/
public ShortList(final int initialCapacity)
{
_array = new short[ initialCapacity ];
_limit = 0;
}
/**
* add the specfied value at the specified index
*
* @param index the index where the new value is to be added
* @param value the new value
*
* @exception IndexOutOfBoundsException if the index is out of
* range (index < 0 || index > size()).
*/
public void add(final int index, final short value)
{
if (index > _limit)
{
throw new IndexOutOfBoundsException();
}
else if (index == _limit)
{
add(value);
}
else
{
// index < limit -- insert into the middle
if (_limit == _array.length)
{
growArray(_limit * 2);
}
System.arraycopy(_array, index, _array, index + 1,
_limit - index);
_array[ index ] = value;
_limit++;
}
}
/**
* Appends the specified element to the end of this list
*
* @param value element to be appended to this list.
*
* @return true (as per the general contract of the Collection.add
* method).
*/
public boolean add(final short value)
{
if (_limit == _array.length)
{
growArray(_limit * 2);
}
_array[ _limit++ ] = value;
return true;
}
/**
* Appends all of the elements in the specified collection to the
* end of this list, in the order that they are returned by the
* specified collection's iterator. The behavior of this
* operation is unspecified if the specified collection is
* modified while the operation is in progress. (Note that this
* will occur if the specified collection is this list, and it's
* nonempty.)
*
* @param c collection whose elements are to be added to this
* list.
*
* @return true if this list changed as a result of the call.
*/
public boolean addAll(final ShortList c)
{
if (c._limit != 0)
{
if ((_limit + c._limit) > _array.length)
{
growArray(_limit + c._limit);
}
System.arraycopy(c._array, 0, _array, _limit, c._limit);
_limit += c._limit;
}
return true;
}
/**
* Inserts all of the elements in the specified collection into
* this list at the specified position. Shifts the element
* currently at that position (if any) and any subsequent elements
* to the right (increases their indices). The new elements will
* appear in this list in the order that they are returned by the
* specified collection's iterator. The behavior of this
* operation is unspecified if the specified collection is
* modified while the operation is in progress. (Note that this
* will occur if the specified collection is this list, and it's
* nonempty.)
*
* @param index index at which to insert first element from the
* specified collection.
* @param c elements to be inserted into this list.
*
* @return true if this list changed as a result of the call.
*
* @exception IndexOutOfBoundsException if the index is out of
* range (index < 0 || index > size())
*/
public boolean addAll(final int index, final ShortList c)
{
if (index > _limit)
{
throw new IndexOutOfBoundsException();
}
if (c._limit != 0)
{
if ((_limit + c._limit) > _array.length)
{
growArray(_limit + c._limit);
}
// make a hole
System.arraycopy(_array, index, _array, index + c._limit,
_limit - index);
// fill it in
System.arraycopy(c._array, 0, _array, index, c._limit);
_limit += c._limit;
}
return true;
}
/**
* Removes all of the elements from this list. This list will be
* empty after this call returns (unless it throws an exception).
*/
public void clear()
{
_limit = 0;
}
/**
* Returns true if this list contains the specified element. More
* formally, returns true if and only if this list contains at
* least one element e such that o == e
*
* @param o element whose presence in this list is to be tested.
*
* @return true if this list contains the specified element.
*/
public boolean contains(final short o)
{
boolean rval = false;
for (int j = 0; !rval && (j < _limit); j++)
{
if (_array[ j ] == o)
{
rval = true;
}
}
return rval;
}
/**
* Returns true if this list contains all of the elements of the
* specified collection.
*
* @param c collection to be checked for containment in this list.
*
* @return true if this list contains all of the elements of the
* specified collection.
*/
public boolean containsAll(final ShortList c)
{
boolean rval = true;
if (this != c)
{
for (int j = 0; rval && (j < c._limit); j++)
{
if (!contains(c._array[ j ]))
{
rval = false;
}
}
}
return rval;
}
/**
* Compares the specified object with this list for equality.
* Returns true if and only if the specified object is also a
* list, both lists have the same size, and all corresponding
* pairs of elements in the two lists are equal. (Two elements e1
* and e2 are equal if e1 == e2.) In other words, two lists are
* defined to be equal if they contain the same elements in the
* same order. This definition ensures that the equals method
* works properly across different implementations of the List
* interface.
*
* @param o the object to be compared for equality with this list.
*
* @return true if the specified object is equal to this list.
*/
public boolean equals(final Object o)
{
boolean rval = this == o;
if (!rval && (o != null) && (o.getClass() == this.getClass()))
{
ShortList other = ( ShortList ) o;
if (other._limit == _limit)
{
// assume match
rval = true;
for (int j = 0; rval && (j < _limit); j++)
{
rval = _array[ j ] == other._array[ j ];
}
}
}
return rval;
}
/**
* Returns the element at the specified position in this list.
*
* @param index index of element to return.
*
* @return the element at the specified position in this list.
*
* @exception IndexOutOfBoundsException if the index is out of
* range (index < 0 || index >= size()).
*/
public short get(final int index)
{
if (index >= _limit)
{
throw new IndexOutOfBoundsException();
}
return _array[ index ];
}
/**
* Returns the hash code value for this list. The hash code of a
* list is defined to be the result of the following calculation:
*
* <code>
* hashCode = 1;
* Iterator i = list.iterator();
* while (i.hasNext()) {
* Object obj = i.next();
* hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode());
* }
* </code>
*
* This ensures that list1.equals(list2) implies that
* list1.hashCode()==list2.hashCode() for any two lists, list1 and
* list2, as required by the general contract of Object.hashCode.
*
* @return the hash code value for this list.
*/
public int hashCode()
{
int hash = 0;
for (int j = 0; j < _limit; j++)
{
hash = (31 * hash) + _array[ j ];
}
return hash;
}
/**
* Returns the index in this list of the first occurrence of the
* specified element, or -1 if this list does not contain this
* element. More formally, returns the lowest index i such that
* (o == get(i)), or -1 if there is no such index.
*
* @param o element to search for.
*
* @return the index in this list of the first occurrence of the
* specified element, or -1 if this list does not contain
* this element.
*/
public int indexOf(final short o)
{
int rval = 0;
for (; rval < _limit; rval++)
{
if (o == _array[ rval ])
{
break;
}
}
if (rval == _limit)
{
rval = -1; // didn't find it
}
return rval;
}
/**
* Returns true if this list contains no elements.
*
* @return true if this list contains no elements.
*/
public boolean isEmpty()
{
return _limit == 0;
}
/**
* Returns the index in this list of the last occurrence of the
* specified element, or -1 if this list does not contain this
* element. More formally, returns the highest index i such that
* (o == get(i)), or -1 if there is no such index.
*
* @param o element to search for.
*
* @return the index in this list of the last occurrence of the
* specified element, or -1 if this list does not contain
* this element.
*/
public int lastIndexOf(final short o)
{
int rval = _limit - 1;
for (; rval >= 0; rval--)
{
if (o == _array[ rval ])
{
break;
}
}
return rval;
}
/**
* Removes the element at the specified position in this list.
* Shifts any subsequent elements to the left (subtracts one from
* their indices). Returns the element that was removed from the
* list.
*
* @param index the index of the element to removed.
*
* @return the element previously at the specified position.
*
* @exception IndexOutOfBoundsException if the index is out of
* range (index < 0 || index >= size()).
*/
public short remove(final int index)
{
if (index >= _limit)
{
throw new IndexOutOfBoundsException();
}
short rval = _array[ index ];
System.arraycopy(_array, index + 1, _array, index, _limit - index);
_limit--;
return rval;
}
/**
* Removes the first occurrence in this list of the specified
* element (optional operation). If this list does not contain
* the element, it is unchanged. More formally, removes the
* element with the lowest index i such that (o.equals(get(i)))
* (if such an element exists).
*
* @param o element to be removed from this list, if present.
*
* @return true if this list contained the specified element.
*/
public boolean removeValue(final short o)
{
boolean rval = false;
for (int j = 0; !rval && (j < _limit); j++)
{
if (o == _array[ j ])
{
System.arraycopy(_array, j + 1, _array, j, _limit - j);
_limit--;
rval = true;
}
}
return rval;
}
/**
* Removes from this list all the elements that are contained in
* the specified collection
*
* @param c collection that defines which elements will be removed
* from this list.
*
* @return true if this list changed as a result of the call.
*/
public boolean removeAll(final ShortList c)
{
boolean rval = false;
for (int j = 0; j < c._limit; j++)
{
if (removeValue(c._array[ j ]))
{
rval = true;
}
}
return rval;
}
/**
* Retains only the elements in this list that are contained in
* the specified collection. In other words, removes from this
* list all the elements that are not contained in the specified
* collection.
*
* @param c collection that defines which elements this set will
* retain.
*
* @return true if this list changed as a result of the call.
*/
public boolean retainAll(final ShortList c)
{
boolean rval = false;
for (int j = 0; j < _limit; )
{
if (!c.contains(_array[ j ]))
{
remove(j);
rval = true;
}
else
{
j++;
}
}
return rval;
}
/**
* Replaces the element at the specified position in this list
* with the specified element
*
* @param index index of element to replace.
* @param element element to be stored at the specified position.
*
* @return the element previously at the specified position.
*
* @exception IndexOutOfBoundsException if the index is out of
* range (index < 0 || index >= size()).
*/
public short set(final int index, final short element)
{
if (index >= _limit)
{
throw new IndexOutOfBoundsException();
}
short rval = _array[ index ];
_array[ index ] = element;
return rval;
}
/**
* Returns the number of elements in this list. If this list
* contains more than Integer.MAX_VALUE elements, returns
* Integer.MAX_VALUE.
*
* @return the number of elements in this ShortList
*/
public int size()
{
return _limit;
}
/**
* Returns an array containing all of the elements in this list in
* proper sequence. Obeys the general contract of the
* Collection.toArray method.
*
* @return an array containing all of the elements in this list in
* proper sequence.
*/
public short [] toArray()
{
short[] rval = new short[ _limit ];
System.arraycopy(_array, 0, rval, 0, _limit);
return rval;
}
/**
* Returns an array containing all of the elements in this list in
* proper sequence. Obeys the general contract of the
* Collection.toArray(Object[]) method.
*
* @param a the array into which the elements of this list are to
* be stored, if it is big enough; otherwise, a new array
* is allocated for this purpose.
*
* @return an array containing the elements of this list.
*/
public short [] toArray(final short [] a)
{
short[] rval;
if (a.length == _limit)
{
System.arraycopy(_array, 0, a, 0, _limit);
rval = a;
}
else
{
rval = toArray();
}
return rval;
}
private void growArray(final int new_size)
{
int size = (new_size == _array.length) ? new_size + 1
: new_size;
short[] new_array = new short[ size ];
System.arraycopy(_array, 0, new_array, 0, _limit);
_array = new_array;
}
} // end public class ShortList

View File

@ -26,7 +26,6 @@ import org.junit.runners.Suite;
@RunWith(Suite.class) @RunWith(Suite.class)
@Suite.SuiteClasses({ @Suite.SuiteClasses({
TestArrayUtil.class TestArrayUtil.class
, TestBinaryTree.class
, TestBitField.class , TestBitField.class
, TestByteField.class , TestByteField.class
, TestHexDump.class , TestHexDump.class
@ -37,7 +36,6 @@ import org.junit.runners.Suite;
, TestPOILogFactory.class , TestPOILogFactory.class
, TestPOILogger.class , TestPOILogger.class
, TestShortField.class , TestShortField.class
, TestShortList.class
, TestStringUtil.class , TestStringUtil.class
, TestTempFile.class , TestTempFile.class
}) })

File diff suppressed because it is too large Load Diff

View File

@ -1,570 +0,0 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.util;
import junit.framework.TestCase;
/**
* Class to test ShortList
*
* @author Marc Johnson
*/
public final class TestShortList extends TestCase {
public void testConstructors() {
ShortList list = new ShortList();
assertTrue(list.isEmpty());
list.add(( short ) 0);
list.add(( short ) 1);
ShortList list2 = new ShortList(list);
assertEquals(list, list2);
ShortList list3 = new ShortList(2);
assertTrue(list3.isEmpty());
}
public void testAdd() {
ShortList list = new ShortList();
short[] testArray =
{
0, 1, 2, 3, 5
};
for (int j = 0; j < testArray.length; j++)
{
list.add(testArray[ j ]);
}
for (int j = 0; j < testArray.length; j++)
{
assertEquals(testArray[ j ], list.get(j));
}
assertEquals(testArray.length, list.size());
// add at the beginning
list.add(0, ( short ) -1);
assertEquals(( short ) -1, list.get(0));
assertEquals(testArray.length + 1, list.size());
for (int j = 0; j < testArray.length; j++)
{
assertEquals(testArray[ j ], list.get(j + 1));
}
// add in the middle
list.add(5, ( short ) 4);
assertEquals(( short ) 4, list.get(5));
assertEquals(testArray.length + 2, list.size());
for (int j = 0; j < list.size(); j++)
{
assertEquals(( short ) (j - 1), list.get(j));
}
// add at the end
list.add(list.size(), ( short ) 6);
assertEquals(testArray.length + 3, list.size());
for (int j = 0; j < list.size(); j++)
{
assertEquals(( short ) (j - 1), list.get(j));
}
// add past end
try
{
list.add(list.size() + 1, ( short ) 8);
fail("should have thrown exception");
}
catch (IndexOutOfBoundsException e)
{
// as expected
}
// test growth
list = new ShortList(0);
for (short j = 0; j < 1000; j++)
{
list.add(j);
}
assertEquals(1000, list.size());
for (short j = 0; j < 1000; j++)
{
assertEquals(j, list.get(j));
}
list = new ShortList(0);
for (short j = 0; j < 1000; j++)
{
list.add(0, j);
}
assertEquals(1000, list.size());
for (short j = 0; j < 1000; j++)
{
assertEquals(j, list.get(999 - j));
}
}
public void testAddAll() {
ShortList list = new ShortList();
for (short j = 0; j < 5; j++)
{
list.add(j);
}
ShortList list2 = new ShortList(0);
list2.addAll(list);
list2.addAll(list);
assertEquals(2 * list.size(), list2.size());
for (short j = 0; j < 5; j++)
{
assertEquals(list2.get(j), j);
assertEquals(list2.get(j + list.size()), j);
}
ShortList empty = new ShortList();
int limit = list.size();
for (int j = 0; j < limit; j++)
{
assertTrue(list.addAll(j, empty));
assertEquals(limit, list.size());
}
try
{
list.addAll(limit + 1, empty);
fail("should have thrown an exception");
}
catch (IndexOutOfBoundsException e)
{
// as expected
}
// try add at beginning
empty.addAll(0, list);
assertEquals(empty, list);
// try in the middle
empty.addAll(1, list);
assertEquals(2 * list.size(), empty.size());
assertEquals(list.get(0), empty.get(0));
assertEquals(list.get(0), empty.get(1));
assertEquals(list.get(1), empty.get(2));
assertEquals(list.get(1), empty.get(6));
assertEquals(list.get(2), empty.get(3));
assertEquals(list.get(2), empty.get(7));
assertEquals(list.get(3), empty.get(4));
assertEquals(list.get(3), empty.get(8));
assertEquals(list.get(4), empty.get(5));
assertEquals(list.get(4), empty.get(9));
// try at the end
empty.addAll(empty.size(), list);
assertEquals(3 * list.size(), empty.size());
assertEquals(list.get(0), empty.get(0));
assertEquals(list.get(0), empty.get(1));
assertEquals(list.get(0), empty.get(10));
assertEquals(list.get(1), empty.get(2));
assertEquals(list.get(1), empty.get(6));
assertEquals(list.get(1), empty.get(11));
assertEquals(list.get(2), empty.get(3));
assertEquals(list.get(2), empty.get(7));
assertEquals(list.get(2), empty.get(12));
assertEquals(list.get(3), empty.get(4));
assertEquals(list.get(3), empty.get(8));
assertEquals(list.get(3), empty.get(13));
assertEquals(list.get(4), empty.get(5));
assertEquals(list.get(4), empty.get(9));
assertEquals(list.get(4), empty.get(14));
}
public void testClear() {
ShortList list = new ShortList();
for (short j = 0; j < 500; j++)
{
list.add(j);
}
assertEquals(500, list.size());
list.clear();
assertEquals(0, list.size());
for (short j = 0; j < 500; j++)
{
list.add(( short ) (j + 1));
}
assertEquals(500, list.size());
for (short j = 0; j < 500; j++)
{
assertEquals(j + 1, list.get(j));
}
}
public void testContains() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j += 2)
{
list.add(j);
}
for (short j = 0; j < 1000; j++)
{
if (j % 2 == 0)
{
assertTrue(list.contains(j));
}
else
{
assertTrue(!list.contains(j));
}
}
}
public void testContainsAll() {
ShortList list = new ShortList();
assertTrue(list.containsAll(list));
for (short j = 0; j < 10; j++)
{
list.add(j);
}
ShortList list2 = new ShortList(list);
assertTrue(list2.containsAll(list));
assertTrue(list.containsAll(list2));
list2.add(( short ) 10);
assertTrue(list2.containsAll(list));
assertTrue(!list.containsAll(list2));
list.add(( short ) 11);
assertTrue(!list2.containsAll(list));
assertTrue(!list.containsAll(list2));
}
public void testEquals() {
ShortList list = new ShortList();
assertEquals(list, list);
assertTrue(!list.equals(null));
ShortList list2 = new ShortList(200);
assertEquals(list, list2);
assertEquals(list2, list);
assertEquals(list.hashCode(), list2.hashCode());
list.add(( short ) 0);
list.add(( short ) 1);
list2.add(( short ) 1);
list2.add(( short ) 0);
assertTrue(!list.equals(list2));
list2.removeValue(( short ) 1);
list2.add(( short ) 1);
assertEquals(list, list2);
assertEquals(list2, list);
list2.add(( short ) 2);
assertTrue(!list.equals(list2));
assertTrue(!list2.equals(list));
}
public void testGet() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
{
list.add(j);
}
for (short j = 0; j < 1001; j++)
{
try
{
assertEquals(j, list.get(j));
if (j == 1000)
{
fail("should have gotten exception");
}
}
catch (IndexOutOfBoundsException e)
{
if (j != 1000)
{
fail("unexpected IndexOutOfBoundsException");
}
}
}
}
public void testIndexOf() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
{
list.add(( short ) (j / 2));
}
for (short j = 0; j < 1000; j++)
{
if (j < 500)
{
assertEquals(j * 2, list.indexOf(j));
}
else
{
assertEquals(-1, list.indexOf(j));
}
}
}
public void testIsEmpty() {
ShortList list1 = new ShortList();
ShortList list2 = new ShortList(1000);
ShortList list3 = new ShortList(list1);
assertTrue(list1.isEmpty());
assertTrue(list2.isEmpty());
assertTrue(list3.isEmpty());
list1.add(( short ) 1);
list2.add(( short ) 2);
list3 = new ShortList(list2);
assertTrue(!list1.isEmpty());
assertTrue(!list2.isEmpty());
assertTrue(!list3.isEmpty());
list1.clear();
list2.remove(0);
list3.removeValue(( short ) 2);
assertTrue(list1.isEmpty());
assertTrue(list2.isEmpty());
assertTrue(list3.isEmpty());
}
public void testLastIndexOf() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
{
list.add(( short ) (j / 2));
}
for (short j = 0; j < 1000; j++)
{
if (j < 500)
{
assertEquals(1 + j * 2, list.lastIndexOf(j));
}
else
{
assertEquals(-1, list.indexOf(j));
}
}
}
public void testRemove() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
{
list.add(j);
}
for (short j = 0; j < 1000; j++)
{
assertEquals(j, list.remove(0));
assertEquals(( short ) (999 - j), list.size());
}
for (short j = 0; j < 1000; j++)
{
list.add(j);
}
for (short j = 0; j < 1000; j++)
{
assertEquals(( short ) (999 - j),
list.remove(( short ) (999 - j)));
assertEquals(999 - j, list.size());
}
try
{
list.remove(0);
fail("should have caught IndexOutOfBoundsException");
}
catch (IndexOutOfBoundsException e)
{
// as expected
}
}
public void testRemoveValue() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
{
list.add(( short ) (j / 2));
}
for (short j = 0; j < 1000; j++)
{
if (j < 500)
{
assertTrue(list.removeValue(j));
assertTrue(list.removeValue(j));
}
assertTrue(!list.removeValue(j));
}
}
public void testRemoveAll() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
{
list.add(j);
}
ShortList listCopy = new ShortList(list);
ShortList listOdd = new ShortList();
ShortList listEven = new ShortList();
for (short j = 0; j < 1000; j++)
{
if (j % 2 == 0)
{
listEven.add(j);
}
else
{
listOdd.add(j);
}
}
list.removeAll(listEven);
assertEquals(list, listOdd);
list.removeAll(listOdd);
assertTrue(list.isEmpty());
listCopy.removeAll(listOdd);
assertEquals(listCopy, listEven);
listCopy.removeAll(listEven);
assertTrue(listCopy.isEmpty());
}
public void testRetainAll() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
{
list.add(j);
}
ShortList listCopy = new ShortList(list);
ShortList listOdd = new ShortList();
ShortList listEven = new ShortList();
for (short j = 0; j < 1000; j++)
{
if (j % 2 == 0)
{
listEven.add(j);
}
else
{
listOdd.add(j);
}
}
list.retainAll(listOdd);
assertEquals(list, listOdd);
list.retainAll(listEven);
assertTrue(list.isEmpty());
listCopy.retainAll(listEven);
assertEquals(listCopy, listEven);
listCopy.retainAll(listOdd);
assertTrue(listCopy.isEmpty());
}
public void testSet() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
{
list.add(j);
}
for (short j = 0; j < 1001; j++)
{
try
{
list.set(j, ( short ) (j + 1));
if (j == 1000)
{
fail("Should have gotten exception");
}
assertEquals(j + 1, list.get(j));
}
catch (IndexOutOfBoundsException e)
{
if (j != 1000)
{
fail("premature exception");
}
}
}
}
public void testSize() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
{
assertEquals(j, list.size());
list.add(j);
assertEquals(j + 1, list.size());
}
for (short j = 0; j < 1000; j++)
{
assertEquals(1000 - j, list.size());
list.removeValue(j);
assertEquals(999 - j, list.size());
}
}
public void testToArray() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
{
list.add(j);
}
short[] a1 = list.toArray();
assertEquals(a1.length, list.size());
for (short j = 0; j < 1000; j++)
{
assertEquals(a1[ j ], list.get(j));
}
short[] a2 = new short[ list.size() ];
short[] a3 = list.toArray(a2);
assertSame(a2, a3);
for (short j = 0; j < 1000; j++)
{
assertEquals(a2[ j ], list.get(j));
}
short[] aShort = new short[ list.size() - 1 ];
short[] aLong = new short[ list.size() + 1 ];
short[] a4 = list.toArray(aShort);
short[] a5 = list.toArray(aLong);
assertTrue(a4 != aShort);
assertTrue(a5 != aLong);
assertEquals(a4.length, list.size());
for (short j = 0; j < 1000; j++)
{
assertEquals(a3[ j ], list.get(j));
}
assertEquals(a5.length, list.size());
for (short j = 0; j < 1000; j++)
{
assertEquals(a5[ j ], list.get(j));
}
}
}