commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1468579 - in /commons/proper/collections/trunk/src: main/java/org/apache/commons/collections/ main/java/org/apache/commons/collections/iterators/ test/java/org/apache/commons/collections/ test/java/org/apache/commons/collections/buffer/ te...
Date Tue, 16 Apr 2013 19:55:21 GMT
Author: tn
Date: Tue Apr 16 19:55:20 2013
New Revision: 1468579

URL: http://svn.apache.org/r1468579
Log:
[COLLECTION-432] Remove Buffer interface from ArrayStack.

Modified:
    commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/ArrayStack.java
    commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/BufferUtils.java
    commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/BufferUtilsTest.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/PredicatedBufferTest.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/TransformedBufferTest.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollectionTest.java

Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/ArrayStack.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/ArrayStack.java?rev=1468579&r1=1468578&r2=1468579&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/ArrayStack.java
(original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/ArrayStack.java
Tue Apr 16 19:55:20 2013
@@ -29,10 +29,12 @@ import java.util.EmptyStackException;
  * The removal order of an <code>ArrayStack</code> is based on insertion 
  * order: The most recently added element is removed first.  The iteration
  * order is <i>not</i> 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.
  * <p>
  * Unlike <code>Stack</code>, <code>ArrayStack</code> accepts null
entries.
+ * <p>
+ * <b>Note:</b> 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<E> extends ArrayList<E> implements Buffer<E> {
+public class ArrayStack<E> extends ArrayList<E> {
 
     /** Ensure serialization compatibility */    
     private static final long serialVersionUID = 2130079159931574599L;
@@ -162,32 +164,4 @@ public class ArrayStack<E> extends Array
         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);
-    }
-
 }

Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/BufferUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/BufferUtils.java?rev=1468579&r1=1468578&r2=1468579&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/BufferUtils.java
(original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/BufferUtils.java
Tue Apr 16 19:55:20 2013
@@ -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<Object> EMPTY_BUFFER = UnmodifiableBuffer.unmodifiableBuffer(new
ArrayStack<Object>(1));
+    public static final Buffer<Object> EMPTY_BUFFER = UnmodifiableBuffer.unmodifiableBuffer(new
CircularFifoBuffer<Object>(1));
 
     /**
      * <code>BufferUtils</code> should not normally be instantiated.

Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java?rev=1468579&r1=1468578&r2=1468579&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java
(original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java
Tue Apr 16 19:55:20 2013
@@ -19,8 +19,8 @@ package org.apache.commons.collections.i
 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.Tr
  * @since 3.1
  * @version $Id$
  */
+@SuppressWarnings("deprecation") // we use the deprecated ArrayStack - change to ArrayDeque
(Java 1.6)
 public class ObjectGraphIterator<E> implements Iterator<E> {
 
     /** The stack of iterators */

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/BufferUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/BufferUtilsTest.java?rev=1468579&r1=1468578&r2=1468579&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/BufferUtilsTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/BufferUtilsTest.java
Tue Apr 16 19:55:20 2013
@@ -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 Bul
     }
 
     public void testpredicatedBuffer() {
-        final Predicate<Object> predicate = new Predicate<Object>() {
-            public boolean evaluate(final Object o) {
-                return o instanceof String;
-            }
-        };
-        Buffer<Object> buffer = BufferUtils.predicatedBuffer(new ArrayStack<Object>(),
predicate);
-        assertTrue("returned object should be a PredicatedBuffer",
-            buffer instanceof PredicatedBuffer);
-        try {
-            buffer = BufferUtils.predicatedBuffer(new ArrayStack<Object>(), 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<Object> predicate = new Predicate<Object>() {
+//            public boolean evaluate(final Object o) {
+//                return o instanceof String;
+//            }
+//        };
+//        Buffer<Object> buffer = BufferUtils.predicatedBuffer(new ArrayStack<Object>(),
predicate);
+//        assertTrue("returned object should be a PredicatedBuffer",
+//            buffer instanceof PredicatedBuffer);
+//        try {
+//            buffer = BufferUtils.predicatedBuffer(new ArrayStack<Object>(), 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
+//        }
     }
 
 }

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/PredicatedBufferTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/PredicatedBufferTest.java?rev=1468579&r1=1468578&r2=1468579&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/PredicatedBufferTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/PredicatedBufferTest.java
Tue Apr 16 19:55:20 2013
@@ -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<E> ext
 
     @Override
     public Buffer<E> makeObject() {
-        return decorateCollection(new ArrayStack<E>(), truePredicate);
+        return decorateCollection(new LifoStackAsBuffer<E>(), truePredicate);
     }
 
     @Override
@@ -63,7 +64,7 @@ public class PredicatedBufferTest<E> ext
     //------------------------------------------------------------
 
     public Buffer<E> makeTestBuffer() {
-        return decorateCollection(new ArrayStack<E>(), testPredicate);
+        return decorateCollection(new LifoStackAsBuffer<E>(), testPredicate);
     }
 
     @SuppressWarnings("unchecked")
@@ -105,5 +106,25 @@ public class PredicatedBufferTest<E> ext
 //        resetFull();
 //        writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/PredicatedBuffer.fullCollection.version3.1.obj");
 //    }
+    
+    private static class LifoStackAsBuffer<E> extends ArrayStack<E> implements
Buffer<E> {
+
+        public E get() {
+            try {
+                return peek();
+            } catch (EmptyStackException e) {
+                throw new BufferUnderflowException();
+            }
+        }
+
+        public E remove() {
+            try {
+                return pop();
+            } catch (EmptyStackException e) {
+                throw new BufferUnderflowException();
+            }
+        }
+        
+    }
 
 }

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/TransformedBufferTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/TransformedBufferTest.java?rev=1468579&r1=1468578&r2=1468579&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/TransformedBufferTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/TransformedBufferTest.java
Tue Apr 16 19:55:20 2013
@@ -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 exten
     }
 
     public void testTransformedBuffer() {
-        final Buffer<Object> buffer = TransformedBuffer.transformingBuffer(new ArrayStack<Object>(),
TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
+        final Buffer<Object> buffer = TransformedBuffer.transformingBuffer(new CircularFifoBuffer<Object>(),
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 exten
     }
 
     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);

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollectionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollectionTest.java?rev=1468579&r1=1468578&r2=1468579&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollectionTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollectionTest.java
Tue Apr 16 19:55:20 2013
@@ -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 UnmodifiableBoundedCollecti
     //-----------------------------------------------------------------------
     @Override
     public Collection<E> makeObject() {
-        final BoundedBuffer<E> buffer = BoundedBuffer.<E>boundedBuffer(new ArrayStack<E>(),
10);
-        return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(buffer);
+        final BoundedCollection<E> coll = FixedSizeList.<E>fixedSizeList(new
ArrayList<E>());
+        return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll);
     }
 
     @Override
     public Collection<E> makeFullCollection() {
         final E[] allElements = getFullElements();
-        final Buffer<E> buffer = BufferUtils.boundedBuffer(new ArrayStack<E>(),
allElements.length);
-        buffer.addAll(Arrays.asList(allElements));
-        return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(buffer);
+        final BoundedCollection<E> coll = FixedSizeList.<E>fixedSizeList(new
ArrayList<E>(Arrays.asList(allElements)));
+        return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll);
     }
 
     @Override



Mime
View raw message