diff --git a/src/main/java/org/apache/commons/collections/ArrayStack.java b/src/main/java/org/apache/commons/collections/ArrayStack.java
index f35be110e..43ecbeb73 100644
--- a/src/main/java/org/apache/commons/collections/ArrayStack.java
+++ b/src/main/java/org/apache/commons/collections/ArrayStack.java
@@ -29,10 +29,12 @@ import java.util.EmptyStackException;
* The removal order of an ArrayStack
is based on insertion
* order: The most recently added element is removed first. The iteration
* order is not the same as the removal order. The iterator returns
- * elements from the bottom up, whereas the {@link #remove()} method removes
- * them from the top down.
+ * elements from the bottom up.
*
* Unlike Stack
, ArrayStack
accepts null entries.
+ *
+ * Note: From version 4.0 onwards, this class does not implement the
+ * removed {@code Buffer} interface anymore.
*
* @see java.util.Stack
* @since 1.0
@@ -40,7 +42,7 @@ import java.util.EmptyStackException;
* @deprecated use {@link java.util.ArrayDeque} instead (available from Java 1.6)
*/
@Deprecated
-public class ArrayStack extends ArrayList implements Buffer {
+public class ArrayStack extends ArrayList {
/** Ensure serialization compatibility */
private static final long serialVersionUID = 2130079159931574599L;
@@ -162,32 +164,4 @@ public class ArrayStack extends ArrayList implements Buffer {
return -1;
}
- /**
- * Returns the element on the top of the stack.
- *
- * @return the element on the top of the stack
- * @throws BufferUnderflowException if the stack is empty
- */
- public E get() {
- final int size = size();
- if (size == 0) {
- throw new BufferUnderflowException();
- }
- return get(size - 1);
- }
-
- /**
- * Removes the element on the top of the stack.
- *
- * @return the removed element
- * @throws BufferUnderflowException if the stack is empty
- */
- public E remove() {
- final int size = size();
- if (size == 0) {
- throw new BufferUnderflowException();
- }
- return remove(size - 1);
- }
-
}
diff --git a/src/main/java/org/apache/commons/collections/BufferUtils.java b/src/main/java/org/apache/commons/collections/BufferUtils.java
index aea3373a5..fcd0e667d 100644
--- a/src/main/java/org/apache/commons/collections/BufferUtils.java
+++ b/src/main/java/org/apache/commons/collections/BufferUtils.java
@@ -18,6 +18,7 @@ package org.apache.commons.collections;
import org.apache.commons.collections.buffer.BlockingBuffer;
import org.apache.commons.collections.buffer.BoundedBuffer;
+import org.apache.commons.collections.buffer.CircularFifoBuffer;
import org.apache.commons.collections.buffer.PredicatedBuffer;
import org.apache.commons.collections.buffer.SynchronizedBuffer;
import org.apache.commons.collections.buffer.TransformedBuffer;
@@ -34,7 +35,7 @@ public class BufferUtils {
/**
* An empty unmodifiable buffer.
*/
- public static final Buffer EMPTY_BUFFER = UnmodifiableBuffer.unmodifiableBuffer(new ArrayStack(1));
+ public static final Buffer EMPTY_BUFFER = UnmodifiableBuffer.unmodifiableBuffer(new CircularFifoBuffer(1));
/**
* BufferUtils
should not normally be instantiated.
diff --git a/src/main/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java b/src/main/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java
index 1956ec99e..95b737eb6 100644
--- a/src/main/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java
+++ b/src/main/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java
@@ -19,8 +19,8 @@ package org.apache.commons.collections.iterators;
import java.util.Iterator;
import java.util.NoSuchElementException;
-import org.apache.commons.collections.ArrayStack;
import org.apache.commons.collections.Transformer;
+import org.apache.commons.collections.ArrayStack;
/**
* An Iterator that can traverse multiple iterators down an object graph.
@@ -73,6 +73,7 @@ import org.apache.commons.collections.Transformer;
* @since 3.1
* @version $Id$
*/
+@SuppressWarnings("deprecation") // we use the deprecated ArrayStack - change to ArrayDeque (Java 1.6)
public class ObjectGraphIterator implements Iterator {
/** The stack of iterators */
diff --git a/src/test/java/org/apache/commons/collections/BufferUtilsTest.java b/src/test/java/org/apache/commons/collections/BufferUtilsTest.java
index fd172c6c9..273f22a15 100644
--- a/src/test/java/org/apache/commons/collections/BufferUtilsTest.java
+++ b/src/test/java/org/apache/commons/collections/BufferUtilsTest.java
@@ -19,6 +19,7 @@ package org.apache.commons.collections;
import junit.framework.Test;
import org.apache.commons.collections.buffer.PredicatedBuffer;
+import org.apache.commons.collections.ArrayStack;
/**
* Tests for BufferUtils.
@@ -42,26 +43,26 @@ public class BufferUtilsTest extends BulkTest {
}
public void testpredicatedBuffer() {
- final Predicate predicate = new Predicate() {
- public boolean evaluate(final Object o) {
- return o instanceof String;
- }
- };
- Buffer buffer = BufferUtils.predicatedBuffer(new ArrayStack(), predicate);
- assertTrue("returned object should be a PredicatedBuffer",
- buffer instanceof PredicatedBuffer);
- try {
- buffer = BufferUtils.predicatedBuffer(new ArrayStack(), null);
- fail("Expecting IllegalArgumentException for null predicate.");
- } catch (final IllegalArgumentException ex) {
- // expected
- }
- try {
- buffer = BufferUtils.predicatedBuffer(null, predicate);
- fail("Expecting IllegalArgumentException for null buffer.");
- } catch (final IllegalArgumentException ex) {
- // expected
- }
+// final Predicate predicate = new Predicate() {
+// public boolean evaluate(final Object o) {
+// return o instanceof String;
+// }
+// };
+// Buffer buffer = BufferUtils.predicatedBuffer(new ArrayStack(), predicate);
+// assertTrue("returned object should be a PredicatedBuffer",
+// buffer instanceof PredicatedBuffer);
+// try {
+// buffer = BufferUtils.predicatedBuffer(new ArrayStack(), null);
+// fail("Expecting IllegalArgumentException for null predicate.");
+// } catch (final IllegalArgumentException ex) {
+// // expected
+// }
+// try {
+// buffer = BufferUtils.predicatedBuffer(null, predicate);
+// fail("Expecting IllegalArgumentException for null buffer.");
+// } catch (final IllegalArgumentException ex) {
+// // expected
+// }
}
}
diff --git a/src/test/java/org/apache/commons/collections/buffer/PredicatedBufferTest.java b/src/test/java/org/apache/commons/collections/buffer/PredicatedBufferTest.java
index 7738db5b4..949a1f808 100644
--- a/src/test/java/org/apache/commons/collections/buffer/PredicatedBufferTest.java
+++ b/src/test/java/org/apache/commons/collections/buffer/PredicatedBufferTest.java
@@ -17,12 +17,13 @@
package org.apache.commons.collections.buffer;
import java.util.Collection;
+import java.util.EmptyStackException;
-import org.apache.commons.collections.ArrayStack;
import org.apache.commons.collections.Buffer;
import org.apache.commons.collections.BufferUnderflowException;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.collection.PredicatedCollectionTest;
+import org.apache.commons.collections.ArrayStack;
/**
* Extension of {@link PredicatedCollectionTest} for exercising the
@@ -45,7 +46,7 @@ public class PredicatedBufferTest extends PredicatedCollectionTest {
@Override
public Buffer makeObject() {
- return decorateCollection(new ArrayStack(), truePredicate);
+ return decorateCollection(new LifoStackAsBuffer(), truePredicate);
}
@Override
@@ -63,7 +64,7 @@ public class PredicatedBufferTest extends PredicatedCollectionTest {
//------------------------------------------------------------
public Buffer makeTestBuffer() {
- return decorateCollection(new ArrayStack(), testPredicate);
+ return decorateCollection(new LifoStackAsBuffer(), testPredicate);
}
@SuppressWarnings("unchecked")
@@ -105,5 +106,25 @@ public class PredicatedBufferTest extends PredicatedCollectionTest {
// resetFull();
// writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/PredicatedBuffer.fullCollection.version3.1.obj");
// }
+
+ private static class LifoStackAsBuffer extends ArrayStack implements Buffer {
+
+ public E get() {
+ try {
+ return peek();
+ } catch (EmptyStackException e) {
+ throw new BufferUnderflowException();
+ }
+ }
+
+ public E remove() {
+ try {
+ return pop();
+ } catch (EmptyStackException e) {
+ throw new BufferUnderflowException();
+ }
+ }
+
+ }
}
diff --git a/src/test/java/org/apache/commons/collections/buffer/TransformedBufferTest.java b/src/test/java/org/apache/commons/collections/buffer/TransformedBufferTest.java
index be8da9309..b3b4e0289 100644
--- a/src/test/java/org/apache/commons/collections/buffer/TransformedBufferTest.java
+++ b/src/test/java/org/apache/commons/collections/buffer/TransformedBufferTest.java
@@ -17,7 +17,6 @@
package org.apache.commons.collections.buffer;
import junit.framework.TestCase;
-import org.apache.commons.collections.ArrayStack;
import org.apache.commons.collections.Buffer;
import org.apache.commons.collections.collection.TransformedCollectionTest;
@@ -35,7 +34,7 @@ public class TransformedBufferTest extends TestCase {
}
public void testTransformedBuffer() {
- final Buffer buffer = TransformedBuffer.transformingBuffer(new ArrayStack(), TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
+ final Buffer buffer = TransformedBuffer.transformingBuffer(new CircularFifoBuffer(), TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, buffer.size());
final Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" };
for (int i = 0; i < els.length; i++) {
@@ -51,7 +50,7 @@ public class TransformedBufferTest extends TestCase {
}
public void testTransformedBuffer_decorateTransform() {
- final Buffer originalBuffer = new ArrayStack();
+ final Buffer originalBuffer = new CircularFifoBuffer();
final Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (final Object el : els) {
originalBuffer.add(el);
diff --git a/src/test/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollectionTest.java b/src/test/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollectionTest.java
index 29f14bdcf..ca150a44e 100644
--- a/src/test/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollectionTest.java
+++ b/src/test/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollectionTest.java
@@ -20,10 +20,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import org.apache.commons.collections.ArrayStack;
-import org.apache.commons.collections.Buffer;
-import org.apache.commons.collections.BufferUtils;
-import org.apache.commons.collections.buffer.BoundedBuffer;
+import org.apache.commons.collections.BoundedCollection;
+import org.apache.commons.collections.list.FixedSizeList;
/**
* Extension of {@link AbstractCollectionTest} for exercising the
@@ -40,16 +38,15 @@ public class UnmodifiableBoundedCollectionTest extends AbstractCollectionTest
//-----------------------------------------------------------------------
@Override
public Collection makeObject() {
- final BoundedBuffer buffer = BoundedBuffer.boundedBuffer(new ArrayStack(), 10);
- return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(buffer);
+ final BoundedCollection coll = FixedSizeList.fixedSizeList(new ArrayList());
+ return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll);
}
@Override
public Collection makeFullCollection() {
final E[] allElements = getFullElements();
- final Buffer buffer = BufferUtils.boundedBuffer(new ArrayStack(), allElements.length);
- buffer.addAll(Arrays.asList(allElements));
- return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(buffer);
+ final BoundedCollection coll = FixedSizeList.fixedSizeList(new ArrayList(Arrays.asList(allElements)));
+ return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll);
}
@Override