You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2009/09/15 07:30:02 UTC
svn commit: r814997 [13/18] - in /commons/proper/collections/trunk/src:
java/org/apache/commons/collections/ java/org/apache/commons/collections/bag/
java/org/apache/commons/collections/bidimap/
java/org/apache/commons/collections/buffer/ java/org/apac...
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPriorityBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPriorityBuffer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPriorityBuffer.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPriorityBuffer.java Tue Sep 15 05:29:56 2009
@@ -42,7 +42,7 @@
* @author Michael A. Smith
* @author Steve Phelps
*/
-public class TestPriorityBuffer extends AbstractTestCollection {
+public class TestPriorityBuffer<E> extends AbstractTestCollection<E> {
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
@@ -56,22 +56,23 @@
super(testName);
}
- //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void verify() {
super.verify();
- PriorityBuffer heap = (PriorityBuffer) collection;
+ PriorityBuffer<E> heap = getCollection();
- Comparator c = heap.comparator;
+ Comparator<? super E> c = heap.comparator;
if (c == null) {
- c = ComparatorUtils.naturalComparator();
+ c = ComparatorUtils.NATURAL_COMPARATOR;
}
if (!heap.ascendingOrder) {
c = ComparatorUtils.reversedComparator(c);
}
- Object[] tree = heap.elements;
+ E[] tree = heap.elements;
for (int i = 1; i <= heap.size; i++) {
- Object parent = tree[i];
+ E parent = tree[i];
if (i * 2 <= heap.size) {
assertTrue("Parent is less than or equal to its left child", c.compare(parent, tree[i * 2]) <= 0);
}
@@ -81,7 +82,7 @@
}
}
- //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
/**
* Overridden because BinaryBuffer isn't fail fast.
* @return false
@@ -90,13 +91,13 @@
return false;
}
- //-----------------------------------------------------------------------
- public Collection makeConfirmedCollection() {
- return new ArrayList();
+ //-----------------------------------------------------------------------
+ public Collection<E> makeConfirmedCollection() {
+ return new ArrayList<E>();
}
- public Collection makeConfirmedFullCollection() {
- ArrayList list = new ArrayList();
+ public Collection<E> makeConfirmedFullCollection() {
+ ArrayList<E> list = new ArrayList<E>();
list.addAll(Arrays.asList(getFullElements()));
return list;
}
@@ -104,23 +105,25 @@
/**
* Return a new, empty {@link Object} to used for testing.
*/
- public Collection makeCollection() {
- return new PriorityBuffer();
+ public Buffer<E> makeObject() {
+ return new PriorityBuffer<E>();
}
- //-----------------------------------------------------------------------
- public Object[] getFullElements() {
- return getFullNonNullStringElements();
+ //-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
+ public E[] getFullElements() {
+ return (E[]) getFullNonNullStringElements();
}
- public Object[] getOtherElements() {
- return getOtherNonNullStringElements();
+ @SuppressWarnings("unchecked")
+ public E[] getOtherElements() {
+ return (E[]) getOtherNonNullStringElements();
}
- //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
public void testBufferEmpty() {
resetEmpty();
- Buffer buffer = (Buffer) collection;
+ Buffer<E> buffer = getCollection();
assertEquals(0, buffer.size());
assertEquals(true, buffer.isEmpty());
@@ -134,24 +137,24 @@
fail();
} catch (BufferUnderflowException ex) {}
}
-
- public void testBasicOps() {
- PriorityBuffer heap = new PriorityBuffer();
- heap.add("a");
- heap.add("c");
- heap.add("e");
- heap.add("b");
- heap.add("d");
- heap.add("n");
- heap.add("m");
- heap.add("l");
- heap.add("k");
- heap.add("j");
- heap.add("i");
- heap.add("h");
- heap.add("g");
- heap.add("f");
+ @SuppressWarnings("unchecked")
+ public void testBasicOps() {
+ PriorityBuffer<E> heap = new PriorityBuffer<E>();
+ heap.add((E) "a");
+ heap.add((E) "c");
+ heap.add((E) "e");
+ heap.add((E) "b");
+ heap.add((E) "d");
+ heap.add((E) "n");
+ heap.add((E) "m");
+ heap.add((E) "l");
+ heap.add((E) "k");
+ heap.add((E) "j");
+ heap.add((E) "i");
+ heap.add((E) "h");
+ heap.add((E) "g");
+ heap.add((E) "f");
assertTrue("heap should not be empty after adds", !heap.isEmpty());
@@ -184,8 +187,9 @@
} catch (BufferUnderflowException ex) {}
}
+ @SuppressWarnings("unchecked")
public void testBasicComparatorOps() {
- PriorityBuffer heap = new PriorityBuffer(new ReverseComparator(new ComparableComparator()));
+ PriorityBuffer<E> heap = new PriorityBuffer<E>(new ReverseComparator<E>((Comparator<E>) ComparableComparator.INSTANCE));
assertTrue("heap should be empty after create", heap.isEmpty());
@@ -199,20 +203,20 @@
fail("NoSuchElementException should be thrown if remove is called before any elements are added");
} catch (BufferUnderflowException ex) {}
- heap.add("a");
- heap.add("c");
- heap.add("e");
- heap.add("b");
- heap.add("d");
- heap.add("n");
- heap.add("m");
- heap.add("l");
- heap.add("k");
- heap.add("j");
- heap.add("i");
- heap.add("h");
- heap.add("g");
- heap.add("f");
+ heap.add((E) "a");
+ heap.add((E) "c");
+ heap.add((E) "e");
+ heap.add((E) "b");
+ heap.add((E) "d");
+ heap.add((E) "n");
+ heap.add((E) "m");
+ heap.add((E) "l");
+ heap.add((E) "k");
+ heap.add((E) "j");
+ heap.add((E) "i");
+ heap.add((E) "h");
+ heap.add((E) "g");
+ heap.add((E) "f");
assertTrue("heap should not be empty after adds", !heap.isEmpty());
@@ -250,28 +254,28 @@
}
/**
- * Illustrates bad internal heap state reported in Bugzilla PR #235818.
- */
+ * Illustrates bad internal heap state reported in Bugzilla PR #235818.
+ */
+ @SuppressWarnings("unchecked")
public void testAddRemove() {
resetEmpty();
- PriorityBuffer heap = (PriorityBuffer) collection;
- heap.add(new Integer(0));
- heap.add(new Integer(2));
- heap.add(new Integer(4));
- heap.add(new Integer(3));
- heap.add(new Integer(8));
- heap.add(new Integer(10));
- heap.add(new Integer(12));
- heap.add(new Integer(3));
- confirmed.addAll(heap);
+ PriorityBuffer heap = getCollection();
+ heap.add(0);
+ heap.add(2);
+ heap.add(4);
+ heap.add(3);
+ heap.add(8);
+ heap.add(10);
+ heap.add(12);
+ heap.add(3);
+ getConfirmed().addAll(heap);
// System.out.println(heap);
- Object obj = new Integer(10);
- heap.remove(obj);
- confirmed.remove(obj);
+ heap.remove(10);
+ getConfirmed().remove(10);
// System.out.println(heap);
verify();
}
-
+
/**
* Generate heaps staring with Integers from 0 - heapSize - 1.
* Then perform random add / remove operations, checking
@@ -285,29 +289,29 @@
int heapSize = 100;
int operations = 20;
Random randGenerator = new Random();
- PriorityBuffer h = null;
- for(int i=0; i < iterations; i++) {
- if (i < iterations / 2) {
- h = new PriorityBuffer(true);
+ PriorityBuffer<Integer> h = null;
+ for (int i = 0; i < iterations; i++) {
+ if (i < iterations / 2) {
+ h = new PriorityBuffer<Integer>(true);
} else {
- h = new PriorityBuffer(false);
+ h = new PriorityBuffer<Integer>(false);
}
- for(int r = 0; r < heapSize; r++) {
- h.add( new Integer( randGenerator.nextInt(heapSize)) );
+ for (int r = 0; r < heapSize; r++) {
+ h.add(randGenerator.nextInt(heapSize));
}
- for( int r = 0; r < operations; r++ ) {
+ for (int r = 0; r < operations; r++) {
h.remove(new Integer(r));
- h.add(new Integer(randGenerator.nextInt(heapSize)));
+ h.add(randGenerator.nextInt(heapSize));
}
checkOrder(h);
}
}
-
+
/**
* Pops all elements from the heap and verifies that the elements come off
* in the correct order. NOTE: this method empties the heap.
*/
- protected void checkOrder(PriorityBuffer h) {
+ protected void checkOrder(PriorityBuffer<?> h) {
Integer lastNum = null;
Integer num = null;
while (!h.isEmpty()) {
@@ -321,17 +325,17 @@
num = null;
}
}
-
+
/**
* Returns a string showing the contents of the heap formatted as a tree.
- * Makes no attempt at padding levels or handling wrapping.
+ * Makes no attempt at padding levels or handling wrapping.
*/
- protected String showTree(PriorityBuffer h) {
+ protected String showTree(PriorityBuffer<?> h) {
int count = 1;
StringBuffer buffer = new StringBuffer();
for (int offset = 1; count < h.size() + 1; offset *= 2) {
for (int i = offset; i < offset * 2; i++) {
- if (i < h.elements.length && h.elements[i] != null)
+ if (i < h.elements.length && h.elements[i] != null)
buffer.append(h.elements[i] + " ");
count++;
}
@@ -344,15 +348,16 @@
* Generates 500 randomly initialized heaps of size 100
* and tests that after serializing and restoring them to a byte array
* that the following conditions hold:
- *
- * - the size of the restored heap is the same
+ *
+ * - the size of the restored heap is the same
* as the size of the orignal heap
- *
+ *
* - all elements in the original heap are present in the restored heap
- *
- * - the heap order of the restored heap is intact as
+ *
+ * - the heap order of the restored heap is intact as
* verified by checkOrder()
*/
+ @SuppressWarnings("unchecked")
public void testSerialization() {
int iterations = 500;
int heapSize = 100;
@@ -360,17 +365,17 @@
Random randGenerator = new Random();
for (int i = 0; i < iterations; i++) {
if (i < iterations / 2) {
- h = new PriorityBuffer(true);
+ h = new PriorityBuffer<E>(true);
} else {
- h = new PriorityBuffer(false);
+ h = new PriorityBuffer<E>(false);
}
for (int r = 0; r < heapSize; r++) {
h.add(new Integer(randGenerator.nextInt(heapSize)));
}
assertTrue(h.size() == heapSize);
- PriorityBuffer h1 = serializeAndRestore(h);
+ PriorityBuffer<?> h1 = serializeAndRestore(h);
assertTrue(h1.size() == heapSize);
- Iterator hit = h.iterator();
+ Iterator<?> hit = h.iterator();
while (hit.hasNext()) {
Integer n = (Integer) hit.next();
assertTrue(h1.contains(n));
@@ -379,11 +384,11 @@
}
}
- public PriorityBuffer serializeAndRestore(PriorityBuffer h) {
- PriorityBuffer h1 = null;
+ public PriorityBuffer<?> serializeAndRestore(PriorityBuffer<E> h) {
+ PriorityBuffer<?> h1 = null;
try {
byte[] objekt = writeExternalFormToBytes(h);
- h1 = (PriorityBuffer) readExternalFormFromBytes(objekt);
+ h1 = (PriorityBuffer<?>) readExternalFormFromBytes(objekt);
} catch (IOException e) {
e.printStackTrace();
fail(e.toString());
@@ -405,4 +410,11 @@
// writeExternalFormToDisk((java.io.Serializable) collection, "C:/commons/collections/data/test/PriorityBuffer.fullCollection.version3.2.obj");
// }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public PriorityBuffer<E> getCollection() {
+ return (PriorityBuffer<E>) super.getCollection();
+ }
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestSynchronizedBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestSynchronizedBuffer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestSynchronizedBuffer.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestSynchronizedBuffer.java Tue Sep 15 05:29:56 2009
@@ -27,7 +27,7 @@
import org.apache.commons.collections.collection.AbstractTestCollection;
/**
- * Extension of {@link AbstractTestCollection} for exercising the
+ * Extension of {@link AbstractTestCollection} for exercising the
* {@link SynchronizedBuffer} implementation.
*
* @since Commons Collections 3.1
@@ -36,39 +36,38 @@
* @author Phil Steitz
* @author Stephen Colebourne
*/
-public class TestSynchronizedBuffer extends AbstractTestCollection {
-
+public class TestSynchronizedBuffer<E> extends AbstractTestCollection<E> {
+
public TestSynchronizedBuffer(String testName) {
super(testName);
}
-
+
public static Test suite() {
return new TestSuite(TestSynchronizedBuffer.class);
}
-
+
public static void main(String args[]) {
String[] testCaseName = { TestSynchronizedBuffer.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
- //-----------------------------------------------------------------------
- public Collection makeCollection() {
- return SynchronizedBuffer.decorate(new UnboundedFifoBuffer());
- }
-
- public Collection makeFullCollection() {
- Buffer buffer = new UnboundedFifoBuffer();
+ //-----------------------------------------------------------------------
+ public Buffer<E> makeObject() {
+ return SynchronizedBuffer.decorate(new UnboundedFifoBuffer<E>());
+ }
+
+ public Collection<E> makeFullCollection() {
+ Buffer<E> buffer = new UnboundedFifoBuffer<E>();
buffer.addAll(Arrays.asList(getFullElements()));
return SynchronizedBuffer.decorate(buffer);
}
-
- public Collection makeConfirmedCollection() {
- ArrayStack list = new ArrayStack();
- return list;
+
+ public Collection<E> makeConfirmedCollection() {
+ return new ArrayStack<E>();
}
- public Collection makeConfirmedFullCollection() {
- ArrayStack list = new ArrayStack();
+ public Collection<E> makeConfirmedFullCollection() {
+ ArrayStack<E> list = new ArrayStack<E>();
list.addAll(Arrays.asList(getFullElements()));
return list;
}
@@ -76,7 +75,7 @@
public boolean isNullSupported() {
return false;
}
-
+
public String getCompatibilityVersion() {
return "3.1";
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestTransformedBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestTransformedBuffer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestTransformedBuffer.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestTransformedBuffer.java Tue Sep 15 05:29:56 2009
@@ -49,9 +49,9 @@
}
public void testTransformedBuffer() {
- Buffer buffer = TransformedBuffer.decorate(new ArrayStack(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
+ Buffer<Object> buffer = TransformedBuffer.decorate(new ArrayStack<Object>(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, buffer.size());
- Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
+ Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" };
for (int i = 0; i < els.length; i++) {
buffer.add(els[i]);
assertEquals(i + 1, buffer.size());
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestUnboundedFifoBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestUnboundedFifoBuffer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestUnboundedFifoBuffer.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestUnboundedFifoBuffer.java Tue Sep 15 05:29:56 2009
@@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
import junit.framework.Test;
@@ -32,7 +33,7 @@
*
* @author Unknown
*/
-public class TestUnboundedFifoBuffer extends AbstractTestCollection {
+public class TestUnboundedFifoBuffer<E> extends AbstractTestCollection<E> {
public TestUnboundedFifoBuffer(String n) {
super(n);
@@ -49,8 +50,8 @@
*/
public void verify() {
super.verify();
- Iterator iterator1 = collection.iterator();
- Iterator iterator2 = confirmed.iterator();
+ Iterator<E> iterator1 = getCollection().iterator();
+ Iterator<E> iterator2 = getConfirmed().iterator();
while (iterator2.hasNext()) {
assertTrue(iterator1.hasNext());
Object o1 = iterator1.next();
@@ -82,8 +83,8 @@
*
* @return an empty ArrayList
*/
- public Collection makeConfirmedCollection() {
- return new ArrayList();
+ public Collection<E> makeConfirmedCollection() {
+ return new ArrayList<E>();
}
/**
@@ -91,8 +92,8 @@
*
* @return a full ArrayList
*/
- public Collection makeConfirmedFullCollection() {
- Collection c = makeConfirmedCollection();
+ public Collection<E> makeConfirmedFullCollection() {
+ Collection<E> c = makeConfirmedCollection();
c.addAll(java.util.Arrays.asList(getFullElements()));
return c;
}
@@ -102,8 +103,8 @@
*
* @return an empty UnboundedFifoBuffer
*/
- public Collection makeCollection() {
- return new UnboundedFifoBuffer(5);
+ public Collection<E> makeObject() {
+ return new UnboundedFifoBuffer<E>(5);
}
//-----------------------------------------------------------------------
@@ -112,10 +113,10 @@
*/
public void testUnboundedFifoBufferRemove() {
resetFull();
- int size = confirmed.size();
+ int size = getConfirmed().size();
for (int i = 0; i < size; i++) {
- Object o1 = ((UnboundedFifoBuffer)collection).remove();
- Object o2 = ((ArrayList)confirmed).remove(0);
+ E o1 = getCollection().remove();
+ E o2 = getConfirmed().remove(0);
assertEquals("Removed objects should be equal", o1, o2);
verify();
}
@@ -126,7 +127,7 @@
*/
public void testConstructorException1() {
try {
- new UnboundedFifoBuffer(0);
+ new UnboundedFifoBuffer<E>(0);
} catch (IllegalArgumentException ex) {
return;
}
@@ -138,7 +139,7 @@
*/
public void testConstructorException2() {
try {
- new UnboundedFifoBuffer(-20);
+ new UnboundedFifoBuffer<E>(-20);
} catch (IllegalArgumentException ex) {
return;
}
@@ -146,43 +147,45 @@
}
//-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void testInternalStateAdd() {
- UnboundedFifoBuffer test = new UnboundedFifoBuffer(2);
+ UnboundedFifoBuffer<E> test = new UnboundedFifoBuffer<E>(2);
assertEquals(3, test.buffer.length);
assertEquals(0, test.head);
assertEquals(0, test.tail);
- test.add("A");
+ test.add((E) "A");
assertEquals(3, test.buffer.length);
assertEquals(0, test.head);
assertEquals(1, test.tail);
- test.add("B");
+ test.add((E) "B");
assertEquals(3, test.buffer.length);
assertEquals(0, test.head);
assertEquals(2, test.tail);
- test.add("C"); // forces buffer increase
+ test.add((E) "C"); // forces buffer increase
assertEquals(5, test.buffer.length);
assertEquals(0, test.head);
assertEquals(3, test.tail);
- test.add("D");
+ test.add((E) "D");
assertEquals(5, test.buffer.length);
assertEquals(0, test.head);
assertEquals(4, test.tail);
}
+ @SuppressWarnings("unchecked")
public void testInternalStateAddWithWrap() {
- UnboundedFifoBuffer test = new UnboundedFifoBuffer(3);
+ UnboundedFifoBuffer<E> test = new UnboundedFifoBuffer<E>(3);
assertEquals(4, test.buffer.length);
assertEquals(0, test.head);
assertEquals(0, test.tail);
- test.add("A");
+ test.add((E) "A");
assertEquals(4, test.buffer.length);
assertEquals(0, test.head);
assertEquals(1, test.tail);
- test.add("B");
+ test.add((E) "B");
assertEquals(4, test.buffer.length);
assertEquals(0, test.head);
assertEquals(2, test.tail);
- test.add("C");
+ test.add((E) "C");
assertEquals(4, test.buffer.length);
assertEquals(0, test.head);
assertEquals(3, test.tail);
@@ -194,21 +197,22 @@
assertEquals(4, test.buffer.length);
assertEquals(2, test.head);
assertEquals(3, test.tail);
- test.add("D");
+ test.add((E) "D");
assertEquals(4, test.buffer.length);
assertEquals(2, test.head);
assertEquals(0, test.tail);
- test.add("E");
+ test.add((E) "E");
assertEquals(4, test.buffer.length);
assertEquals(2, test.head);
assertEquals(1, test.tail);
}
+ @SuppressWarnings("unchecked")
public void testInternalStateRemove1() {
- UnboundedFifoBuffer test = new UnboundedFifoBuffer(4);
- test.add("A");
- test.add("B");
- test.add("C");
+ UnboundedFifoBuffer<E> test = new UnboundedFifoBuffer<E>(4);
+ test.add((E) "A");
+ test.add((E) "B");
+ test.add((E) "C");
assertEquals(5, test.buffer.length);
assertEquals(0, test.head);
assertEquals(3, test.tail);
@@ -218,17 +222,18 @@
assertEquals(1, test.head);
assertEquals(3, test.tail);
- test.add("D");
+ test.add((E) "D");
assertEquals(5, test.buffer.length);
assertEquals(1, test.head);
assertEquals(4, test.tail);
}
+ @SuppressWarnings("unchecked")
public void testInternalStateRemove2() {
- UnboundedFifoBuffer test = new UnboundedFifoBuffer(4);
- test.add("A");
- test.add("B");
- test.add("C");
+ UnboundedFifoBuffer<E> test = new UnboundedFifoBuffer<E>(4);
+ test.add((E) "A");
+ test.add((E) "B");
+ test.add((E) "C");
assertEquals(5, test.buffer.length);
assertEquals(0, test.head);
assertEquals(3, test.tail);
@@ -238,41 +243,43 @@
assertEquals(0, test.head);
assertEquals(2, test.tail);
- test.add("D");
+ test.add((E) "D");
assertEquals(5, test.buffer.length);
assertEquals(0, test.head);
assertEquals(3, test.tail);
}
+ @SuppressWarnings("unchecked")
public void testInternalStateIteratorRemove1() {
- UnboundedFifoBuffer test = new UnboundedFifoBuffer(4);
- test.add("A");
- test.add("B");
- test.add("C");
+ UnboundedFifoBuffer<E> test = new UnboundedFifoBuffer<E>(4);
+ test.add((E) "A");
+ test.add((E) "B");
+ test.add((E) "C");
assertEquals(5, test.buffer.length);
assertEquals(0, test.head);
assertEquals(3, test.tail);
- Iterator it = test.iterator();
+ Iterator<E> it = test.iterator();
it.next();
it.remove();
assertEquals(5, test.buffer.length);
assertEquals(1, test.head);
assertEquals(3, test.tail);
- test.add("D");
+ test.add((E) "D");
assertEquals(5, test.buffer.length);
assertEquals(1, test.head);
assertEquals(4, test.tail);
}
+ @SuppressWarnings("unchecked")
public void testInternalStateIteratorRemove2() {
- UnboundedFifoBuffer test = new UnboundedFifoBuffer(4);
- test.add("A");
- test.add("B");
- test.add("C");
+ UnboundedFifoBuffer<E> test = new UnboundedFifoBuffer<E>(4);
+ test.add((E) "A");
+ test.add((E) "B");
+ test.add((E) "C");
- Iterator it = test.iterator();
+ Iterator<E> it = test.iterator();
it.next();
it.next();
it.remove();
@@ -280,24 +287,25 @@
assertEquals(0, test.head);
assertEquals(2, test.tail);
- test.add("D");
+ test.add((E) "D");
assertEquals(5, test.buffer.length);
assertEquals(0, test.head);
assertEquals(3, test.tail);
}
+ @SuppressWarnings("unchecked")
public void testInternalStateIteratorRemoveWithTailAtEnd1() {
- UnboundedFifoBuffer test = new UnboundedFifoBuffer(3);
- test.add("A");
- test.add("B");
- test.add("C");
+ UnboundedFifoBuffer<E> test = new UnboundedFifoBuffer<E>(3);
+ test.add((E) "A");
+ test.add((E) "B");
+ test.add((E) "C");
test.remove("A");
- test.add("D");
+ test.add((E) "D");
assertEquals(4, test.buffer.length);
assertEquals(1, test.head);
assertEquals(0, test.tail);
- Iterator it = test.iterator();
+ Iterator<E> it = test.iterator();
assertEquals("B", it.next());
it.remove();
assertEquals(4, test.buffer.length);
@@ -305,18 +313,19 @@
assertEquals(0, test.tail);
}
+ @SuppressWarnings("unchecked")
public void testInternalStateIteratorRemoveWithTailAtEnd2() {
- UnboundedFifoBuffer test = new UnboundedFifoBuffer(3);
- test.add("A");
- test.add("B");
- test.add("C");
+ UnboundedFifoBuffer<E> test = new UnboundedFifoBuffer<E>(3);
+ test.add((E) "A");
+ test.add((E) "B");
+ test.add((E) "C");
test.remove("A");
- test.add("D");
+ test.add((E) "D");
assertEquals(4, test.buffer.length);
assertEquals(1, test.head);
assertEquals(0, test.tail);
- Iterator it = test.iterator();
+ Iterator<E> it = test.iterator();
assertEquals("B", it.next());
assertEquals("C", it.next());
it.remove();
@@ -325,18 +334,19 @@
assertEquals(3, test.tail);
}
+ @SuppressWarnings("unchecked")
public void testInternalStateIteratorRemoveWithTailAtEnd3() {
- UnboundedFifoBuffer test = new UnboundedFifoBuffer(3);
- test.add("A");
- test.add("B");
- test.add("C");
+ UnboundedFifoBuffer<E> test = new UnboundedFifoBuffer<E>(3);
+ test.add((E) "A");
+ test.add((E) "B");
+ test.add((E) "C");
test.remove("A");
- test.add("D");
+ test.add((E) "D");
assertEquals(4, test.buffer.length);
assertEquals(1, test.head);
assertEquals(0, test.tail);
- Iterator it = test.iterator();
+ Iterator<E> it = test.iterator();
assertEquals("B", it.next());
assertEquals("C", it.next());
assertEquals("D", it.next());
@@ -346,20 +356,21 @@
assertEquals(3, test.tail);
}
+ @SuppressWarnings("unchecked")
public void testInternalStateIteratorRemoveWithWrap1() {
- UnboundedFifoBuffer test = new UnboundedFifoBuffer(3);
- test.add("A");
- test.add("B");
- test.add("C");
+ UnboundedFifoBuffer<E> test = new UnboundedFifoBuffer<E>(3);
+ test.add((E) "A");
+ test.add((E) "B");
+ test.add((E) "C");
test.remove("A");
test.remove("B");
- test.add("D");
- test.add("E");
+ test.add((E) "D");
+ test.add((E) "E");
assertEquals(4, test.buffer.length);
assertEquals(2, test.head);
assertEquals(1, test.tail);
- Iterator it = test.iterator();
+ Iterator<E> it = test.iterator();
assertEquals("C", it.next());
it.remove();
assertEquals(4, test.buffer.length);
@@ -367,20 +378,21 @@
assertEquals(1, test.tail);
}
+ @SuppressWarnings("unchecked")
public void testInternalStateIteratorRemoveWithWrap2() {
- UnboundedFifoBuffer test = new UnboundedFifoBuffer(3);
- test.add("A");
- test.add("B");
- test.add("C");
+ UnboundedFifoBuffer<E> test = new UnboundedFifoBuffer<E>(3);
+ test.add((E) "A");
+ test.add((E) "B");
+ test.add((E) "C");
test.remove("A");
test.remove("B");
- test.add("D");
- test.add("E");
+ test.add((E) "D");
+ test.add((E) "E");
assertEquals(4, test.buffer.length);
assertEquals(2, test.head);
assertEquals(1, test.tail);
- Iterator it = test.iterator();
+ Iterator<E> it = test.iterator();
assertEquals("C", it.next());
assertEquals("D", it.next());
it.remove();
@@ -389,20 +401,21 @@
assertEquals(0, test.tail);
}
+ @SuppressWarnings("unchecked")
public void testInternalStateIteratorRemoveWithWrap3() {
- UnboundedFifoBuffer test = new UnboundedFifoBuffer(3);
- test.add("A");
- test.add("B");
- test.add("C");
+ UnboundedFifoBuffer<E> test = new UnboundedFifoBuffer<E>(3);
+ test.add((E) "A");
+ test.add((E) "B");
+ test.add((E) "C");
test.remove("A");
test.remove("B");
- test.add("D");
- test.add("E");
+ test.add((E) "D");
+ test.add((E) "E");
assertEquals(4, test.buffer.length);
assertEquals(2, test.head);
assertEquals(1, test.tail);
- Iterator it = test.iterator();
+ Iterator<E> it = test.iterator();
assertEquals("C", it.next());
assertEquals("D", it.next());
assertEquals("E", it.next());
@@ -435,4 +448,19 @@
// writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/UnboundedFifoBuffer.fullCollection.version3.1.obj");
// }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public UnboundedFifoBuffer<E> getCollection() {
+ return (UnboundedFifoBuffer<E>) super.getCollection();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<E> getConfirmed() {
+ return (List<E>) super.getConfirmed();
+ }
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestUnmodifiableBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestUnmodifiableBuffer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestUnmodifiableBuffer.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestUnmodifiableBuffer.java Tue Sep 15 05:29:56 2009
@@ -27,7 +27,7 @@
import org.apache.commons.collections.collection.AbstractTestCollection;
/**
- * Extension of {@link AbstractTestCollection} for exercising the
+ * Extension of {@link AbstractTestCollection} for exercising the
* {@link UnmodifiableBuffer} implementation.
*
* @since Commons Collections 3.1
@@ -36,39 +36,38 @@
* @author Phil Steitz
* @author Stephen Colebourne
*/
-public class TestUnmodifiableBuffer extends AbstractTestCollection {
-
+public class TestUnmodifiableBuffer<E> extends AbstractTestCollection<E> {
+
public TestUnmodifiableBuffer(String testName) {
super(testName);
}
-
+
public static Test suite() {
return new TestSuite(TestUnmodifiableBuffer.class);
}
-
+
public static void main(String args[]) {
String[] testCaseName = { TestUnmodifiableBuffer.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
- //-----------------------------------------------------------------------
- public Collection makeCollection() {
- return UnmodifiableBuffer.decorate(new UnboundedFifoBuffer());
- }
-
- public Collection makeFullCollection() {
- Buffer buffer = new UnboundedFifoBuffer();
+ //-----------------------------------------------------------------------
+ public Collection<E> makeObject() {
+ return UnmodifiableBuffer.decorate(new UnboundedFifoBuffer<E>());
+ }
+
+ public Collection<E> makeFullCollection() {
+ Buffer<E> buffer = new UnboundedFifoBuffer<E>();
buffer.addAll(Arrays.asList(getFullElements()));
return UnmodifiableBuffer.decorate(buffer);
}
-
- public Collection makeConfirmedCollection() {
- ArrayStack list = new ArrayStack();
- return list;
+
+ public Collection<E> makeConfirmedCollection() {
+ return new ArrayStack<E>();
}
- public Collection makeConfirmedFullCollection() {
- ArrayStack list = new ArrayStack();
+ public Collection<E> makeConfirmedFullCollection() {
+ ArrayStack<E> list = new ArrayStack<E>();
list.addAll(Arrays.asList(getFullElements()));
return list;
}
@@ -76,20 +75,19 @@
public boolean isAddSupported() {
return false;
}
-
+
public boolean isRemoveSupported() {
return false;
}
-
+
public boolean isNullSupported() {
return false;
}
-
+
public void testBufferRemove() {
resetEmpty();
- Buffer buffer = (Buffer) collection;
try {
- buffer.remove();
+ getCollection().remove();
fail();
} catch (UnsupportedOperationException ex) {}
}
@@ -105,4 +103,11 @@
// writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/UnmodifiableBuffer.fullCollection.version3.1.obj");
// }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Buffer<E> getCollection() {
+ return (Buffer<E>) super.getCollection();
+ }
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestBooleanComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestBooleanComparator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestBooleanComparator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestBooleanComparator.java Tue Sep 15 05:29:56 2009
@@ -30,7 +30,7 @@
*
* @author Rodney Waldhoff
*/
-public class TestBooleanComparator extends AbstractTestComparator {
+public class TestBooleanComparator extends AbstractTestComparator<Boolean> {
// conventional
// ------------------------------------------------------------------------
@@ -46,21 +46,21 @@
// collections testing framework
// ------------------------------------------------------------------------
- public Comparator makeComparator() {
+ public Comparator<Boolean> makeObject() {
return new BooleanComparator();
}
- public List getComparableObjectsOrdered() {
- List list = new ArrayList();
+ public List<Boolean> getComparableObjectsOrdered() {
+ List<Boolean> list = new ArrayList<Boolean>();
list.add(new Boolean(false));
list.add(Boolean.FALSE);
list.add(new Boolean(false));
list.add(Boolean.TRUE);
list.add(new Boolean(true));
- list.add(Boolean.TRUE);
+ list.add(true);
return list;
}
-
+
public String getCompatibilityVersion() {
return "3";
}
@@ -71,16 +71,16 @@
public void testConstructors() {
allTests(false,new BooleanComparator());
allTests(false,new BooleanComparator(false));
- allTests(true,new BooleanComparator(true));
+ allTests(true,new BooleanComparator(true));
}
-
+
public void testStaticFactoryMethods() {
allTests(false,BooleanComparator.getFalseFirstComparator());
allTests(false,BooleanComparator.getBooleanComparator(false));
allTests(true,BooleanComparator.getTrueFirstComparator());
allTests(true,BooleanComparator.getBooleanComparator(true));
}
-
+
public void testEqualsCompatibleInstance() {
assertEquals(new BooleanComparator(),new BooleanComparator(false));
assertEquals(new BooleanComparator(false),new BooleanComparator(false));
@@ -94,7 +94,7 @@
assertTrue(!(new BooleanComparator().equals(new BooleanComparator(true))));
assertTrue(!(new BooleanComparator(true).equals(new BooleanComparator(false))));
}
-
+
// utilities
// ------------------------------------------------------------------------
@@ -109,36 +109,24 @@
protected void trueFirstTests(BooleanComparator comp) {
assertNotNull(comp);
- assertEquals(0,comp.compare(Boolean.TRUE,Boolean.TRUE));
- assertEquals(0,comp.compare(Boolean.FALSE,Boolean.FALSE));
- assertTrue(comp.compare(Boolean.FALSE,Boolean.TRUE) > 0);
- assertTrue(comp.compare(Boolean.TRUE,Boolean.FALSE) < 0);
-
- assertEquals(0,comp.compare((Object)(Boolean.TRUE),(Object)(Boolean.TRUE)));
- assertEquals(0,comp.compare((Object)(Boolean.FALSE),(Object)(Boolean.FALSE)));
- assertTrue(comp.compare((Object)(Boolean.FALSE),(Object)(Boolean.TRUE)) > 0);
- assertTrue(comp.compare((Object)(Boolean.TRUE),(Object)(Boolean.FALSE)) < 0);
+ assertEquals(0,comp.compare(true, true));
+ assertEquals(0,comp.compare(false, false));
+ assertTrue(comp.compare(false, true) > 0);
+ assertTrue(comp.compare(true, false) < 0);
}
protected void falseFirstTests(BooleanComparator comp) {
assertNotNull(comp);
- assertEquals(0,comp.compare(Boolean.TRUE,Boolean.TRUE));
- assertEquals(0,comp.compare(Boolean.FALSE,Boolean.FALSE));
- assertTrue(comp.compare(Boolean.FALSE,Boolean.TRUE) < 0);
- assertTrue(comp.compare(Boolean.TRUE,Boolean.FALSE) > 0);
-
- assertEquals(0,comp.compare((Object)(Boolean.TRUE),(Object)(Boolean.TRUE)));
- assertEquals(0,comp.compare((Object)(Boolean.FALSE),(Object)(Boolean.FALSE)));
- assertTrue(comp.compare((Object)(Boolean.FALSE),(Object)(Boolean.TRUE)) < 0);
- assertTrue(comp.compare((Object)(Boolean.TRUE),(Object)(Boolean.FALSE)) > 0);
+ assertEquals(0,comp.compare(true, true));
+ assertEquals(0,comp.compare(false, false));
+ assertTrue(comp.compare(false, true) < 0);
+ assertTrue(comp.compare(true, false) > 0);
}
protected void orderIndependentTests(BooleanComparator comp) {
nullArgumentTests(comp);
- nonBooleanArgumentTests(comp);
- nullAndNonBooleanArgumentsTests(comp);
}
-
+
protected void nullArgumentTests(BooleanComparator comp) {
assertNotNull(comp);
try {
@@ -172,59 +160,5 @@
// expected
}
}
-
- protected void nonBooleanArgumentTests(BooleanComparator comp) {
- assertNotNull(comp);
- try {
- comp.compare("string","string");
- fail("Expected ClassCastException");
- } catch(ClassCastException e) {
- // expected
- }
- try {
- comp.compare(Boolean.TRUE,"string");
- fail("Expected ClassCastException");
- } catch(ClassCastException e) {
- // expected
- }
- try {
- comp.compare("string",Boolean.TRUE);
- fail("Expected ClassCastException");
- } catch(ClassCastException e) {
- // expected
- }
- try {
- comp.compare("string",new Integer(3));
- fail("Expected ClassCastException");
- } catch(ClassCastException e) {
- // expected
- }
- try {
- comp.compare(new Integer(3),"string");
- fail("Expected ClassCastException");
- } catch(ClassCastException e) {
- // expected
- }
- }
-
- protected void nullAndNonBooleanArgumentsTests(BooleanComparator comp) {
- assertNotNull(comp);
- try {
- comp.compare(null,"string");
- fail("Expected ClassCast or NullPointer Exception");
- } catch(ClassCastException e) {
- // expected
- } catch(NullPointerException e) {
- // expected
- }
- try {
- comp.compare("string",null);
- fail("Expected ClassCast or NullPointer Exception");
- } catch(ClassCastException e) {
- // expected
- } catch(NullPointerException e) {
- // expected
- }
- }
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestComparableComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestComparableComparator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestComparableComparator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestComparableComparator.java Tue Sep 15 05:29:56 2009
@@ -30,7 +30,7 @@
*
* @author Unknown
*/
-public class TestComparableComparator extends AbstractTestComparator {
+public class TestComparableComparator extends AbstractTestComparator<Integer> {
public TestComparableComparator(String testName) {
super(testName);
@@ -40,17 +40,17 @@
return new TestSuite(TestComparableComparator.class);
}
- public Comparator makeComparator() {
- return new ComparableComparator();
+ public Comparator<Integer> makeObject() {
+ return new ComparableComparator<Integer>();
}
- public List getComparableObjectsOrdered() {
- List list = new LinkedList();
- list.add(new Integer(1));
- list.add(new Integer(2));
- list.add(new Integer(3));
- list.add(new Integer(4));
- list.add(new Integer(5));
+ public List<Integer> getComparableObjectsOrdered() {
+ List<Integer> list = new LinkedList<Integer>();
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ list.add(4);
+ list.add(5);
return list;
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestComparatorChain.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestComparatorChain.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestComparatorChain.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestComparatorChain.java Tue Sep 15 05:29:56 2009
@@ -31,7 +31,7 @@
*
* @author Unknown
*/
-public class TestComparatorChain extends AbstractTestComparator {
+public class TestComparatorChain extends AbstractTestComparator<TestComparatorChain.PseudoRow> {
public TestComparatorChain(String testName) {
super(testName);
@@ -41,97 +41,94 @@
return new TestSuite(TestComparatorChain.class);
}
- public Comparator makeComparator() {
- ComparatorChain chain = new ComparatorChain(new ColumnComparator(0));
- chain.addComparator(new ColumnComparator(1),true); // reverse the second column
- chain.addComparator(new ColumnComparator(2),false);
+ public Comparator<PseudoRow> makeObject() {
+ ComparatorChain<PseudoRow> chain = new ComparatorChain<PseudoRow>(new ColumnComparator(0));
+ chain.addComparator(new ColumnComparator(1), true); // reverse the second column
+ chain.addComparator(new ColumnComparator(2), false);
return chain;
}
public void testNoopComparatorChain() {
- ComparatorChain chain = new ComparatorChain();
+ ComparatorChain<Integer> chain = new ComparatorChain<Integer>();
Integer i1 = new Integer(4);
Integer i2 = new Integer(6);
- chain.addComparator(new ComparableComparator());
+ chain.addComparator(new ComparableComparator<Integer>());
int correctValue = i1.compareTo(i2);
- assertTrue("Comparison returns the right order",chain.compare(i1,i2) == correctValue);
+ assertTrue("Comparison returns the right order", chain.compare(i1, i2) == correctValue);
}
public void testBadNoopComparatorChain() {
- ComparatorChain chain = new ComparatorChain();
+ ComparatorChain<Integer> chain = new ComparatorChain<Integer>();
Integer i1 = new Integer(4);
Integer i2 = new Integer(6);
try {
chain.compare(i1,i2);
fail("An exception should be thrown when a chain contains zero comparators.");
} catch (UnsupportedOperationException e) {
-
}
}
public void testListComparatorChain() {
- List list = new LinkedList();
- list.add(new ComparableComparator());
- ComparatorChain chain = new ComparatorChain(list);
+ List<Comparator<Integer>> list = new LinkedList<Comparator<Integer>>();
+ list.add(new ComparableComparator<Integer>());
+ ComparatorChain<Integer> chain = new ComparatorChain<Integer>(list);
Integer i1 = new Integer(4);
Integer i2 = new Integer(6);
int correctValue = i1.compareTo(i2);
- assertTrue("Comparison returns the right order",chain.compare(i1,i2) == correctValue);
+ assertTrue("Comparison returns the right order", chain.compare(i1, i2) == correctValue);
}
public void testBadListComparatorChain() {
- List list = new LinkedList();
- ComparatorChain chain = new ComparatorChain(list);
+ List<Comparator<Integer>> list = new LinkedList<Comparator<Integer>>();
+ ComparatorChain<Integer> chain = new ComparatorChain<Integer>(list);
Integer i1 = new Integer(4);
Integer i2 = new Integer(6);
try {
- chain.compare(i1,i2);
+ chain.compare(i1, i2);
fail("An exception should be thrown when a chain contains zero comparators.");
} catch (UnsupportedOperationException e) {
-
}
}
-
public void testComparatorChainOnMinvaluedCompatator() {
// -1 * Integer.MIN_VALUE is less than 0,
// test that ComparatorChain handles this edge case correctly
- ComparatorChain chain = new ComparatorChain();
- chain.addComparator(
- new Comparator() {
- public int compare(Object a, Object b) {
- int result = ((Comparable)a).compareTo(b);
- if(result < 0) {
- return Integer.MIN_VALUE;
- } else if(result > 0) {
- return Integer.MAX_VALUE;
- } else {
- return 0;
- }
+ ComparatorChain<Integer> chain = new ComparatorChain<Integer>();
+ chain.addComparator(new Comparator<Integer>() {
+ public int compare(Integer a, Integer b) {
+ int result = a.compareTo(b);
+ if (result < 0) {
+ return Integer.MIN_VALUE;
}
- }, true);
+ if (result > 0) {
+ return Integer.MAX_VALUE;
+ }
+ return 0;
+ }
+ }, true);
- assertTrue(chain.compare(new Integer(4), new Integer(5)) > 0);
- assertTrue(chain.compare(new Integer(5), new Integer(4)) < 0);
- assertTrue(chain.compare(new Integer(4), new Integer(4)) == 0);
+ assertTrue(chain.compare(new Integer(4), new Integer(5)) > 0);
+ assertTrue(chain.compare(new Integer(5), new Integer(4)) < 0);
+ assertTrue(chain.compare(new Integer(4), new Integer(4)) == 0);
}
- public List getComparableObjectsOrdered() {
- List list = new LinkedList();
+ public List<PseudoRow> getComparableObjectsOrdered() {
+ List<PseudoRow> list = new LinkedList<PseudoRow>();
// this is the correct order assuming a
// "0th forward, 1st reverse, 2nd forward" sort
- list.add(new PseudoRow(1,2,3));
- list.add(new PseudoRow(2,3,5));
- list.add(new PseudoRow(2,2,4));
- list.add(new PseudoRow(2,2,8));
- list.add(new PseudoRow(3,1,0));
- list.add(new PseudoRow(4,4,4));
- list.add(new PseudoRow(4,4,7));
+ list.add(new PseudoRow(1, 2, 3));
+ list.add(new PseudoRow(2, 3, 5));
+ list.add(new PseudoRow(2, 2, 4));
+ list.add(new PseudoRow(2, 2, 8));
+ list.add(new PseudoRow(3, 1, 0));
+ list.add(new PseudoRow(4, 4, 4));
+ list.add(new PseudoRow(4, 4, 7));
return list;
}
+ @SuppressWarnings("serial")
public static class PseudoRow implements Serializable {
public int cols[] = new int[3];
@@ -170,8 +167,8 @@
if (getColumn(1) != row.getColumn(1)) {
return false;
- }
-
+ }
+
if (getColumn(2) != row.getColumn(2)) {
return false;
}
@@ -181,7 +178,8 @@
}
- public static class ColumnComparator implements Comparator,Serializable {
+ public static class ColumnComparator implements Comparator<PseudoRow>, Serializable {
+ private static final long serialVersionUID = -2284880866328872105L;
protected int colIndex = 0;
@@ -189,32 +187,26 @@
this.colIndex = colIndex;
}
- public int compare(Object o1, Object o2) {
+ public int compare(PseudoRow o1, PseudoRow o2) {
- int col1 = ( (PseudoRow) o1).getColumn(colIndex);
- int col2 = ( (PseudoRow) o2).getColumn(colIndex);
+ int col1 = o1.getColumn(colIndex);
+ int col2 = o2.getColumn(colIndex);
if (col1 > col2) {
return 1;
- } else if (col1 < col2) {
+ }
+ if (col1 < col2) {
return -1;
}
-
return 0;
}
-
+
public int hashCode() {
return colIndex;
}
-
+
public boolean equals(Object that) {
- if(that instanceof ColumnComparator) {
- return colIndex == ((ColumnComparator)that).colIndex;
- } else {
- return false;
- }
+ return that instanceof ColumnComparator && colIndex == ((ColumnComparator) that).colIndex;
}
-
- private static final long serialVersionUID = -2284880866328872105L;
}
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestFixedOrderComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestFixedOrderComparator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestFixedOrderComparator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestFixedOrderComparator.java Tue Sep 15 05:29:56 2009
@@ -31,12 +31,11 @@
*
* @version $Revision$ $Date$
*
- * @author David Leppik
+ * @author David Leppik
* @author Stephen Colebourne
*/
public class TestFixedOrderComparator extends TestCase {
-
/**
* Top cities of the world, by population including metro areas.
*/
@@ -65,7 +64,7 @@
return new TestSuite(TestFixedOrderComparator.class);
}
- public static void main(String args[]) {
+ public static void main(String args[]) {
junit.textui.TestRunner.run(suite());
}
@@ -79,11 +78,11 @@
// The tests
//
- /**
- * Tests that the constructor plus add method compares items properly.
+ /**
+ * Tests that the constructor plus add method compares items properly.
*/
public void testConstructorPlusAdd() {
- FixedOrderComparator comparator = new FixedOrderComparator();
+ FixedOrderComparator<String> comparator = new FixedOrderComparator<String>();
for (int i = 0; i < topCities.length; i++) {
comparator.add(topCities[i]);
}
@@ -91,13 +90,13 @@
assertComparatorYieldsOrder(keys, comparator);
}
- /**
- * Tests that the array constructor compares items properly.
+ /**
+ * Tests that the array constructor compares items properly.
*/
public void testArrayConstructor() {
String[] keys = (String[]) topCities.clone();
String[] topCitiesForTest = (String[]) topCities.clone();
- FixedOrderComparator comparator = new FixedOrderComparator(topCitiesForTest);
+ FixedOrderComparator<String> comparator = new FixedOrderComparator<String>(topCitiesForTest);
assertComparatorYieldsOrder(keys, comparator);
// test that changing input after constructor has no effect
topCitiesForTest[0] = "Brighton";
@@ -105,12 +104,12 @@
}
/**
- * Tests the list constructor.
+ * Tests the list constructor.
*/
public void testListConstructor() {
String[] keys = (String[]) topCities.clone();
- List topCitiesForTest = new LinkedList(Arrays.asList(topCities));
- FixedOrderComparator comparator = new FixedOrderComparator(topCitiesForTest);
+ List<String> topCitiesForTest = new LinkedList<String>(Arrays.asList(topCities));
+ FixedOrderComparator<String> comparator = new FixedOrderComparator<String>(topCitiesForTest);
assertComparatorYieldsOrder(keys, comparator);
// test that changing input after constructor has no effect
topCitiesForTest.set(0, "Brighton");
@@ -121,18 +120,18 @@
* Tests addAsEqual method.
*/
public void testAddAsEqual() {
- FixedOrderComparator comparator = new FixedOrderComparator(topCities);
+ FixedOrderComparator<String> comparator = new FixedOrderComparator<String>(topCities);
comparator.addAsEqual("New York", "Minneapolis");
assertEquals(0, comparator.compare("New York", "Minneapolis"));
assertEquals(-1, comparator.compare("Tokyo", "Minneapolis"));
assertEquals(1, comparator.compare("Shanghai", "Minneapolis"));
}
- /**
+ /**
* Tests whether or not updates are disabled after a comparison is made.
*/
public void testLock() {
- FixedOrderComparator comparator = new FixedOrderComparator(topCities);
+ FixedOrderComparator<String> comparator = new FixedOrderComparator<String>(topCities);
assertEquals(false, comparator.isLocked());
comparator.compare("New York", "Tokyo");
assertEquals(true, comparator.isLocked());
@@ -152,7 +151,7 @@
}
public void testUnknownObjectBehavior() {
- FixedOrderComparator comparator = new FixedOrderComparator(topCities);
+ FixedOrderComparator<String> comparator = new FixedOrderComparator<String>(topCities);
try {
comparator.compare("New York", "Minneapolis");
fail("Should have thrown a IllegalArgumentException");
@@ -165,42 +164,43 @@
} catch (IllegalArgumentException e) {
// success-- ignore
}
- assertEquals(FixedOrderComparator.UNKNOWN_THROW_EXCEPTION, comparator.getUnknownObjectBehavior());
+ assertEquals(FixedOrderComparator.UnknownObjectBehavior.EXCEPTION, comparator.getUnknownObjectBehavior());
- comparator = new FixedOrderComparator(topCities);
- comparator.setUnknownObjectBehavior(FixedOrderComparator.UNKNOWN_BEFORE);
- assertEquals(FixedOrderComparator.UNKNOWN_BEFORE, comparator.getUnknownObjectBehavior());
- LinkedList keys = new LinkedList(Arrays.asList(topCities));
+ comparator = new FixedOrderComparator<String>(topCities);
+ comparator.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.BEFORE);
+ assertEquals(FixedOrderComparator.UnknownObjectBehavior.BEFORE, comparator.getUnknownObjectBehavior());
+ LinkedList<String> keys = new LinkedList<String>(Arrays.asList(topCities));
keys.addFirst("Minneapolis");
assertComparatorYieldsOrder(keys.toArray(new String[0]), comparator);
-
+
assertEquals(-1, comparator.compare("Minneapolis", "New York"));
assertEquals( 1, comparator.compare("New York", "Minneapolis"));
assertEquals( 0, comparator.compare("Minneapolis", "St Paul"));
- comparator = new FixedOrderComparator(topCities);
- comparator.setUnknownObjectBehavior(FixedOrderComparator.UNKNOWN_AFTER);
- keys = new LinkedList(Arrays.asList(topCities));
+ comparator = new FixedOrderComparator<String>(topCities);
+ comparator.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.AFTER);
+ keys = new LinkedList<String>(Arrays.asList(topCities));
keys.add("Minneapolis");
assertComparatorYieldsOrder(keys.toArray(new String[0]), comparator);
-
+
assertEquals( 1, comparator.compare("Minneapolis", "New York"));
assertEquals(-1, comparator.compare("New York", "Minneapolis"));
assertEquals( 0, comparator.compare("Minneapolis", "St Paul"));
-
+
}
-
+
//
// Helper methods
//
-
+
/** Shuffles the keys and asserts that the comparator sorts them back to
* their original order.
*/
- private void assertComparatorYieldsOrder(Object[] orderedObjects,
- Comparator comparator) {
- Object[] keys = (Object[]) orderedObjects.clone();
-
+ @SuppressWarnings("unused")
+ private void assertComparatorYieldsOrder(String[] orderedObjects,
+ Comparator<String> comparator) {
+ String[] keys = orderedObjects.clone();
+
// shuffle until the order changes. It's extremely rare that
// this requires more than one shuffle.
@@ -209,13 +209,13 @@
shuffle: {
Random rand = new Random();
for (int i = keys.length-1; i > 0; i--) {
- Object swap = keys[i];
+ String swap = keys[i];
int j = rand.nextInt(i+1);
keys[i] = keys[j];
- keys[j] = swap;
+ keys[j] = swap;
}
}
-
+
testShuffle: {
for (int i = 0; i < keys.length && !isInNewOrder; i++) {
if( !orderedObjects[i].equals(keys[i])) {
@@ -224,14 +224,14 @@
}
}
}
-
+
// The real test: sort and make sure they come out right.
-
+
Arrays.sort(keys, comparator);
for (int i = 0; i < orderedObjects.length; i++) {
assertEquals(orderedObjects[i], keys[i]);
}
}
-
+
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestReverseComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestReverseComparator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestReverseComparator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestReverseComparator.java Tue Sep 15 05:29:56 2009
@@ -35,7 +35,7 @@
*
* @author Unknown
*/
-public class TestReverseComparator extends AbstractTestComparator {
+public class TestReverseComparator extends AbstractTestComparator<Integer> {
public TestReverseComparator(String testName) {
super(testName);
@@ -46,21 +46,21 @@
}
/**
- * For the purposes of this test, return a
+ * For the purposes of this test, return a
* ReverseComparator that wraps the java.util.Collections.reverseOrder()
* Comparator. The resulting comparator should
* sort according to natural Order. (Note: we wrap
* a Comparator taken from the JDK so that we can
* save a "canonical" form in SVN.
- *
+ *
* @return Comparator that returns "natural" order
*/
- public Comparator makeComparator() {
- return new ReverseComparator(Collections.reverseOrder());
+ public Comparator<Integer> makeObject() {
+ return new ReverseComparator<Integer>(Collections.<Integer>reverseOrder());
}
- public List getComparableObjectsOrdered() {
- List list = new LinkedList();
+ public List<Integer> getComparableObjectsOrdered() {
+ List<Integer> list = new LinkedList<Integer>();
list.add(new Integer(1));
list.add(new Integer(2));
list.add(new Integer(3));
@@ -69,11 +69,12 @@
return list;
}
- /**
+ /**
* Override this inherited test since Collections.reverseOrder
* doesn't adhere to the "soft" Comparator contract, and we've
* already "cannonized" the comparator returned by makeComparator.
*/
+ @SuppressWarnings("unchecked")
public void testSerializeDeserializeThenCompare() throws Exception {
Comparator comp = new ReverseComparator(new ComparableComparator());
@@ -81,7 +82,7 @@
ObjectOutputStream out = new ObjectOutputStream(buffer);
out.writeObject(comp);
out.close();
-
+
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
Object dest = in.readObject();
in.close();
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/AbstractTestIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/AbstractTestIterator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/AbstractTestIterator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/AbstractTestIterator.java Tue Sep 15 05:29:56 2009
@@ -35,7 +35,7 @@
* @author Morgan Delagrange
* @author Stephen Colebourne
*/
-public abstract class AbstractTestIterator extends AbstractTestObject {
+public abstract class AbstractTestIterator<E> extends AbstractTestObject {
/**
* JUnit constructor.
@@ -52,23 +52,14 @@
*
* @return an empty iterator
*/
- public abstract Iterator makeEmptyIterator();
-
- /**
- * Implement this method to return an iterator over a collection with elements.
- *
- * @return a full iterator
- */
- public abstract Iterator makeFullIterator();
+ public abstract Iterator<E> makeEmptyIterator();
/**
* Implements the abstract superclass method to return the full iterator.
*
* @return a full iterator
*/
- public Object makeObject() {
- return makeFullIterator();
- }
+ public abstract Iterator<E> makeObject();
/**
* Whether or not we are testing an iterator that can be empty.
@@ -116,7 +107,7 @@
return;
}
- Iterator it = makeEmptyIterator();
+ Iterator<E> it = makeEmptyIterator();
// hasNext() should return false
assertEquals("hasNext() should return false for empty iterators", false, it.hasNext());
@@ -140,7 +131,7 @@
return;
}
- Iterator it = makeFullIterator();
+ Iterator<E> it = makeObject();
// hasNext() must be true (ensure makeFullIterator is correct!)
assertEquals("hasNext() should return true for at least one element", true, it.hasNext());
@@ -172,7 +163,7 @@
* Test remove behaviour.
*/
public void testRemove() {
- Iterator it = makeFullIterator();
+ Iterator<E> it = makeObject();
if (supportsRemove() == false) {
// check for UnsupportedOperationException if not supported
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/AbstractTestListIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/AbstractTestListIterator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/AbstractTestListIterator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/AbstractTestListIterator.java Tue Sep 15 05:29:56 2009
@@ -17,7 +17,6 @@
package org.apache.commons.collections.iterators;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.ListIterator;
import java.util.NoSuchElementException;
@@ -35,11 +34,11 @@
* @author Rodney Waldhoff
* @author Stephen Colebourne
*/
-public abstract class AbstractTestListIterator extends AbstractTestIterator {
+public abstract class AbstractTestListIterator<E> extends AbstractTestIterator<E> {
/**
* JUnit constructor.
- *
+ *
* @param testName the test class name
*/
public AbstractTestListIterator(String testName) {
@@ -48,41 +47,23 @@
//-----------------------------------------------------------------------
/**
- * Implement this method to return a list iterator over an empty collection.
- *
- * @return an empty iterator
- */
- public abstract ListIterator makeEmptyListIterator();
-
- /**
- * Implement this method to return a list iterator over a collection with elements.
- *
- * @return a full iterator
- */
- public abstract ListIterator makeFullListIterator();
-
- /**
* Implements the abstract superclass method to return the list iterator.
- *
+ *
* @return an empty iterator
*/
- public Iterator makeEmptyIterator() {
- return makeEmptyListIterator();
- }
+ public abstract ListIterator<E> makeEmptyIterator();
/**
* Implements the abstract superclass method to return the list iterator.
- *
+ *
* @return a full iterator
*/
- public Iterator makeFullIterator() {
- return makeFullListIterator();
- }
+ public abstract ListIterator<E> makeObject();
/**
* Whether or not we are testing an iterator that supports add().
* Default is true.
- *
+ *
* @return true if Iterator supports add
*/
public boolean supportsAdd() {
@@ -92,7 +73,7 @@
/**
* Whether or not we are testing an iterator that supports set().
* Default is true.
- *
+ *
* @return true if Iterator supports set
*/
public boolean supportsSet() {
@@ -103,7 +84,7 @@
* The value to be used in the add and set tests.
* Default is null.
*/
- public Object addSetValue() {
+ public E addSetValue() {
return null;
}
@@ -116,20 +97,20 @@
return;
}
- ListIterator it = makeEmptyListIterator();
-
+ ListIterator<E> it = makeEmptyIterator();
+
assertEquals(false, it.hasNext());
assertEquals(0, it.nextIndex());
assertEquals(false, it.hasPrevious());
assertEquals(-1, it.previousIndex());
-
+
// next() should throw a NoSuchElementException
try {
it.next();
fail("NoSuchElementException must be thrown from empty ListIterator");
} catch (NoSuchElementException e) {
}
-
+
// previous() should throw a NoSuchElementException
try {
it.previous();
@@ -137,17 +118,17 @@
} catch (NoSuchElementException e) {
}
}
-
+
/**
* Test navigation through the iterator.
*/
public void testWalkForwardAndBack() {
- ArrayList list = new ArrayList();
- ListIterator it = makeFullListIterator();
+ ArrayList<E> list = new ArrayList<E>();
+ ListIterator<E> it = makeObject();
while (it.hasNext()) {
list.add(it.next());
}
-
+
// check state at end
assertEquals(false, it.hasNext());
assertEquals(true, it.hasPrevious());
@@ -156,16 +137,16 @@
fail("NoSuchElementException must be thrown from next at end of ListIterator");
} catch (NoSuchElementException e) {
}
-
+
// loop back through comparing
for (int i = list.size() - 1; i >= 0; i--) {
assertEquals(i + 1, it.nextIndex());
assertEquals(i, it.previousIndex());
-
+
Object obj = list.get(i);
assertEquals(obj, it.previous());
}
-
+
// check state at start
assertEquals(true, it.hasNext());
assertEquals(false, it.hasPrevious());
@@ -175,14 +156,14 @@
} catch (NoSuchElementException e) {
}
}
-
+
/**
* Test add behaviour.
*/
public void testAdd() {
- ListIterator it = makeFullListIterator();
-
- Object addValue = addSetValue();
+ ListIterator<E> it = makeObject();
+
+ E addValue = addSetValue();
if (supportsAdd() == false) {
// check for UnsupportedOperationException if not supported
try {
@@ -190,34 +171,34 @@
} catch (UnsupportedOperationException ex) {}
return;
}
-
+
// add at start should be OK, added should be previous
- it = makeFullListIterator();
+ it = makeObject();
it.add(addValue);
assertEquals(addValue, it.previous());
// add at start should be OK, added should not be next
- it = makeFullListIterator();
+ it = makeObject();
it.add(addValue);
assertTrue(addValue != it.next());
// add in middle and at end should be OK
- it = makeFullListIterator();
+ it = makeObject();
while (it.hasNext()) {
it.next();
it.add(addValue);
// check add OK
assertEquals(addValue, it.previous());
it.next();
- }
+ }
}
-
+
/**
* Test set behaviour.
*/
public void testSet() {
- ListIterator it = makeFullListIterator();
-
+ ListIterator<E> it = makeObject();
+
if (supportsSet() == false) {
// check for UnsupportedOperationException if not supported
try {
@@ -225,24 +206,24 @@
} catch (UnsupportedOperationException ex) {}
return;
}
-
+
// should throw IllegalStateException before next() called
try {
it.set(addSetValue());
fail();
} catch (IllegalStateException ex) {}
-
+
// set after next should be fine
it.next();
it.set(addSetValue());
-
+
// repeated set calls should be fine
it.set(addSetValue());
}
-
+
public void testRemoveThenSet() {
- ListIterator it = makeFullListIterator();
+ ListIterator<E> it = makeObject();
if (supportsRemove() && supportsSet()) {
it.next();
it.remove();
@@ -255,7 +236,7 @@
}
public void testAddThenSet() {
- ListIterator it = makeFullListIterator();
+ ListIterator<E> it = makeObject();
// add then set
if (supportsAdd() && supportsSet()) {
it.next();
@@ -267,13 +248,13 @@
}
}
}
-
+
/**
* Test remove after add behaviour.
*/
public void testAddThenRemove() {
- ListIterator it = makeFullListIterator();
-
+ ListIterator<E> it = makeObject();
+
// add then remove
if (supportsAdd() && supportsRemove()) {
it.next();
@@ -285,5 +266,5 @@
}
}
}
-
+
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/AbstractTestMapIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/AbstractTestMapIterator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/AbstractTestMapIterator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/AbstractTestMapIterator.java Tue Sep 15 05:29:56 2009
@@ -17,7 +17,6 @@
package org.apache.commons.collections.iterators;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
@@ -37,11 +36,11 @@
*
* @author Stephen Colebourne
*/
-public abstract class AbstractTestMapIterator extends AbstractTestIterator {
+public abstract class AbstractTestMapIterator<K, V> extends AbstractTestIterator<K> {
/**
* JUnit constructor.
- *
+ *
* @param testName the test class name
*/
public AbstractTestMapIterator(String testName) {
@@ -51,56 +50,38 @@
//-----------------------------------------------------------------------
/**
* Implement this method to return a map iterator over an empty map.
- *
+ *
* @return an empty iterator
*/
- public abstract MapIterator makeEmptyMapIterator();
+ public abstract MapIterator<K, V> makeEmptyIterator();
/**
* Implement this method to return a map iterator over a map with elements.
- *
+ *
* @return a full iterator
*/
- public abstract MapIterator makeFullMapIterator();
+ public abstract MapIterator<K, V> makeObject();
/**
* Implement this method to return the map which contains the same data as the
* iterator.
- *
+ *
* @return a full map which can be updated
*/
- public abstract Map getMap();
-
+ public abstract Map<K, V> getMap();
+
/**
* Implement this method to return the confirmed map which contains the same
* data as the iterator.
- *
+ *
* @return a full map which can be updated
*/
- public abstract Map getConfirmedMap();
-
- /**
- * Implements the abstract superclass method to return the list iterator.
- *
- * @return an empty iterator
- */
- public final Iterator makeEmptyIterator() {
- return makeEmptyMapIterator();
- }
-
- /**
- * Implements the abstract superclass method to return the list iterator.
- *
- * @return a full iterator
- */
- public final Iterator makeFullIterator() {
- return makeFullMapIterator();
- }
+ public abstract Map<K, V> getConfirmedMap();
/**
* Whether or not we are testing an iterator that supports setValue().
* Default is true.
- *
+ *
* @return true if Iterator supports set
*/
public boolean supportsSetValue() {
@@ -110,19 +91,20 @@
/**
* Whether the get operation on the map structurally modifies the map,
* such as with LRUMap. Default is false.
- *
+ *
* @return true if the get method structurally modifies the map
*/
public boolean isGetStructuralModify() {
return false;
}
-
+
/**
* The values to be used in the add and set tests.
* Default is two strings.
*/
- public Object[] addSetValues() {
- return new Object[] {"A", "B"};
+ @SuppressWarnings("unchecked")
+ public V[] addSetValues() {
+ return (V[]) new Object[] { "A", "B" };
}
//-----------------------------------------------------------------------
@@ -134,28 +116,27 @@
return;
}
- MapIterator it = makeEmptyMapIterator();
- Map map = getMap();
+ MapIterator<K, V> it = makeEmptyIterator();
assertEquals(false, it.hasNext());
-
+
// next() should throw a NoSuchElementException
try {
it.next();
fail();
} catch (NoSuchElementException ex) {}
-
+
// getKey() should throw an IllegalStateException
try {
it.getKey();
fail();
} catch (IllegalStateException ex) {}
-
+
// getValue() should throw an IllegalStateException
try {
it.getValue();
fail();
} catch (IllegalStateException ex) {}
-
+
if (supportsSetValue() == false) {
// setValue() should throw an UnsupportedOperationException/IllegalStateException
try {
@@ -181,21 +162,21 @@
return;
}
- MapIterator it = makeFullMapIterator();
- Map map = getMap();
+ MapIterator<K, V> it = makeObject();
+ Map<K, V> map = getMap();
assertEquals(true, it.hasNext());
-
+
assertEquals(true, it.hasNext());
- Set set = new HashSet();
+ Set<K> set = new HashSet<K>();
while (it.hasNext()) {
// getKey
- Object key = it.next();
+ K key = it.next();
assertSame("it.next() should equals getKey()", key, it.getKey());
assertTrue("Key must be in map", map.containsKey(key));
assertTrue("Key must be unique", set.add(key));
-
+
// getValue
- Object value = it.getValue();
+ V value = it.getValue();
if (isGetStructuralModify() == false) {
assertSame("Value must be mapped to key", map.get(key), value);
}
@@ -204,22 +185,22 @@
verify();
}
}
-
+
//-----------------------------------------------------------------------
public void testMapIteratorSet() {
if (supportsFullIterator() == false) {
return;
}
- Object newValue = addSetValues()[0];
- Object newValue2 = (addSetValues().length == 1 ? addSetValues()[0] : addSetValues()[1]);
- MapIterator it = makeFullMapIterator();
- Map map = getMap();
- Map confirmed = getConfirmedMap();
+ V newValue = addSetValues()[0];
+ V newValue2 = (addSetValues().length == 1 ? addSetValues()[0] : addSetValues()[1]);
+ MapIterator<K, V> it = makeObject();
+ Map<K, V> map = getMap();
+ Map<K, V> confirmed = getConfirmedMap();
assertEquals(true, it.hasNext());
- Object key = it.next();
- Object value = it.getValue();
-
+ K key = it.next();
+ V value = it.getValue();
+
if (supportsSetValue() == false) {
try {
it.setValue(newValue);
@@ -227,24 +208,24 @@
} catch (UnsupportedOperationException ex) {}
return;
}
- Object old = it.setValue(newValue);
+ V old = it.setValue(newValue);
confirmed.put(key, newValue);
assertSame("Key must not change after setValue", key, it.getKey());
assertSame("Value must be changed after setValue", newValue, it.getValue());
assertSame("setValue must return old value", value, old);
assertEquals("Map must contain key", true, map.containsKey(key));
// test against confirmed, as map may contain value twice
- assertEquals("Map must not contain old value",
+ assertEquals("Map must not contain old value",
confirmed.containsValue(old), map.containsValue(old));
assertEquals("Map must contain new value", true, map.containsValue(newValue));
verify();
-
+
it.setValue(newValue); // same value - should be OK
confirmed.put(key, newValue);
assertSame("Key must not change after setValue", key, it.getKey());
assertSame("Value must be changed after setValue", newValue, it.getValue());
verify();
-
+
it.setValue(newValue2); // new value
confirmed.put(key, newValue2);
assertSame("Key must not change after setValue", key, it.getKey());
@@ -254,12 +235,12 @@
//-----------------------------------------------------------------------
public void testRemove() { // override
- MapIterator it = makeFullMapIterator();
- Map map = getMap();
- Map confirmed = getConfirmedMap();
+ MapIterator<K, V> it = makeObject();
+ Map<K, V> map = getMap();
+ Map<K, V> confirmed = getConfirmedMap();
assertEquals(true, it.hasNext());
- Object key = it.next();
-
+ K key = it.next();
+
if (supportsRemove() == false) {
try {
it.remove();
@@ -268,12 +249,12 @@
}
return;
}
-
+
it.remove();
confirmed.remove(key);
assertEquals(false, map.containsKey(key));
verify();
-
+
try {
it.remove(); // second remove fails
} catch (IllegalStateException ex) {
@@ -286,19 +267,18 @@
if (supportsSetValue() == false || supportsRemove() == false) {
return;
}
- Object newValue = addSetValues()[0];
- MapIterator it = makeFullMapIterator();
- Map map = getMap();
- Map confirmed = getConfirmedMap();
-
+ V newValue = addSetValues()[0];
+ MapIterator<K, V> it = makeObject();
+ Map<K, V> confirmed = getConfirmedMap();
+
assertEquals(true, it.hasNext());
- Object key = it.next();
-
+ K key = it.next();
+
it.setValue(newValue);
it.remove();
confirmed.remove(key);
verify();
-
+
try {
it.setValue(newValue);
fail();
@@ -311,17 +291,16 @@
if (supportsRemove() == false) {
return;
}
- MapIterator it = makeFullMapIterator();
- Map map = getMap();
- Map confirmed = getConfirmedMap();
-
+ MapIterator<K, V> it = makeObject();
+ Map<K, V> confirmed = getConfirmedMap();
+
assertEquals(true, it.hasNext());
- Object key = it.next();
-
+ K key = it.next();
+
it.remove();
confirmed.remove(key);
verify();
-
+
try {
it.getKey();
fail();
@@ -334,17 +313,16 @@
if (supportsRemove() == false) {
return;
}
- MapIterator it = makeFullMapIterator();
- Map map = getMap();
- Map confirmed = getConfirmedMap();
-
+ MapIterator<K, V> it = makeObject();
+ Map<K, V> confirmed = getConfirmedMap();
+
assertEquals(true, it.hasNext());
- Object key = it.next();
-
+ K key = it.next();
+
it.remove();
confirmed.remove(key);
verify();
-
+
try {
it.getValue();
fail();