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 [12/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/bidimap/TestDualTreeBidiMap2.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap2.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap2.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap2.java Tue Sep 15 05:29:56 2009
@@ -25,13 +25,11 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.TreeMap;
import junit.framework.Test;
import junit.textui.TestRunner;
-import org.apache.commons.collections.BidiMap;
import org.apache.commons.collections.BulkTest;
import org.apache.commons.collections.SortedBidiMap;
import org.apache.commons.collections.comparators.ComparableComparator;
@@ -46,7 +44,7 @@
* @author Stephen Colebourne
* @author Jonas Van Poucke
*/
-public class TestDualTreeBidiMap2 extends AbstractTestSortedBidiMap {
+public class TestDualTreeBidiMap2<K extends Comparable<K>, V extends Comparable<V>> extends AbstractTestSortedBidiMap<K, V> {
public static void main(String[] args) {
TestRunner.run(suite());
@@ -60,21 +58,24 @@
super(testName);
}
- public BidiMap makeEmptyBidiMap() {
- return new DualTreeBidiMap(new ReverseComparator(ComparableComparator.getInstance()));
+ public DualTreeBidiMap<K, V> makeObject() {
+ return new DualTreeBidiMap<K, V>(
+ new ReverseComparator<K>(ComparableComparator.<K> getInstance()),
+ new ReverseComparator<V>(ComparableComparator.<V> getInstance()));
}
- public Map makeConfirmedMap() {
- return new TreeMap(new ReverseComparator(ComparableComparator.getInstance()));
+ public TreeMap<K, V> makeConfirmedMap() {
+ return new TreeMap<K, V>(new ReverseComparator<K>(ComparableComparator.<K>getInstance()));
}
public void testComparator() {
resetEmpty();
- SortedBidiMap bidi = (SortedBidiMap) map;
+ SortedBidiMap<K, V> bidi = (SortedBidiMap<K, V>) map;
assertNotNull(bidi.comparator());
assertTrue(bidi.comparator() instanceof ReverseComparator);
}
+ @SuppressWarnings("unchecked")
public void testSerializeDeserializeCheckComparator() throws Exception {
SortedBidiMap obj = (SortedBidiMap) makeObject();
if (obj instanceof Serializable && isTestSerialization()) {
@@ -95,18 +96,18 @@
}
public void testSortOrder() throws Exception {
- SortedBidiMap sm = (SortedBidiMap) makeFullMap();
+ SortedBidiMap<K, V> sm = makeFullMap();
// Sort by the comparator used in the makeEmptyBidiMap() method
- List newSortedKeys = Arrays.asList(getSampleKeys());
- Collections.sort(newSortedKeys, new ReverseComparator(ComparableComparator.getInstance()));
+ List<K> newSortedKeys = Arrays.asList(getSampleKeys());
+ Collections.sort(newSortedKeys, new ReverseComparator<K>(ComparableComparator.<K>getInstance()));
newSortedKeys = Collections.unmodifiableList(newSortedKeys);
- Iterator mapIter = sm.keySet().iterator();
- Iterator expectedIter = newSortedKeys.iterator();
+ Iterator<K> mapIter = sm.keySet().iterator();
+ Iterator<K> expectedIter = newSortedKeys.iterator();
while (expectedIter.hasNext()) {
- Object expectedKey = expectedIter.next();
- Object mapKey = mapIter.next();
+ K expectedKey = expectedIter.next();
+ K mapKey = mapIter.next();
assertNotNull("key in sorted list may not be null", expectedKey);
assertNotNull("key in map may not be null", mapKey);
assertEquals("key from sorted list and map must be equal", expectedKey, mapKey);
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestTreeBidiMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestTreeBidiMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestTreeBidiMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestTreeBidiMap.java Tue Sep 15 05:29:56 2009
@@ -16,7 +16,6 @@
*/
package org.apache.commons.collections.bidimap;
-import java.util.Map;
import java.util.TreeMap;
import junit.framework.Test;
@@ -32,7 +31,7 @@
*
* @author Stephen Colebourne
*/
-public class TestTreeBidiMap extends AbstractTestOrderedBidiMap {
+public class TestTreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> extends AbstractTestOrderedBidiMap<K, V> {
public static void main(String[] args) {
TestRunner.run(suite());
@@ -46,12 +45,12 @@
super(testName);
}
- public BidiMap makeEmptyBidiMap() {
- return new TreeBidiMap();
+ public BidiMap<K, V> makeObject() {
+ return new TreeBidiMap<K, V>();
}
- public Map makeConfirmedMap() {
- return new TreeMap();
+ public TreeMap<K, V> makeConfirmedMap() {
+ return new TreeMap<K, V>();
}
/**
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableBidiMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableBidiMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableBidiMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableBidiMap.java Tue Sep 15 05:29:56 2009
@@ -32,12 +32,12 @@
*
* @author Stephen Colebourne
*/
-public class TestUnmodifiableBidiMap extends AbstractTestBidiMap {
+public class TestUnmodifiableBidiMap<K, V> extends AbstractTestBidiMap<K, V> {
public static void main(String[] args) {
TestRunner.run(suite());
}
-
+
public static Test suite() {
return BulkTest.makeSuite(TestUnmodifiableBidiMap.class);
}
@@ -46,24 +46,18 @@
super(testName);
}
- public BidiMap makeEmptyBidiMap() {
- return UnmodifiableBidiMap.decorate(new DualHashBidiMap());
- }
- public BidiMap makeFullBidiMap() {
- BidiMap bidi = new DualHashBidiMap();
- for (int i = 0; i < entries.length; i++) {
- bidi.put(entries[i][0], entries[i][1]);
- }
- return UnmodifiableBidiMap.decorate(bidi);
+ public BidiMap<K, V> makeObject() {
+ return UnmodifiableBidiMap.decorate(new DualHashBidiMap<K, V>());
}
- public Map makeFullMap() {
- BidiMap bidi = new DualHashBidiMap();
+
+ public BidiMap<K, V> makeFullMap() {
+ BidiMap<K, V> bidi = new DualHashBidiMap<K, V>();
addSampleMappings(bidi);
return UnmodifiableBidiMap.decorate(bidi);
}
-
- public Map makeConfirmedMap() {
- return new HashMap();
+
+ public Map<K, V> makeConfirmedMap() {
+ return new HashMap<K, V>();
}
/**
@@ -76,11 +70,13 @@
public boolean isPutAddSupported() {
return false;
}
+
public boolean isPutChangeSupported() {
return false;
}
+
public boolean isRemoveSupported() {
return false;
}
-
+
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableOrderedBidiMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableOrderedBidiMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableOrderedBidiMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableOrderedBidiMap.java Tue Sep 15 05:29:56 2009
@@ -33,12 +33,12 @@
*
* @author Stephen Colebourne
*/
-public class TestUnmodifiableOrderedBidiMap extends AbstractTestOrderedBidiMap {
+public class TestUnmodifiableOrderedBidiMap<K extends Comparable<K>, V extends Comparable<V>> extends AbstractTestOrderedBidiMap<K, V> {
public static void main(String[] args) {
TestRunner.run(suite());
}
-
+
public static Test suite() {
return BulkTest.makeSuite(TestUnmodifiableOrderedBidiMap.class);
}
@@ -47,24 +47,18 @@
super(testName);
}
- public BidiMap makeEmptyBidiMap() {
- return UnmodifiableOrderedBidiMap.decorate(new TreeBidiMap());
- }
- public BidiMap makeFullBidiMap() {
- OrderedBidiMap bidi = new TreeBidiMap();
- for (int i = 0; i < entries.length; i++) {
- bidi.put(entries[i][0], entries[i][1]);
- }
- return UnmodifiableOrderedBidiMap.decorate(bidi);
+ public OrderedBidiMap<K, V> makeObject() {
+ return UnmodifiableOrderedBidiMap.decorate(new TreeBidiMap<K, V>());
}
- public Map makeFullMap() {
- OrderedBidiMap bidi = new TreeBidiMap();
+
+ public BidiMap<K, V> makeFullMap() {
+ OrderedBidiMap<K, V> bidi = new TreeBidiMap<K, V>();
addSampleMappings(bidi);
return UnmodifiableOrderedBidiMap.decorate(bidi);
}
-
- public Map makeConfirmedMap() {
- return new TreeMap();
+
+ public Map<K, V> makeConfirmedMap() {
+ return new TreeMap<K, V>();
}
/**
@@ -73,21 +67,25 @@
public String[] ignoredTests() {
return new String[] {"TestUnmodifiableOrderedBidiMap.bulkTestInverseMap.bulkTestInverseMap"};
}
-
+
public boolean isAllowNullKey() {
return false;
}
+
public boolean isAllowNullValue() {
return false;
}
+
public boolean isPutAddSupported() {
return false;
}
+
public boolean isPutChangeSupported() {
return false;
}
+
public boolean isRemoveSupported() {
return false;
}
-
+
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableSortedBidiMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableSortedBidiMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableSortedBidiMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableSortedBidiMap.java Tue Sep 15 05:29:56 2009
@@ -16,13 +16,12 @@
*/
package org.apache.commons.collections.bidimap;
-import java.util.Map;
+import java.util.SortedMap;
import java.util.TreeMap;
import junit.framework.Test;
import junit.textui.TestRunner;
-import org.apache.commons.collections.BidiMap;
import org.apache.commons.collections.BulkTest;
import org.apache.commons.collections.SortedBidiMap;
@@ -33,12 +32,12 @@
*
* @author Stephen Colebourne
*/
-public class TestUnmodifiableSortedBidiMap extends AbstractTestSortedBidiMap {
+public class TestUnmodifiableSortedBidiMap<K extends Comparable<K>, V extends Comparable<V>> extends AbstractTestSortedBidiMap<K, V> {
public static void main(String[] args) {
TestRunner.run(suite());
}
-
+
public static Test suite() {
return BulkTest.makeSuite(TestUnmodifiableSortedBidiMap.class);
}
@@ -48,30 +47,25 @@
}
//-----------------------------------------------------------------------
- public BidiMap makeEmptyBidiMap() {
- return UnmodifiableSortedBidiMap.decorate(new DualTreeBidiMap());
- }
- public BidiMap makeFullBidiMap() {
- SortedBidiMap bidi = new DualTreeBidiMap();
- for (int i = 0; i < entries.length; i++) {
- bidi.put(entries[i][0], entries[i][1]);
- }
- return UnmodifiableSortedBidiMap.decorate(bidi);
+ public SortedBidiMap<K, V> makeObject() {
+ return UnmodifiableSortedBidiMap.decorate(new DualTreeBidiMap<K, V>());
}
- public Map makeFullMap() {
- SortedBidiMap bidi = new DualTreeBidiMap();
+
+ public SortedBidiMap<K, V> makeFullMap() {
+ SortedBidiMap<K, V> bidi = new DualTreeBidiMap<K, V>();
addSampleMappings(bidi);
return UnmodifiableSortedBidiMap.decorate(bidi);
}
-
- public Map makeConfirmedMap() {
- return new TreeMap();
+
+ public SortedMap<K, V> makeConfirmedMap() {
+ return new TreeMap<K, V>();
}
public boolean isSubMapViewsSerializable() {
// TreeMap sub map views have a bug in deserialization.
return false;
}
+
public String[] ignoredTests() {
// Override to prevent infinite recursion of tests.
return new String[] {"TestUnmodifiableSortedBidiMap.bulkTestInverseMap.bulkTestInverseMap"};
@@ -81,17 +75,21 @@
public boolean isAllowNullKey() {
return false;
}
+
public boolean isAllowNullValue() {
return false;
}
+
public boolean isPutAddSupported() {
return false;
}
+
public boolean isPutChangeSupported() {
return false;
}
+
public boolean isRemoveSupported() {
return false;
}
-
+
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBlockingBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBlockingBuffer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBlockingBuffer.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBlockingBuffer.java Tue Sep 15 05:29:56 2009
@@ -29,30 +29,31 @@
import java.util.Set;
/**
- * Extension of {@link AbstractTestObject} for exercising the {@link BlockingBuffer} implementation.
+ * Extension of {@link AbstractTestObject} for exercising the
+ * {@link BlockingBuffer} implementation.
*
* @author Janek Bogucki
* @author Phil Steitz
* @version $Revision$
* @since Commons Collections 3.0
*/
-public class TestBlockingBuffer extends AbstractTestObject {
+public class TestBlockingBuffer<E> extends AbstractTestObject {
- public TestBlockingBuffer( String testName ) {
- super( testName );
+ public TestBlockingBuffer(String testName) {
+ super(testName);
}
public static Test suite() {
- return new TestSuite( TestBlockingBuffer.class );
+ return new TestSuite(TestBlockingBuffer.class);
}
- public static void main( String args[] ) {
- String[] testCaseName = {TestBlockingBuffer.class.getName()};
- junit.textui.TestRunner.main( testCaseName );
+ public static void main(String args[]) {
+ String[] testCaseName = { TestBlockingBuffer.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
}
- public Object makeObject() {
- return BlockingBuffer.decorate( new MyBuffer() );
+ public Buffer<E> makeObject() {
+ return BlockingBuffer.decorate(new MyBuffer<E>());
}
public boolean isEqualsCheckable() {
@@ -61,113 +62,122 @@
//-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
+ protected E makeElement() {
+ return (E) new Object();
+ }
+
/**
- * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#add(Object)}.
+ * Tests {@link BlockingBuffer#get()} in combination with
+ * {@link BlockingBuffer#add(Object)}.
*/
public void testGetWithAdd() {
- Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() );
- Object obj = new Object();
- new DelayedAdd( blockingBuffer, obj ).start();
+ Buffer<E> blockingBuffer = makeObject();
+ E obj = makeElement();
+ new DelayedAdd<E>(blockingBuffer, obj).start();
// verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
- assertSame( obj, blockingBuffer.get() );
+ assertSame(obj, blockingBuffer.get());
}
public void testGetWithAddTimeout() {
- Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer(), 500 );
- Object obj = new Object();
- new DelayedAdd( blockingBuffer, obj, 100 ).start();
+ Buffer<E> blockingBuffer = BlockingBuffer.decorate(new MyBuffer<E>(), 500);
+ E obj = makeElement();
+ new DelayedAdd<E>(blockingBuffer, obj, 100).start();
// verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
- assertSame( obj, blockingBuffer.get() );
+ assertSame(obj, blockingBuffer.get());
}
//-----------------------------------------------------------------------
/**
- * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#addAll(java.util.Collection)}.
+ * Tests {@link BlockingBuffer#get()} in combination with
+ * {@link BlockingBuffer#addAll(java.util.Collection)}.
*/
public void testGetWithAddAll() {
- Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() );
- Object obj = new Object();
- new DelayedAddAll( blockingBuffer, obj ).start();
+ Buffer<E> blockingBuffer = makeObject();
+ E obj = makeElement();
+ new DelayedAddAll<E>(blockingBuffer, obj).start();
// verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
- assertSame( obj, blockingBuffer.get() );
+ assertSame(obj, blockingBuffer.get());
}
public void testGetWithAddAllTimeout() {
- Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer(), 500 );
- Object obj = new Object();
- new DelayedAddAll( blockingBuffer, obj, 100 ).start();
+ Buffer<E> blockingBuffer = BlockingBuffer.decorate(new MyBuffer<E>(), 500);
+ E obj = makeElement();
+ new DelayedAddAll<E>(blockingBuffer, obj, 100).start();
// verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
- assertSame( obj, blockingBuffer.get() );
+ assertSame(obj, blockingBuffer.get());
}
//-----------------------------------------------------------------------
/**
- * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#add(Object)}.
+ * Tests {@link BlockingBuffer#remove()} in combination with
+ * {@link BlockingBuffer#add(Object)}.
*/
public void testRemoveWithAdd() {
- Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() );
- Object obj = new Object();
- new DelayedAdd( blockingBuffer, obj ).start();
+ Buffer<E> blockingBuffer = makeObject();
+ E obj = makeElement();
+ new DelayedAdd<E>(blockingBuffer, obj).start();
// verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
- assertSame( obj, blockingBuffer.remove() );
+ assertSame(obj, blockingBuffer.remove());
}
public void testRemoveWithAddTimeout() {
- Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer(), 100 );
- Object obj = new Object();
- new DelayedAdd( blockingBuffer, obj, 500 ).start();
+ Buffer<E> blockingBuffer = BlockingBuffer.decorate(new MyBuffer<E>(), 100);
+ E obj = makeElement();
+ new DelayedAdd<E>(blockingBuffer, obj, 500).start();
try {
blockingBuffer.remove();
- }
- catch( BufferUnderflowException e ) {
+ } catch (BufferUnderflowException e) {
}
}
+
//-----------------------------------------------------------------------
/**
- * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#addAll(java.util.Collection)}.
+ * Tests {@link BlockingBuffer#remove()} in combination with
+ * {@link BlockingBuffer#addAll(java.util.Collection)}.
*/
public void testRemoveWithAddAll() {
- Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() );
- Object obj = new Object();
- new DelayedAddAll( blockingBuffer, obj ).start();
+ Buffer<E> blockingBuffer = makeObject();
+ E obj = makeElement();
+ new DelayedAddAll<E>(blockingBuffer, obj).start();
// verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
- assertSame( obj, blockingBuffer.remove() );
+ assertSame(obj, blockingBuffer.remove());
}
public void testRemoveWithAddAllTimeout() {
- Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer(), 100 );
- Object obj = new Object();
- new DelayedAddAll( blockingBuffer, obj, 500 ).start();
+ Buffer<E> blockingBuffer = BlockingBuffer.decorate(new MyBuffer<E>(), 100);
+ E obj = makeElement();
+ new DelayedAddAll<E>(blockingBuffer, obj, 500).start();
try {
blockingBuffer.remove();
- }
- catch( BufferUnderflowException e ) {
+ } catch (BufferUnderflowException e) {
}
}
+
//-----------------------------------------------------------------------
/**
- * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#add(Object)} using multiple read
- * threads.
- * <p/>
- * Two read threads should block on an empty buffer until one object is added then both threads should complete.
+ * Tests {@link BlockingBuffer#get()} in combination with
+ * {@link BlockingBuffer#add(Object)} using multiple read threads. <p/> Two
+ * read threads should block on an empty buffer until one object is added
+ * then both threads should complete.
*/
public void testBlockedGetWithAdd() {
- Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() );
- Object obj = new Object();
+ Buffer<E> blockingBuffer = makeObject();
+ E obj = makeElement();
// run methods will get and compare -- must wait for add
- Thread thread1 = new ReadThread( blockingBuffer, obj );
- Thread thread2 = new ReadThread( blockingBuffer, obj );
+ Thread thread1 = new ReadThread<E>(blockingBuffer, obj);
+ Thread thread2 = new ReadThread<E>(blockingBuffer, obj);
thread1.start();
thread2.start();
@@ -175,32 +185,32 @@
delay();
// notifyAll should allow both read threads to complete
- blockingBuffer.add( obj );
+ blockingBuffer.add(obj);
// allow notified threads to complete
delay();
// There should not be any threads waiting.
- if( thread1.isAlive() || thread2.isAlive() ) {
- fail( "Live thread(s) when both should be dead." );
+ if (thread1.isAlive() || thread2.isAlive()) {
+ fail("Live thread(s) when both should be dead.");
}
}
//-----------------------------------------------------------------------
/**
- * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#addAll(java.util.Collection)} using
- * multiple read threads.
- * <p/>
- * Two read threads should block on an empty buffer until a singleton is added then both threads should complete.
+ * Tests {@link BlockingBuffer#get()} in combination with
+ * {@link BlockingBuffer#addAll(java.util.Collection)} using multiple read
+ * threads. <p/> Two read threads should block on an empty buffer until a
+ * singleton is added then both threads should complete.
*/
public void testBlockedGetWithAddAll() {
- Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() );
- Object obj = new Object();
+ Buffer<E> blockingBuffer = makeObject();
+ E obj = makeElement();
// run methods will get and compare -- must wait for addAll
- Thread thread1 = new ReadThread( blockingBuffer, obj );
- Thread thread2 = new ReadThread( blockingBuffer, obj );
+ Thread thread1 = new ReadThread<E>(blockingBuffer, obj);
+ Thread thread2 = new ReadThread<E>(blockingBuffer, obj);
thread1.start();
thread2.start();
@@ -208,14 +218,14 @@
delay();
// notifyAll should allow both read threads to complete
- blockingBuffer.addAll( Collections.singleton( obj ) );
+ blockingBuffer.addAll(Collections.singleton(obj));
// allow notified threads to complete
delay();
// There should not be any threads waiting.
- if( thread1.isAlive() || thread2.isAlive() ) {
- fail( "Live thread(s) when both should be dead." );
+ if (thread1.isAlive() || thread2.isAlive()) {
+ fail("Live thread(s) when both should be dead.");
}
}
@@ -225,12 +235,12 @@
* Tests interrupted {@link BlockingBuffer#get()}.
*/
public void testInterruptedGet() {
- Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() );
- Object obj = new Object();
+ Buffer<E> blockingBuffer = makeObject();
+ E obj = makeElement();
// spawn a read thread to wait on the empty buffer
- ArrayList exceptionList = new ArrayList();
- Thread thread = new ReadThread( blockingBuffer, obj, exceptionList );
+ ArrayList<String> exceptionList = new ArrayList<String>();
+ Thread thread = new ReadThread<E>(blockingBuffer, obj, exceptionList);
thread.start();
// Interrupting the thread should cause it to throw BufferUnderflowException
@@ -238,10 +248,10 @@
// Chill, so thread can throw and add message to exceptionList
delay();
- assertTrue( "Thread interrupt should have led to underflow",
- exceptionList.contains( "BufferUnderFlow" ) );
- if( thread.isAlive() ) {
- fail( "Read thread has hung." );
+ assertTrue("Thread interrupt should have led to underflow", exceptionList
+ .contains("BufferUnderFlow"));
+ if (thread.isAlive()) {
+ fail("Read thread has hung.");
}
}
@@ -249,115 +259,116 @@
//-----------------------------------------------------------------------
/**
- * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#add(Object)} using multiple read
- * threads.
- * <p/>
- * Two read threads should block on an empty buffer until one object is added then one thread should complete. The
- * remaining thread should complete after the addition of a second object.
+ * Tests {@link BlockingBuffer#remove()} in combination with
+ * {@link BlockingBuffer#add(Object)} using multiple read threads. <p/> Two
+ * read threads should block on an empty buffer until one object is added
+ * then one thread should complete. The remaining thread should complete
+ * after the addition of a second object.
*/
public void testBlockedRemoveWithAdd() {
- Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() );
- Object obj = new Object();
+ Buffer<E> blockingBuffer = makeObject();
+ E obj = makeElement();
// run methods will remove and compare -- must wait for add
- Thread thread1 = new ReadThread( blockingBuffer, obj, null, "remove" );
- Thread thread2 = new ReadThread( blockingBuffer, obj, null, "remove" );
+ Thread thread1 = new ReadThread<E>(blockingBuffer, obj, null, "remove");
+ Thread thread2 = new ReadThread<E>(blockingBuffer, obj, null, "remove");
thread1.start();
thread2.start();
// give hungry read threads ample time to hang
delay();
- blockingBuffer.add( obj );
+ blockingBuffer.add(obj);
// allow notified threads to complete
delay();
// There should be one thread waiting.
- assertTrue( "There is one thread waiting", thread1.isAlive() ^ thread2.isAlive() );
- blockingBuffer.add( obj );
+ assertTrue("There is one thread waiting", thread1.isAlive() ^ thread2.isAlive());
+ blockingBuffer.add(obj);
// allow notified thread to complete
delay();
// There should not be any threads waiting.
- if( thread1.isAlive() || thread2.isAlive() ) {
- fail( "Live thread(s) when both should be dead." );
+ if (thread1.isAlive() || thread2.isAlive()) {
+ fail("Live thread(s) when both should be dead.");
}
}
//-----------------------------------------------------------------------
/**
- * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#addAll(java.util.Collection)}
- * using multiple read threads.
- * <p/>
- * Two read threads should block on an empty buffer until a singleton collection is added then one thread should
- * complete. The remaining thread should complete after the addition of a second singleton.
+ * Tests {@link BlockingBuffer#remove()} in combination with
+ * {@link BlockingBuffer#addAll(java.util.Collection)} using multiple read
+ * threads. <p/> Two read threads should block on an empty buffer until a
+ * singleton collection is added then one thread should complete. The
+ * remaining thread should complete after the addition of a second
+ * singleton.
*/
public void testBlockedRemoveWithAddAll1() {
- Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() );
- Object obj = new Object();
+ Buffer<E> blockingBuffer = makeObject();
+ E obj = makeElement();
// run methods will remove and compare -- must wait for addAll
- Thread thread1 = new ReadThread( blockingBuffer, obj, null, "remove" );
- Thread thread2 = new ReadThread( blockingBuffer, obj, null, "remove" );
+ Thread thread1 = new ReadThread<E>(blockingBuffer, obj, null, "remove");
+ Thread thread2 = new ReadThread<E>(blockingBuffer, obj, null, "remove");
thread1.start();
thread2.start();
// give hungry read threads ample time to hang
delay();
- blockingBuffer.addAll( Collections.singleton( obj ) );
+ blockingBuffer.addAll(Collections.singleton(obj));
// allow notified threads to complete
delay();
// There should be one thread waiting.
- assertTrue( "There is one thread waiting", thread1.isAlive() ^ thread2.isAlive() );
- blockingBuffer.addAll( Collections.singleton( obj ) );
+ assertTrue("There is one thread waiting", thread1.isAlive() ^ thread2.isAlive());
+ blockingBuffer.addAll(Collections.singleton(obj));
// allow notified thread to complete
delay();
// There should not be any threads waiting.
- if( thread1.isAlive() || thread2.isAlive() ) {
- fail( "Live thread(s) when both should be dead." );
+ if (thread1.isAlive() || thread2.isAlive()) {
+ fail("Live thread(s) when both should be dead.");
}
}
//-----------------------------------------------------------------------
/**
- * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#addAll(java.util.Collection)}
- * using multiple read threads.
- * <p/>
- * Two read threads should block on an empty buffer until a collection with two distinct objects is added then both
- * threads should complete. Each thread should have read a different object.
+ * Tests {@link BlockingBuffer#remove()} in combination with
+ * {@link BlockingBuffer#addAll(java.util.Collection)} using multiple read
+ * threads. <p/> Two read threads should block on an empty buffer until a
+ * collection with two distinct objects is added then both threads should
+ * complete. Each thread should have read a different object.
*/
public void testBlockedRemoveWithAddAll2() {
- Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() );
- Object obj1 = new Object();
- Object obj2 = new Object();
- Set objs = Collections.synchronizedSet( new HashSet() );
- objs.add( obj1 );
- objs.add( obj2 );
+ Buffer<E> blockingBuffer = makeObject();
+ E obj1 = makeElement();
+ E obj2 = makeElement();
+ Set<E> objs = Collections.synchronizedSet(new HashSet<E>());
+ objs.add(obj1);
+ objs.add(obj2);
// run methods will remove and compare -- must wait for addAll
- Thread thread1 = new ReadThread( blockingBuffer, objs, "remove" );
- Thread thread2 = new ReadThread( blockingBuffer, objs, "remove" );
+ Thread thread1 = new ReadThread<E>(blockingBuffer, objs, "remove");
+ Thread thread2 = new ReadThread<E>(blockingBuffer, objs, "remove");
thread1.start();
thread2.start();
// give hungry read threads ample time to hang
delay();
- blockingBuffer.addAll( objs );
+ blockingBuffer.addAll(objs);
// allow notified threads to complete
delay();
- assertEquals( "Both objects were removed", 0, objs.size() );
+ assertEquals("Both objects were removed", 0, objs.size());
// There should not be any threads waiting.
- if( thread1.isAlive() || thread2.isAlive() ) {
- fail( "Live thread(s) when both should be dead." );
+ if (thread1.isAlive() || thread2.isAlive()) {
+ fail("Live thread(s) when both should be dead.");
}
}
@@ -367,12 +378,12 @@
* Tests interrupted remove.
*/
public void testInterruptedRemove() {
- Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() );
- Object obj = new Object();
+ Buffer<E> blockingBuffer = makeObject();
+ E obj = makeElement();
// spawn a read thread to wait on the empty buffer
- ArrayList exceptionList = new ArrayList();
- Thread thread = new ReadThread( blockingBuffer, obj, exceptionList, "remove" );
+ ArrayList<String> exceptionList = new ArrayList<String>();
+ Thread thread = new ReadThread<E>(blockingBuffer, obj, exceptionList, "remove");
thread.start();
// Interrupting the thread should cause it to throw BufferUnderflowException
@@ -380,49 +391,47 @@
// Chill, so thread can throw and add message to exceptionList
delay();
- assertTrue( "Thread interrupt should have led to underflow",
- exceptionList.contains( "BufferUnderFlow" ) );
- if( thread.isAlive() ) {
- fail( "Read thread has hung." );
+ assertTrue("Thread interrupt should have led to underflow", exceptionList
+ .contains("BufferUnderFlow"));
+ if (thread.isAlive()) {
+ fail("Read thread has hung.");
}
}
public void testTimeoutGet() {
- final BlockingBuffer buffer = new BlockingBuffer( new MyBuffer() );
+ final BlockingBuffer<E> buffer = new BlockingBuffer<E>(new MyBuffer<E>());
try {
- buffer.get( 100 );
- fail( "Get should have timed out." );
- }
- catch( BufferUnderflowException e ) {
+ buffer.get(100);
+ fail("Get should have timed out.");
+ } catch (BufferUnderflowException e) {
}
}
public void testTimeoutRemove() {
- final BlockingBuffer buffer = new BlockingBuffer( new MyBuffer() );
+ final BlockingBuffer<E> buffer = new BlockingBuffer<E>(new MyBuffer<E>());
try {
- buffer.remove( 100 );
- fail( "Get should have timed out." );
- }
- catch( BufferUnderflowException e ) {
+ buffer.remove(100);
+ fail("Get should have timed out.");
+ } catch (BufferUnderflowException e) {
}
}
- protected static class DelayedAdd extends Thread {
+ protected static class DelayedAdd<E> extends Thread {
- Buffer buffer;
+ Buffer<E> buffer;
- Object obj;
+ E obj;
long delay = 1000;
- public DelayedAdd( Buffer buffer, Object obj, long delay ) {
+ public DelayedAdd(Buffer<E> buffer, E obj, long delay) {
this.buffer = buffer;
this.obj = obj;
this.delay = delay;
}
- DelayedAdd( Buffer buffer, Object obj ) {
+ DelayedAdd(Buffer<E> buffer, E obj) {
super();
this.buffer = buffer;
this.obj = obj;
@@ -431,29 +440,28 @@
public void run() {
try {
// wait for other thread to block on get() or remove()
- Thread.sleep( delay );
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
}
- catch( InterruptedException e ) {
- }
- buffer.add( obj );
+ buffer.add(obj);
}
}
- protected static class DelayedAddAll extends Thread {
+ protected static class DelayedAddAll<E> extends Thread {
- Buffer buffer;
+ Buffer<E> buffer;
- Object obj;
+ E obj;
long delay = 100;
- public DelayedAddAll( Buffer buffer, Object obj, long delay ) {
+ public DelayedAddAll(Buffer<E> buffer, E obj, long delay) {
this.buffer = buffer;
this.obj = obj;
this.delay = delay;
}
- DelayedAddAll( Buffer buffer, Object obj ) {
+ DelayedAddAll(Buffer<E> buffer, E obj) {
super();
this.buffer = buffer;
this.obj = obj;
@@ -462,40 +470,39 @@
public void run() {
try {
// wait for other thread to block on get() or remove()
- Thread.sleep( delay );
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
}
- catch( InterruptedException e ) {
- }
- buffer.addAll( Collections.singleton( obj ) );
+ buffer.addAll(Collections.singleton(obj));
}
}
- protected static class ReadThread extends Thread {
+ protected static class ReadThread<E> extends Thread {
- Buffer buffer;
+ Buffer<E> buffer;
Object obj;
- ArrayList exceptionList = null;
+ ArrayList<String> exceptionList = null;
String action = "get";
- Set objs;
+ Set<E> objs;
- ReadThread( Buffer buffer, Object obj ) {
+ ReadThread(Buffer<E> buffer, Object obj) {
super();
this.buffer = buffer;
this.obj = obj;
}
- ReadThread( Buffer buffer, Object obj, ArrayList exceptionList ) {
+ ReadThread(Buffer<E> buffer, Object obj, ArrayList<String> exceptionList) {
super();
this.buffer = buffer;
this.obj = obj;
this.exceptionList = exceptionList;
}
- ReadThread( Buffer buffer, Object obj, ArrayList exceptionList, String action ) {
+ ReadThread(Buffer<E> buffer, Object obj, ArrayList<String> exceptionList, String action) {
super();
this.buffer = buffer;
this.obj = obj;
@@ -503,7 +510,7 @@
this.action = action;
}
- ReadThread( Buffer buffer, Set objs, String action ) {
+ ReadThread(Buffer<E> buffer, Set<E> objs, String action) {
super();
this.buffer = buffer;
this.objs = objs;
@@ -512,46 +519,43 @@
public void run() {
try {
- if( action == "get" ) {
- assertSame( obj, buffer.get() );
- }
- else {
- if( null != obj ) {
- assertSame( obj, buffer.remove() );
- }
- else {
- assertTrue( objs.remove( buffer.remove() ) );
+ if (action == "get") {
+ assertSame(obj, buffer.get());
+ } else {
+ if (null != obj) {
+ assertSame(obj, buffer.remove());
+ } else {
+ assertTrue(objs.remove(buffer.remove()));
}
}
- }
- catch( BufferUnderflowException ex ) {
- exceptionList.add( "BufferUnderFlow" );
+ } catch (BufferUnderflowException ex) {
+ exceptionList.add("BufferUnderFlow");
}
}
}
- protected static class MyBuffer extends LinkedList implements Buffer {
+ @SuppressWarnings("serial")
+ protected static class MyBuffer<E> extends LinkedList<E> implements Buffer<E> {
- public Object get() {
- if( isEmpty() ) {
+ public E get() {
+ if (isEmpty()) {
throw new BufferUnderflowException();
}
- return get( 0 );
+ return get(0);
}
- public Object remove() {
- if( isEmpty() ) {
+ public E remove() {
+ if (isEmpty()) {
throw new BufferUnderflowException();
}
- return remove( 0 );
+ return remove(0);
}
}
private void delay() {
try {
Thread.sleep( 200 );
- }
- catch( InterruptedException e ) {
+ } catch (InterruptedException e) {
}
}
@@ -559,15 +563,15 @@
return "3.1";
}
-// public void testCreate() throws Exception {
-// Buffer buffer = BlockingBuffer.decorate(new UnboundedFifoBuffer());
-// writeExternalFormToDisk((java.io.Serializable) buffer,
-// "D:/dev/collections/data/test/BlockingBuffer.emptyCollection.version3.1.obj");
-// buffer = BlockingBuffer.decorate(new UnboundedFifoBuffer());
-// buffer.add("A");
-// buffer.add("B");
-// buffer.add("C");
-// writeExternalFormToDisk((java.io.Serializable) buffer,
-// "D:/dev/collections/data/test/BlockingBuffer.fullCollection.version3.1.obj");
-// }
+ // public void testCreate() throws Exception {
+ // Buffer buffer = BlockingBuffer.decorate(new UnboundedFifoBuffer());
+ // writeExternalFormToDisk((java.io.Serializable) buffer,
+ // "D:/dev/collections/data/test/BlockingBuffer.emptyCollection.version3.1.obj");
+ // buffer = BlockingBuffer.decorate(new UnboundedFifoBuffer());
+ // buffer.add("A");
+ // buffer.add("B");
+ // buffer.add("C");
+ // writeExternalFormToDisk((java.io.Serializable) buffer,
+ // "D:/dev/collections/data/test/BlockingBuffer.fullCollection.version3.1.obj");
+ // }
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBoundedBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBoundedBuffer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBoundedBuffer.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBoundedBuffer.java Tue Sep 15 05:29:56 2009
@@ -28,7 +28,7 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-public class TestBoundedBuffer extends AbstractTestObject {
+public class TestBoundedBuffer<E> extends AbstractTestObject {
public TestBoundedBuffer(String testName) {
super(testName);
@@ -51,136 +51,142 @@
return false;
}
- public Object makeObject() {
- return BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1);
+ public Buffer<E> makeObject() {
+ return BoundedBuffer.decorate(new UnboundedFifoBuffer<E>(), 1);
}
//-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void testMaxSize() {
- final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 2, 500);
- BoundedCollection bc = (BoundedCollection) bounded;
+ final Buffer<E> bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer<E>(), 2, 500);
+ BoundedCollection<?> bc = (BoundedCollection<?>) bounded;
assertEquals(2, bc.maxSize());
assertEquals(false, bc.isFull());
- bounded.add("A");
+ bounded.add((E) "A");
assertEquals(false, bc.isFull());
- bounded.add("B");
+ bounded.add((E) "B");
assertEquals(true, bc.isFull());
bounded.remove();
assertEquals(false, bc.isFull());
try {
- BoundedBuffer.decorate(new UnboundedFifoBuffer(), 0);
+ BoundedBuffer.decorate(new UnboundedFifoBuffer<E>(), 0);
fail();
} catch (IllegalArgumentException ex) {}
try {
- BoundedBuffer.decorate(new UnboundedFifoBuffer(), -1);
+ BoundedBuffer.decorate(new UnboundedFifoBuffer<E>(), -1);
fail();
} catch (IllegalArgumentException ex) {}
}
+ @SuppressWarnings("unchecked")
public void testAddToFullBufferNoTimeout() {
- final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1);
- bounded.add( "Hello" );
+ final Buffer<E> bounded = makeObject();
+ bounded.add((E) "Hello");
try {
- bounded.add("World");
+ bounded.add((E) "World");
fail();
} catch (BufferOverflowException e) {
}
}
+ @SuppressWarnings("unchecked")
public void testAddAllToFullBufferNoTimeout() {
- final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1);
- bounded.add( "Hello" );
+ final Buffer<E> bounded = makeObject();
+ bounded.add((E) "Hello");
try {
- bounded.addAll(Collections.singleton("World"));
+ bounded.addAll(Collections.singleton((E) "World"));
fail();
} catch (BufferOverflowException e) {
}
}
+ @SuppressWarnings("unchecked")
public void testAddAllToEmptyBufferExceedMaxSizeNoTimeout() {
- final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1);
+ final Buffer<E> bounded = makeObject();
try {
- bounded.addAll(Collections.nCopies(2, "test"));
+ bounded.addAll(Collections.nCopies(2, (E) "test"));
fail();
} catch (BufferOverflowException e) {
}
}
+ @SuppressWarnings("unchecked")
public void testAddToFullBufferRemoveViaIterator() {
- final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1, 500);
- bounded.add( "Hello" );
- new DelayedIteratorRemove( bounded, 200 ).start();
- bounded.add( "World" );
- assertEquals( 1, bounded.size() );
- assertEquals( "World", bounded.get() );
+ final Buffer<E> bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer<E>(), 1, 500);
+ bounded.add((E) "Hello");
+ new DelayedIteratorRemove(bounded, 200).start();
+ bounded.add((E) "World");
+ assertEquals(1, bounded.size());
+ assertEquals("World", bounded.get());
}
+ @SuppressWarnings("unchecked")
public void testAddAllToFullBufferRemoveViaIterator() {
- final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 2, 500);
- bounded.add( "Hello" );
- bounded.add( "World" );
- new DelayedIteratorRemove( bounded, 200, 2 ).start();
- bounded.addAll( Arrays.asList( new String[] { "Foo", "Bar" } ) );
- assertEquals( 2, bounded.size() );
- assertEquals( "Foo", bounded.remove() );
- assertEquals( "Bar", bounded.remove() );
+ final Buffer<E> bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer<E>(), 2, 500);
+ bounded.add((E) "Hello");
+ bounded.add((E) "World");
+ new DelayedIteratorRemove(bounded, 200, 2).start();
+ bounded.addAll(Arrays.asList((E[]) new String[] { "Foo", "Bar" }));
+ assertEquals(2, bounded.size());
+ assertEquals("Foo", bounded.remove());
+ assertEquals("Bar", bounded.remove());
}
+ @SuppressWarnings("unchecked")
public void testAddToFullBufferWithTimeout() {
- final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1, 500);
- bounded.add( "Hello" );
- new DelayedRemove( bounded, 200 ).start();
- bounded.add( "World" );
- assertEquals( 1, bounded.size() );
- assertEquals( "World", bounded.get() );
+ final Buffer<E> bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer<E>(), 1, 500);
+ bounded.add((E) "Hello");
+ new DelayedRemove(bounded, 200).start();
+ bounded.add((E) "World");
+ assertEquals(1, bounded.size());
+ assertEquals("World", bounded.get());
try {
- bounded.add( "!" );
+ bounded.add((E) "!");
fail();
- }
- catch( BufferOverflowException e ) {
+ } catch (BufferOverflowException e) {
}
}
+ @SuppressWarnings("unchecked")
public void testAddAllToFullBufferWithTimeout() {
- final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 2, 500);
- bounded.add( "Hello" );
- bounded.add( "World" );
- new DelayedRemove( bounded, 200, 2 ).start();
-
- bounded.addAll( Arrays.asList( new String[] { "Foo", "Bar" } ) );
- assertEquals( 2, bounded.size() );
- assertEquals( "Foo", bounded.get() );
+ final Buffer<E> bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer<E>(), 2, 500);
+ bounded.add((E) "Hello");
+ bounded.add((E) "World");
+ new DelayedRemove(bounded, 200, 2).start();
+
+ bounded.addAll(Arrays.asList((E[]) new String[] { "Foo", "Bar" }));
+ assertEquals(2, bounded.size());
+ assertEquals("Foo", bounded.get());
try {
- bounded.add( "!" );
+ bounded.add((E) "!");
fail();
- }
- catch( BufferOverflowException e ) {
+ } catch (BufferOverflowException e) {
}
}
private class DelayedIteratorRemove extends Thread {
- private final Buffer buffer;
+ private final Buffer<?> buffer;
private final long delay;
private final int nToRemove;
- public DelayedIteratorRemove(Buffer buffer, long delay, int nToRemove) {
+ public DelayedIteratorRemove(Buffer<?> buffer, long delay, int nToRemove) {
this.buffer = buffer;
this.delay = delay;
this.nToRemove = nToRemove;
}
- public DelayedIteratorRemove(Buffer buffer, long delay) {
+ public DelayedIteratorRemove(Buffer<?> buffer, long delay) {
this(buffer, delay, 1);
}
public void run() {
try {
Thread.sleep(delay);
- Iterator iter = buffer.iterator();
+ Iterator<?> iter = buffer.iterator();
for (int i = 0; i < nToRemove; ++i) {
iter.next();
iter.remove();
@@ -193,19 +199,19 @@
private class DelayedRemove extends Thread {
- private final Buffer buffer;
+ private final Buffer<?> buffer;
private final long delay;
private final int nToRemove;
- public DelayedRemove(Buffer buffer, long delay, int nToRemove) {
+ public DelayedRemove(Buffer<?> buffer, long delay, int nToRemove) {
this.buffer = buffer;
this.delay = delay;
this.nToRemove = nToRemove;
}
- public DelayedRemove(Buffer buffer, long delay) {
+ public DelayedRemove(Buffer<?> buffer, long delay) {
this(buffer, delay, 1);
}
@@ -219,4 +225,4 @@
}
}
}
-}
\ No newline at end of file
+}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer.java Tue Sep 15 05:29:56 2009
@@ -17,8 +17,8 @@
package org.apache.commons.collections.buffer;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
import junit.framework.Test;
@@ -33,7 +33,7 @@
*
* @author Paul Jack
*/
-public class TestBoundedFifoBuffer extends AbstractTestCollection {
+public class TestBoundedFifoBuffer<E> extends AbstractTestCollection<E> {
public TestBoundedFifoBuffer(String n) {
super(n);
@@ -45,18 +45,18 @@
//-----------------------------------------------------------------------
/**
- * Runs through the regular verifications, but also verifies that
+ * Runs through the regular verifications, but also verifies that
* the buffer contains the same elements in the same sequence as the
* list.
*/
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();
- Object o2 = iterator2.next();
+ E o1 = iterator1.next();
+ E o2 = iterator2.next();
assertEquals(o1, o2);
}
}
@@ -78,14 +78,14 @@
return false;
}
- //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
/**
* Returns an empty ArrayList.
*
* @return an empty ArrayList
*/
- public Collection makeConfirmedCollection() {
- return new ArrayList();
+ public List<E> makeConfirmedCollection() {
+ return new ArrayList<E>();
}
/**
@@ -93,37 +93,37 @@
*
* @return a full ArrayList
*/
- public Collection makeConfirmedFullCollection() {
- Collection c = makeConfirmedCollection();
+ public List<E> makeConfirmedFullCollection() {
+ List<E> c = makeConfirmedCollection();
c.addAll(java.util.Arrays.asList(getFullElements()));
return c;
}
/**
- * Returns an empty BoundedFifoBuffer that won't overflow.
- *
+ * Returns an empty BoundedFifoBuffer that won't overflow.
+ *
* @return an empty BoundedFifoBuffer
*/
- public Collection makeCollection() {
- return new BoundedFifoBuffer(100);
+ public BoundedFifoBuffer<E> makeObject() {
+ return new BoundedFifoBuffer<E>(100);
}
- //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
/**
* Tests that the removal operation actually removes the first element.
*/
public void testBoundedFifoBufferRemove() {
resetFull();
- int size = confirmed.size();
+ int size = getConfirmed().size();
for (int i = 0; i < size; i++) {
- Object o1 = ((BoundedFifoBuffer)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();
}
try {
- ((BoundedFifoBuffer)collection).remove();
+ getCollection().remove();
fail("Empty buffer should raise Underflow.");
} catch (BufferUnderflowException e) {
// expected
@@ -135,19 +135,19 @@
*/
public void testConstructorException1() {
try {
- new BoundedFifoBuffer(0);
+ new BoundedFifoBuffer<E>(0);
} catch (IllegalArgumentException ex) {
return;
}
fail();
}
-
+
/**
* Tests that the constructor correctly throws an exception.
*/
public void testConstructorException2() {
try {
- new BoundedFifoBuffer(-20);
+ new BoundedFifoBuffer<E>(-20);
} catch (IllegalArgumentException ex) {
return;
}
@@ -159,7 +159,7 @@
*/
public void testConstructorException3() {
try {
- new BoundedFifoBuffer(null);
+ new BoundedFifoBuffer<E>(null);
} catch (NullPointerException ex) {
return;
}
@@ -169,15 +169,16 @@
public String getCompatibilityVersion() {
return "3.1";
}
-
+
// BZ 33071 -- gets start=end=1 before removal of interior element
+ @SuppressWarnings("unchecked")
public void testShift() {
- BoundedFifoBuffer fifo = new BoundedFifoBuffer(3);
- fifo.add("a");
- fifo.add("b");
- fifo.add("c");
+ BoundedFifoBuffer<E> fifo = new BoundedFifoBuffer<E>(3);
+ fifo.add((E) "a");
+ fifo.add((E) "b");
+ fifo.add((E) "c");
fifo.remove();
- fifo.add("e");
+ fifo.add((E) "e");
fifo.remove("c");
}
@@ -188,4 +189,19 @@
// writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/BoundedFifoBuffer.fullCollection.version3.1.obj");
// }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public BoundedFifoBuffer<E> getCollection() {
+ return (BoundedFifoBuffer<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/TestBoundedFifoBuffer2.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer2.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer2.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer2.java Tue Sep 15 05:29:56 2009
@@ -21,7 +21,6 @@
import junit.framework.Test;
-import org.apache.commons.collections.BoundedCollection;
import org.apache.commons.collections.BufferOverflowException;
import org.apache.commons.collections.BulkTest;
@@ -33,7 +32,7 @@
*
* @author Unknown
*/
-public class TestBoundedFifoBuffer2 extends TestBoundedFifoBuffer {
+public class TestBoundedFifoBuffer2<E> extends TestBoundedFifoBuffer<E> {
public TestBoundedFifoBuffer2(String n) {
super(n);
@@ -50,11 +49,10 @@
*
* @return a full BoundedFifoBuffer
*/
- public Collection makeFullCollection() {
- return new BoundedFifoBuffer(Arrays.asList(getFullElements()));
+ public Collection<E> makeFullCollection() {
+ return new BoundedFifoBuffer<E>(Arrays.asList(getFullElements()));
}
-
/**
* Overridden to skip the add tests. All of them would fail with a
* BufferOverflowException.
@@ -65,7 +63,6 @@
return false;
}
-
/**
* Overridden because the add operations raise BufferOverflowException
* instead of UnsupportedOperationException.
@@ -73,14 +70,13 @@
public void testUnsupportedAdd() {
}
-
/**
* Tests to make sure the add operations raise BufferOverflowException.
*/
public void testBufferOverflow() {
resetFull();
try {
- collection.add(getOtherElements()[0]);
+ getCollection().add(getOtherElements()[0]);
fail("add should raise BufferOverflow.");
} catch (BufferOverflowException e) {
// expected
@@ -88,7 +84,7 @@
verify();
try {
- collection.addAll(Arrays.asList(getOtherElements()));
+ getCollection().addAll(Arrays.asList(getOtherElements()));
fail("addAll should raise BufferOverflow.");
} catch (BufferOverflowException e) {
// expected
@@ -99,25 +95,27 @@
/**
* Tests is full
*/
+ @SuppressWarnings("unchecked")
public void testIsFull() {
resetFull();
- assertEquals(true, ((BoundedCollection) collection).isFull());
- ((BoundedFifoBuffer) collection).remove();
- assertEquals(false, ((BoundedCollection) collection).isFull());
- ((BoundedFifoBuffer) collection).add("jj");
- assertEquals(true, ((BoundedCollection) collection).isFull());
+ assertEquals(true, getCollection().isFull());
+ getCollection().remove();
+ assertEquals(false, getCollection().isFull());
+ getCollection().add((E) "jj");
+ assertEquals(true, getCollection().isFull());
}
/**
* Tests max size
*/
+ @SuppressWarnings("unchecked")
public void testMaxSize() {
resetFull();
- assertEquals(getFullElements().length, ((BoundedCollection) collection).maxSize());
- ((BoundedFifoBuffer) collection).remove();
- assertEquals(getFullElements().length, ((BoundedCollection) collection).maxSize());
- ((BoundedFifoBuffer) collection).add("jj");
- assertEquals(getFullElements().length, ((BoundedCollection) collection).maxSize());
+ assertEquals(getFullElements().length, getCollection().maxSize());
+ getCollection().remove();
+ assertEquals(getFullElements().length, getCollection().maxSize());
+ getCollection().add((E) "jj");
+ assertEquals(getFullElements().length, getCollection().maxSize());
}
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestCircularFifoBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestCircularFifoBuffer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestCircularFifoBuffer.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestCircularFifoBuffer.java Tue Sep 15 05:29:56 2009
@@ -40,7 +40,7 @@
*
* @author Stephen Colebourne
*/
-public class TestCircularFifoBuffer extends AbstractTestCollection {
+public class TestCircularFifoBuffer<E> extends AbstractTestCollection<E> {
public TestCircularFifoBuffer(String n) {
super(n);
@@ -56,14 +56,14 @@
//-----------------------------------------------------------------------
/**
- * Runs through the regular verifications, but also verifies that
+ * Runs through the regular verifications, but also verifies that
* the buffer contains the same elements in the same sequence as the
* list.
*/
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();
@@ -95,8 +95,8 @@
*
* @return an empty ArrayList
*/
- public Collection makeConfirmedCollection() {
- return new ArrayList();
+ public Collection<E> makeConfirmedCollection() {
+ return new ArrayList<E>();
}
/**
@@ -104,43 +104,44 @@
*
* @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;
}
/**
- * Returns an empty BoundedFifoBuffer that won't overflow.
- *
+ * Returns an empty BoundedFifoBuffer that won't overflow.
+ *
* @return an empty BoundedFifoBuffer
*/
- public Collection makeCollection() {
- return new CircularFifoBuffer(100);
+ public Collection<E> makeObject() {
+ return new CircularFifoBuffer<E>(100);
}
//-----------------------------------------------------------------------
/**
* Tests that the removal operation actually removes the first element.
*/
+ @SuppressWarnings("unchecked")
public void testCircularFifoBufferCircular() {
- List list = new ArrayList();
- list.add("A");
- list.add("B");
- list.add("C");
- Buffer buf = new CircularFifoBuffer(list);
-
+ List<E> list = new ArrayList<E>();
+ list.add((E) "A");
+ list.add((E) "B");
+ list.add((E) "C");
+ Buffer<E> buf = new CircularFifoBuffer<E>(list);
+
assertEquals(true, buf.contains("A"));
assertEquals(true, buf.contains("B"));
assertEquals(true, buf.contains("C"));
-
- buf.add("D");
-
+
+ buf.add((E) "D");
+
assertEquals(false, buf.contains("A"));
assertEquals(true, buf.contains("B"));
assertEquals(true, buf.contains("C"));
assertEquals(true, buf.contains("D"));
-
+
assertEquals("B", buf.get());
assertEquals("B", buf.remove());
assertEquals("C", buf.remove());
@@ -152,16 +153,16 @@
*/
public void testCircularFifoBufferRemove() {
resetFull();
- int size = confirmed.size();
+ int size = getConfirmed().size();
for (int i = 0; i < size; i++) {
- Object o1 = ((CircularFifoBuffer) collection).remove();
- Object o2 = ((ArrayList) confirmed).remove(0);
+ Object o1 = getCollection().remove();
+ Object o2 = getConfirmed().remove(0);
assertEquals("Removed objects should be equal", o1, o2);
verify();
}
try {
- ((CircularFifoBuffer) collection).remove();
+ getCollection().remove();
fail("Empty buffer should raise Underflow.");
} catch (BufferUnderflowException e) {
// expected
@@ -173,7 +174,7 @@
*/
public void testConstructorException1() {
try {
- new CircularFifoBuffer(0);
+ new CircularFifoBuffer<E>(0);
} catch (IllegalArgumentException ex) {
return;
}
@@ -185,220 +186,230 @@
*/
public void testConstructorException2() {
try {
- new CircularFifoBuffer(-20);
+ new CircularFifoBuffer<E>(-20);
} catch (IllegalArgumentException ex) {
return;
}
fail();
}
-
+
/**
* Tests that the constructor correctly throws an exception.
*/
public void testConstructorException3() {
try {
- new CircularFifoBuffer(null);
+ new CircularFifoBuffer<E>(null);
} catch (NullPointerException ex) {
return;
}
fail();
}
-
+
+ @SuppressWarnings("unchecked")
public void testRemoveError1() throws Exception {
// based on bug 33071
- CircularFifoBuffer fifo = new CircularFifoBuffer(5);
- fifo.add("1");
- fifo.add("2");
- fifo.add("3");
- fifo.add("4");
- fifo.add("5");
-
+ CircularFifoBuffer<E> fifo = new CircularFifoBuffer<E>(5);
+ fifo.add((E) "1");
+ fifo.add((E) "2");
+ fifo.add((E) "3");
+ fifo.add((E) "4");
+ fifo.add((E) "5");
+
assertEquals("[1, 2, 3, 4, 5]", fifo.toString());
-
+
fifo.remove("3");
assertEquals("[1, 2, 4, 5]", fifo.toString());
-
+
fifo.remove("4");
assertEquals("[1, 2, 5]", fifo.toString());
}
+ @SuppressWarnings("unchecked")
public void testRemoveError2() throws Exception {
// based on bug 33071
- CircularFifoBuffer fifo = new CircularFifoBuffer(5);
- fifo.add("1");
- fifo.add("2");
- fifo.add("3");
- fifo.add("4");
- fifo.add("5");
- fifo.add("6");
-
+ CircularFifoBuffer<E> fifo = new CircularFifoBuffer<E>(5);
+ fifo.add((E) "1");
+ fifo.add((E) "2");
+ fifo.add((E) "3");
+ fifo.add((E) "4");
+ fifo.add((E) "5");
+ fifo.add((E) "6");
+
assertEquals(5, fifo.size());
assertEquals("[2, 3, 4, 5, 6]", fifo.toString());
-
+
fifo.remove("3");
assertEquals("[2, 4, 5, 6]", fifo.toString());
-
+
fifo.remove("4");
assertEquals("[2, 5, 6]", fifo.toString());
}
+ @SuppressWarnings("unchecked")
public void testRemoveError3() throws Exception {
// based on bug 33071
- CircularFifoBuffer fifo = new CircularFifoBuffer(5);
- fifo.add("1");
- fifo.add("2");
- fifo.add("3");
- fifo.add("4");
- fifo.add("5");
-
+ CircularFifoBuffer<E> fifo = new CircularFifoBuffer<E>(5);
+ fifo.add((E) "1");
+ fifo.add((E) "2");
+ fifo.add((E) "3");
+ fifo.add((E) "4");
+ fifo.add((E) "5");
+
assertEquals("[1, 2, 3, 4, 5]", fifo.toString());
-
+
fifo.remove("3");
assertEquals("[1, 2, 4, 5]", fifo.toString());
-
- fifo.add("6");
- fifo.add("7");
+
+ fifo.add((E) "6");
+ fifo.add((E) "7");
assertEquals("[2, 4, 5, 6, 7]", fifo.toString());
-
+
fifo.remove("4");
assertEquals("[2, 5, 6, 7]", fifo.toString());
}
+ @SuppressWarnings("unchecked")
public void testRemoveError4() throws Exception {
// based on bug 33071
- CircularFifoBuffer fifo = new CircularFifoBuffer(5);
- fifo.add("1");
- fifo.add("2");
- fifo.add("3");
- fifo.add("4");
- fifo.add("5"); // end=0
- fifo.add("6"); // end=1
- fifo.add("7"); // end=2
-
+ CircularFifoBuffer<E> fifo = new CircularFifoBuffer<E>(5);
+ fifo.add((E) "1");
+ fifo.add((E) "2");
+ fifo.add((E) "3");
+ fifo.add((E) "4");
+ fifo.add((E) "5"); // end=0
+ fifo.add((E) "6"); // end=1
+ fifo.add((E) "7"); // end=2
+
assertEquals("[3, 4, 5, 6, 7]", fifo.toString());
-
+
fifo.remove("4"); // remove element in middle of array, after start
assertEquals("[3, 5, 6, 7]", fifo.toString());
}
+ @SuppressWarnings("unchecked")
public void testRemoveError5() throws Exception {
// based on bug 33071
- CircularFifoBuffer fifo = new CircularFifoBuffer(5);
- fifo.add("1");
- fifo.add("2");
- fifo.add("3");
- fifo.add("4");
- fifo.add("5"); // end=0
- fifo.add("6"); // end=1
- fifo.add("7"); // end=2
-
+ CircularFifoBuffer<E> fifo = new CircularFifoBuffer<E>(5);
+ fifo.add((E) "1");
+ fifo.add((E) "2");
+ fifo.add((E) "3");
+ fifo.add((E) "4");
+ fifo.add((E) "5"); // end=0
+ fifo.add((E) "6"); // end=1
+ fifo.add((E) "7"); // end=2
+
assertEquals("[3, 4, 5, 6, 7]", fifo.toString());
-
+
fifo.remove("5"); // remove element at last pos in array
assertEquals("[3, 4, 6, 7]", fifo.toString());
}
+ @SuppressWarnings("unchecked")
public void testRemoveError6() throws Exception {
// based on bug 33071
- CircularFifoBuffer fifo = new CircularFifoBuffer(5);
- fifo.add("1");
- fifo.add("2");
- fifo.add("3");
- fifo.add("4");
- fifo.add("5"); // end=0
- fifo.add("6"); // end=1
- fifo.add("7"); // end=2
-
+ CircularFifoBuffer<E> fifo = new CircularFifoBuffer<E>(5);
+ fifo.add((E) "1");
+ fifo.add((E) "2");
+ fifo.add((E) "3");
+ fifo.add((E) "4");
+ fifo.add((E) "5"); // end=0
+ fifo.add((E) "6"); // end=1
+ fifo.add((E) "7"); // end=2
+
assertEquals("[3, 4, 5, 6, 7]", fifo.toString());
-
+
fifo.remove("6"); // remove element at position zero in array
assertEquals("[3, 4, 5, 7]", fifo.toString());
}
+ @SuppressWarnings("unchecked")
public void testRemoveError7() throws Exception {
// based on bug 33071
- CircularFifoBuffer fifo = new CircularFifoBuffer(5);
- fifo.add("1");
- fifo.add("2");
- fifo.add("3");
- fifo.add("4");
- fifo.add("5"); // end=0
- fifo.add("6"); // end=1
- fifo.add("7"); // end=2
-
+ CircularFifoBuffer<E> fifo = new CircularFifoBuffer<E>(5);
+ fifo.add((E) "1");
+ fifo.add((E) "2");
+ fifo.add((E) "3");
+ fifo.add((E) "4");
+ fifo.add((E) "5"); // end=0
+ fifo.add((E) "6"); // end=1
+ fifo.add((E) "7"); // end=2
+
assertEquals("[3, 4, 5, 6, 7]", fifo.toString());
-
+
fifo.remove("7"); // remove element at position one in array
assertEquals("[3, 4, 5, 6]", fifo.toString());
}
+ @SuppressWarnings("unchecked")
public void testRemoveError8() throws Exception {
// based on bug 33071
- CircularFifoBuffer fifo = new CircularFifoBuffer(5);
- fifo.add("1");
- fifo.add("2");
- fifo.add("3");
- fifo.add("4");
- fifo.add("5"); // end=0
- fifo.add("6"); // end=1
- fifo.add("7"); // end=2
- fifo.add("8"); // end=3
-
+ CircularFifoBuffer<E> fifo = new CircularFifoBuffer<E>(5);
+ fifo.add((E) "1");
+ fifo.add((E) "2");
+ fifo.add((E) "3");
+ fifo.add((E) "4");
+ fifo.add((E) "5"); // end=0
+ fifo.add((E) "6"); // end=1
+ fifo.add((E) "7"); // end=2
+ fifo.add((E) "8"); // end=3
+
assertEquals("[4, 5, 6, 7, 8]", fifo.toString());
-
+
fifo.remove("7"); // remove element at position one in array, need to shift 8
assertEquals("[4, 5, 6, 8]", fifo.toString());
}
+ @SuppressWarnings("unchecked")
public void testRemoveError9() throws Exception {
// based on bug 33071
- CircularFifoBuffer fifo = new CircularFifoBuffer(5);
- fifo.add("1");
- fifo.add("2");
- fifo.add("3");
- fifo.add("4");
- fifo.add("5"); // end=0
- fifo.add("6"); // end=1
- fifo.add("7"); // end=2
- fifo.add("8"); // end=3
-
+ CircularFifoBuffer<E> fifo = new CircularFifoBuffer<E>(5);
+ fifo.add((E) "1");
+ fifo.add((E) "2");
+ fifo.add((E) "3");
+ fifo.add((E) "4");
+ fifo.add((E) "5"); // end=0
+ fifo.add((E) "6"); // end=1
+ fifo.add((E) "7"); // end=2
+ fifo.add((E) "8"); // end=3
+
assertEquals("[4, 5, 6, 7, 8]", fifo.toString());
-
+
fifo.remove("8"); // remove element at position two in array
assertEquals("[4, 5, 6, 7]", fifo.toString());
}
//-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void testRepeatedSerialization() throws Exception {
// bug 31433
- CircularFifoBuffer b = new CircularFifoBuffer(2);
- b.add("a");
+ CircularFifoBuffer<E> b = new CircularFifoBuffer<E>(2);
+ b.add((E) "a");
assertEquals(1, b.size());
assertEquals(true, b.contains("a"));
-
+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
new ObjectOutputStream(bos).writeObject(b);
-
- CircularFifoBuffer b2 = (CircularFifoBuffer) new ObjectInputStream(
+
+ CircularFifoBuffer<E> b2 = (CircularFifoBuffer<E>) new ObjectInputStream(
new ByteArrayInputStream(bos.toByteArray())).readObject();
-
+
assertEquals(1, b2.size());
assertEquals(true, b2.contains("a"));
- b2.add("b");
+ b2.add((E) "b");
assertEquals(2, b2.size());
assertEquals(true, b2.contains("a"));
assertEquals(true, b2.contains("b"));
-
+
bos = new ByteArrayOutputStream();
new ObjectOutputStream(bos).writeObject(b2);
-
- CircularFifoBuffer b3 = (CircularFifoBuffer) new ObjectInputStream(
+
+ CircularFifoBuffer<E> b3 = (CircularFifoBuffer<E>) new ObjectInputStream(
new ByteArrayInputStream(bos.toByteArray())).readObject();
-
+
assertEquals(2, b3.size());
assertEquals(true, b3.contains("a"));
assertEquals(true, b3.contains("b"));
- b3.add("c");
+ b3.add((E) "c");
assertEquals(2, b3.size());
assertEquals(true, b3.contains("b"));
assertEquals(true, b3.contains("c"));
@@ -415,4 +426,19 @@
// writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/CircularFifoBuffer.fullCollection.version3.1.obj");
// }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public CircularFifoBuffer<E> getCollection() {
+ return (CircularFifoBuffer<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/TestPredicatedBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPredicatedBuffer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPredicatedBuffer.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPredicatedBuffer.java Tue Sep 15 05:29:56 2009
@@ -28,7 +28,7 @@
import org.apache.commons.collections.collection.TestPredicatedCollection;
/**
- * Extension of {@link TestPredicatedCollection} for exercising the
+ * Extension of {@link TestPredicatedCollection} for exercising the
* {@link PredicatedBuffer} implementation.
*
* @since Commons Collections 3.0
@@ -36,71 +36,73 @@
*
* @author Phil Steitz
*/
-public class TestPredicatedBuffer extends TestPredicatedCollection {
-
+public class TestPredicatedBuffer<E> extends TestPredicatedCollection<E> {
+
public TestPredicatedBuffer(String testName) {
super(testName);
}
-
+
public static Test suite() {
return new TestSuite(TestPredicatedBuffer.class);
}
-
+
public static void main(String args[]) {
String[] testCaseName = { TestPredicatedBuffer.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
-
+
//---------------------------------------------------------------
-
- protected Buffer decorateBuffer(Buffer buffer, Predicate predicate) {
+
+ protected Buffer<E> decorateCollection(Buffer<E> buffer, Predicate<E> predicate) {
return PredicatedBuffer.decorate(buffer, predicate);
}
-
- public Collection makeCollection() {
- return decorateBuffer(new ArrayStack(), truePredicate);
- }
-
- public Collection makeConfirmedCollection() {
- return new ArrayStack();
- }
-
- public Collection makeConfirmedFullCollection() {
- ArrayStack list = new ArrayStack();
+
+ public Buffer<E> makeObject() {
+ return decorateCollection(new ArrayStack<E>(), truePredicate);
+ }
+
+ public Collection<E> makeConfirmedCollection() {
+ return new ArrayStack<E>();
+ }
+
+ public Collection<E> makeConfirmedFullCollection() {
+ ArrayStack<E> list = new ArrayStack<E>();
list.addAll(java.util.Arrays.asList(getFullElements()));
return list;
}
-
+
//------------------------------------------------------------
-
- public Buffer makeTestBuffer() {
- return decorateBuffer(new ArrayStack(), testPredicate);
+
+ public Buffer<E> makeTestBuffer() {
+ return decorateCollection(new ArrayStack<E>(), testPredicate);
}
-
+
+ @SuppressWarnings("unchecked")
public void testGet() {
- Buffer buffer = makeTestBuffer();
+ Buffer<E> buffer = makeTestBuffer();
try {
- Object o = buffer.get();
+ buffer.get();
fail("Expecting BufferUnderflowException");
} catch (BufferUnderflowException ex) {
// expected
}
- buffer.add("one");
- buffer.add("two");
- buffer.add("three");
+ buffer.add((E) "one");
+ buffer.add((E) "two");
+ buffer.add((E) "three");
assertEquals("Buffer get", "three", buffer.get());
}
-
+
+ @SuppressWarnings("unchecked")
public void testRemove() {
- Buffer buffer = makeTestBuffer();
- buffer.add("one");
+ Buffer<E> buffer = makeTestBuffer();
+ buffer.add((E) "one");
assertEquals("Buffer get", "one", buffer.remove());
try {
buffer.remove();
fail("Expecting BufferUnderflowException");
} catch (BufferUnderflowException ex) {
// expected
- }
+ }
}
public String getCompatibilityVersion() {