http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/buffer/TestBoundedBuffer.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/buffer/TestBoundedBuffer.java b/src/test/org/apache/commons/collections/buffer/TestBoundedBuffer.java index 5ad63d7..057f469 100644 --- a/src/test/org/apache/commons/collections/buffer/TestBoundedBuffer.java +++ b/src/test/org/apache/commons/collections/buffer/TestBoundedBuffer.java @@ -28,7 +28,7 @@ import java.util.Arrays; 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 @@ public class TestBoundedBuffer extends AbstractTestObject { 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 @@ public class TestBoundedBuffer extends AbstractTestObject { 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); }
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer.java b/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer.java index a767b6c..8ea7113 100644 --- a/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer.java +++ b/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -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; @@ -28,12 +28,12 @@ import org.apache.commons.collections.collection.AbstractTestCollection; /** * Test cases for BoundedFifoBuffer. - * + * * @version $Revision$ $Date$ - * + * * @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 @@ public class TestBoundedFifoBuffer extends AbstractTestCollection { //----------------------------------------------------------------------- /** - * 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 @@ public class TestBoundedFifoBuffer extends AbstractTestCollection { 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 @@ public class TestBoundedFifoBuffer extends AbstractTestCollection { * * @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 class TestBoundedFifoBuffer extends AbstractTestCollection { */ 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 class TestBoundedFifoBuffer extends AbstractTestCollection { */ public void testConstructorException3() { try { - new BoundedFifoBuffer(null); + new BoundedFifoBuffer<E>(null); } catch (NullPointerException ex) { return; } @@ -169,15 +169,16 @@ public class TestBoundedFifoBuffer extends AbstractTestCollection { 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 @@ public class TestBoundedFifoBuffer extends AbstractTestCollection { // 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(); + } } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer2.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer2.java b/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer2.java index abe84d8..7efcbd1 100644 --- a/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer2.java +++ b/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer2.java @@ -21,7 +21,6 @@ import java.util.Collection; 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 @@ import org.apache.commons.collections.BulkTest; * * @author Unknown */ -public class TestBoundedFifoBuffer2 extends TestBoundedFifoBuffer { +public class TestBoundedFifoBuffer2<E> extends TestBoundedFifoBuffer<E> { public TestBoundedFifoBuffer2(String n) { super(n); @@ -50,11 +49,10 @@ public class TestBoundedFifoBuffer2 extends TestBoundedFifoBuffer { * * @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 @@ public class TestBoundedFifoBuffer2 extends TestBoundedFifoBuffer { return false; } - /** * Overridden because the add operations raise BufferOverflowException * instead of UnsupportedOperationException. @@ -73,14 +70,13 @@ public class TestBoundedFifoBuffer2 extends TestBoundedFifoBuffer { 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 @@ public class TestBoundedFifoBuffer2 extends TestBoundedFifoBuffer { 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 @@ public class TestBoundedFifoBuffer2 extends TestBoundedFifoBuffer { /** * 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()); } } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/buffer/TestCircularFifoBuffer.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/buffer/TestCircularFifoBuffer.java b/src/test/org/apache/commons/collections/buffer/TestCircularFifoBuffer.java index 78f0507..cf1aebd 100644 --- a/src/test/org/apache/commons/collections/buffer/TestCircularFifoBuffer.java +++ b/src/test/org/apache/commons/collections/buffer/TestCircularFifoBuffer.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -35,12 +35,12 @@ import org.apache.commons.collections.collection.AbstractTestCollection; /** * Test cases for CircularFifoBuffer. - * + * * @version $Revision$ $Date$ - * + * * @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 @@ public class TestCircularFifoBuffer extends AbstractTestCollection { //----------------------------------------------------------------------- /** - * 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 @@ public class TestCircularFifoBuffer extends AbstractTestCollection { * * @return an empty ArrayList */ - public Collection makeConfirmedCollection() { - return new ArrayList(); + public Collection<E> makeConfirmedCollection() { + return new ArrayList<E>(); } /** @@ -104,43 +104,44 @@ public class TestCircularFifoBuffer extends AbstractTestCollection { * * @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 class TestCircularFifoBuffer extends AbstractTestCollection { */ 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 class TestCircularFifoBuffer extends AbstractTestCollection { */ public void testConstructorException1() { try { - new CircularFifoBuffer(0); + new CircularFifoBuffer<E>(0); } catch (IllegalArgumentException ex) { return; } @@ -185,220 +186,230 @@ public class TestCircularFifoBuffer extends AbstractTestCollection { */ 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 @@ public class TestCircularFifoBuffer extends AbstractTestCollection { // 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(); + } } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/buffer/TestPredicatedBuffer.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/buffer/TestPredicatedBuffer.java b/src/test/org/apache/commons/collections/buffer/TestPredicatedBuffer.java index 4f8c200..af5659d 100644 --- a/src/test/org/apache/commons/collections/buffer/TestPredicatedBuffer.java +++ b/src/test/org/apache/commons/collections/buffer/TestPredicatedBuffer.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -28,79 +28,81 @@ import org.apache.commons.collections.Predicate; 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 * @version $Revision$ $Date$ - * + * * @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 Buffer<E> makeObject() { + return decorateCollection(new ArrayStack<E>(), truePredicate); } - - public Collection makeConfirmedCollection() { - return new ArrayStack(); + + 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(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", buffer.get(), "three"); } - + + @SuppressWarnings("unchecked") public void testRemove() { - Buffer buffer = makeTestBuffer(); - buffer.add("one"); + Buffer<E> buffer = makeTestBuffer(); + buffer.add((E) "one"); assertEquals("Buffer get", buffer.remove(), "one"); try { buffer.remove(); fail("Expecting BufferUnderflowException"); } catch (BufferUnderflowException ex) { // expected - } + } } public String getCompatibilityVersion() { http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/buffer/TestPriorityBuffer.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/buffer/TestPriorityBuffer.java b/src/test/org/apache/commons/collections/buffer/TestPriorityBuffer.java index 3e2aafb..cff46a8 100644 --- a/src/test/org/apache/commons/collections/buffer/TestPriorityBuffer.java +++ b/src/test/org/apache/commons/collections/buffer/TestPriorityBuffer.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -36,13 +36,13 @@ import org.apache.commons.collections.comparators.ReverseComparator; /** * Tests the PriorityBuffer. - * + * * @version $Revision$ $Date$ - * + * * @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 @@ public class TestPriorityBuffer extends AbstractTestCollection { 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 @@ public class TestPriorityBuffer extends AbstractTestCollection { } } - //----------------------------------------------------------------------- + //----------------------------------------------------------------------- /** * Overridden because BinaryBuffer isn't fail fast. * @return false @@ -90,13 +91,13 @@ public class TestPriorityBuffer extends AbstractTestCollection { 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 @@ public class TestPriorityBuffer extends AbstractTestCollection { /** * 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 @@ public class TestPriorityBuffer extends AbstractTestCollection { fail(); } catch (BufferUnderflowException ex) {} } - + + @SuppressWarnings("unchecked") 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"); + 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 @@ public class TestPriorityBuffer extends AbstractTestCollection { } 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 @@ public class TestPriorityBuffer extends AbstractTestCollection { 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 @@ public class TestPriorityBuffer extends AbstractTestCollection { } /** - * 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 @@ public class TestPriorityBuffer extends AbstractTestCollection { 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 @@ public class TestPriorityBuffer extends AbstractTestCollection { 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 @@ public class TestPriorityBuffer extends AbstractTestCollection { * 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 @@ public class TestPriorityBuffer extends AbstractTestCollection { 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 class TestPriorityBuffer extends AbstractTestCollection { } } - 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 @@ public class TestPriorityBuffer extends AbstractTestCollection { // 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(); + } } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/buffer/TestSynchronizedBuffer.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/buffer/TestSynchronizedBuffer.java b/src/test/org/apache/commons/collections/buffer/TestSynchronizedBuffer.java index 7bb47fd..305a788 100644 --- a/src/test/org/apache/commons/collections/buffer/TestSynchronizedBuffer.java +++ b/src/test/org/apache/commons/collections/buffer/TestSynchronizedBuffer.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,48 +27,47 @@ import org.apache.commons.collections.Buffer; 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 * @version $Revision$ $Date$ - * + * * @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 Buffer<E> makeObject() { + return SynchronizedBuffer.decorate(new UnboundedFifoBuffer<E>()); } - - public Collection makeFullCollection() { - Buffer buffer = new UnboundedFifoBuffer(); + + 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 class TestSynchronizedBuffer extends AbstractTestCollection { public boolean isNullSupported() { return false; } - + public String getCompatibilityVersion() { return "3.1"; } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/buffer/TestTransformedBuffer.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/buffer/TestTransformedBuffer.java b/src/test/org/apache/commons/collections/buffer/TestTransformedBuffer.java index 910622e..d1498a1 100644 --- a/src/test/org/apache/commons/collections/buffer/TestTransformedBuffer.java +++ b/src/test/org/apache/commons/collections/buffer/TestTransformedBuffer.java @@ -49,9 +49,9 @@ public class TestTransformedBuffer extends TestCase { } 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()); http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/buffer/TestUnboundedFifoBuffer.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/buffer/TestUnboundedFifoBuffer.java b/src/test/org/apache/commons/collections/buffer/TestUnboundedFifoBuffer.java index 69978f0..a45248d 100644 --- a/src/test/org/apache/commons/collections/buffer/TestUnboundedFifoBuffer.java +++ b/src/test/org/apache/commons/collections/buffer/TestUnboundedFifoBuffer.java @@ -19,6 +19,7 @@ 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; @@ -32,7 +33,7 @@ import org.apache.commons.collections.collection.AbstractTestCollection; * * @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 class TestUnboundedFifoBuffer extends AbstractTestCollection { */ 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 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection { * * @return an empty ArrayList */ - public Collection makeConfirmedCollection() { - return new ArrayList(); + public Collection<E> makeConfirmedCollection() { + return new ArrayList<E>(); } /** @@ -91,8 +92,8 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection { * * @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 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection { * * @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 class TestUnboundedFifoBuffer extends AbstractTestCollection { */ 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 class TestUnboundedFifoBuffer extends AbstractTestCollection { */ public void testConstructorException1() { try { - new UnboundedFifoBuffer(0); + new UnboundedFifoBuffer<E>(0); } catch (IllegalArgumentException ex) { return; } @@ -138,7 +139,7 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection { */ public void testConstructorException2() { try { - new UnboundedFifoBuffer(-20); + new UnboundedFifoBuffer<E>(-20); } catch (IllegalArgumentException ex) { return; } @@ -146,43 +147,45 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection { } //----------------------------------------------------------------------- + @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 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection { 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 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection { 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 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection { 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 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection { 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 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection { 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 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection { 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 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection { 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 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection { 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 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection { 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()); @@ -424,4 +437,19 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection { // 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(); + } } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/buffer/TestUnmodifiableBuffer.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/buffer/TestUnmodifiableBuffer.java b/src/test/org/apache/commons/collections/buffer/TestUnmodifiableBuffer.java index 94b21f9..538dc8a 100644 --- a/src/test/org/apache/commons/collections/buffer/TestUnmodifiableBuffer.java +++ b/src/test/org/apache/commons/collections/buffer/TestUnmodifiableBuffer.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,48 +27,47 @@ import org.apache.commons.collections.Buffer; 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 * @version $Revision$ $Date$ - * + * * @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<E> makeObject() { + return UnmodifiableBuffer.decorate(new UnboundedFifoBuffer<E>()); } - - public Collection makeFullCollection() { - Buffer buffer = new UnboundedFifoBuffer(); + + 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 class TestUnmodifiableBuffer extends AbstractTestCollection { 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 @@ public class TestUnmodifiableBuffer extends AbstractTestCollection { // 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(); + } }