You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2013/03/17 18:50:16 UTC
svn commit: r1457501 - in /commons/proper/collections/trunk/src:
main/java/org/apache/commons/collections/
main/java/org/apache/commons/collections/queue/
test/java/org/apache/commons/collections/queue/ test/resources/data/test/
Author: tn
Date: Sun Mar 17 17:50:15 2013
New Revision: 1457501
URL: http://svn.apache.org/r1457501
Log:
[COLLECTIONS-432] Add queue decorators.
Added:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/QueueUtils.java
- copied, changed from r1457416, commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/BufferUtils.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/
- copied from r1457416, commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/AbstractQueueDecorator.java
- copied, changed from r1457416, commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/AbstractBufferDecorator.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/PredicatedQueue.java
- copied, changed from r1457416, commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/PredicatedBuffer.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/TransformedQueue.java
- copied, changed from r1457416, commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/TransformedBuffer.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/UnmodifiableQueue.java
- copied, changed from r1457416, commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/UnmodifiableBuffer.java
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/
- copied from r1457416, commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/PredicatedQueueTest.java
- copied, changed from r1457416, 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/queue/TransformedQueueTest.java
- copied, changed from r1457416, 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/queue/UnmodifiableQueueTest.java
- copied, changed from r1457416, commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/UnmodifiableBufferTest.java
commons/proper/collections/trunk/src/test/resources/data/test/PredicatedQueue.emptyCollection.version4.obj (with props)
commons/proper/collections/trunk/src/test/resources/data/test/PredicatedQueue.fullCollection.version4.obj (with props)
commons/proper/collections/trunk/src/test/resources/data/test/TransformedQueue.emptyCollection.version4.obj (with props)
commons/proper/collections/trunk/src/test/resources/data/test/TransformedQueue.fullCollection.version4.obj (with props)
commons/proper/collections/trunk/src/test/resources/data/test/UnmodifiableQueue.emptyCollection.version4.obj (with props)
commons/proper/collections/trunk/src/test/resources/data/test/UnmodifiableQueue.fullCollection.version4.obj (with props)
Removed:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/AbstractBufferDecorator.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/BlockingBuffer.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/BoundedBuffer.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/BoundedFifoBuffer.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/CircularFifoBuffer.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/PredicatedBuffer.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/PriorityBuffer.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/SynchronizedBuffer.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/TransformedBuffer.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/UnboundedFifoBuffer.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/UnmodifiableBuffer.java
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/BlockingBufferTest.java
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/BoundedBufferTest.java
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/BoundedFifoBuffer2Test.java
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/BoundedFifoBufferTest.java
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/CircularFifoBufferTest.java
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/PredicatedBufferTest.java
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/PriorityBufferTest.java
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/SynchronizedBufferTest.java
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/TransformedBufferTest.java
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/UnboundedFifoBufferTest.java
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/UnmodifiableBufferTest.java
Modified:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/package-info.java
Copied: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/QueueUtils.java (from r1457416, 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/QueueUtils.java?p2=commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/QueueUtils.java&p1=commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/BufferUtils.java&r1=1457416&r2=1457501&rev=1457501&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/QueueUtils.java Sun Mar 17 17:50:15 2013
@@ -16,190 +16,92 @@
*/
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.PredicatedBuffer;
-import org.apache.commons.collections.buffer.SynchronizedBuffer;
-import org.apache.commons.collections.buffer.TransformedBuffer;
-import org.apache.commons.collections.buffer.UnmodifiableBuffer;
+import java.util.LinkedList;
+import java.util.Queue;
+
+import org.apache.commons.collections.queue.PredicatedQueue;
+import org.apache.commons.collections.queue.TransformedQueue;
+import org.apache.commons.collections.queue.UnmodifiableQueue;
/**
- * Provides utility methods and decorators for {@link Buffer} instances.
+ * Provides utility methods and decorators for {@link Queue} instances.
*
- * @since 2.1
+ * @since 4.0
* @version $Id$
*/
-public class BufferUtils {
+public class QueueUtils {
/**
- * An empty unmodifiable buffer.
+ * An empty unmodifiable queue.
*/
- public static final Buffer<Object> EMPTY_BUFFER = UnmodifiableBuffer.unmodifiableBuffer(new ArrayStack<Object>(1));
+ public static final Queue<Object> EMPTY_QUEUE = UnmodifiableQueue.unmodifiableQueue(new LinkedList<Object>());
/**
- * <code>BufferUtils</code> should not normally be instantiated.
+ * <code>QueueUtils</code> should not normally be instantiated.
*/
- public BufferUtils() {
- }
+ private QueueUtils() {}
//-----------------------------------------------------------------------
- /**
- * Returns a synchronized buffer backed by the given buffer.
- * Much like the synchronized collections returned by
- * {@link java.util.Collections}, you must manually synchronize on
- * the returned buffer's iterator to avoid non-deterministic behavior:
- *
- * <pre>
- * Buffer b = BufferUtils.synchronizedBuffer(myBuffer);
- * synchronized (b) {
- * Iterator i = b.iterator();
- * while (i.hasNext()) {
- * process (i.next());
- * }
- * }
- * </pre>
- *
- * @param <E> the type of the elements in the buffer
- * @param buffer the buffer to synchronize, must not be null
- * @return a synchronized buffer backed by that buffer
- * @throws IllegalArgumentException if the Buffer is null
- */
- public static <E> Buffer<E> synchronizedBuffer(final Buffer<E> buffer) {
- return SynchronizedBuffer.synchronizedBuffer(buffer);
- }
-
- /**
- * Returns a synchronized buffer backed by the given buffer that will
- * block on {@link Buffer#get()} and {@link Buffer#remove()} operations.
- * If the buffer is empty, then the {@link Buffer#get()} and
- * {@link Buffer#remove()} operations will block until new elements
- * are added to the buffer, rather than immediately throwing a
- * <code>BufferUnderflowException</code>.
- *
- * @param <E> the type of the elements in the buffer
- * @param buffer the buffer to synchronize, must not be null
- * @return a blocking buffer backed by that buffer
- * @throws IllegalArgumentException if the Buffer is null
- */
- public static <E> Buffer<E> blockingBuffer(final Buffer<E> buffer) {
- return BlockingBuffer.blockingBuffer(buffer);
- }
-
- /**
- * Returns a synchronized buffer backed by the given buffer that will
- * block on {@link Buffer#get()} and {@link Buffer#remove()} operations
- * until <code>timeout</code> expires. If the buffer is empty, then the
- * {@link Buffer#get()} and {@link Buffer#remove()} operations will block
- * until new elements are added to the buffer, rather than immediately
- * throwing a <code>BufferUnderflowException</code>.
- *
- * @param <E> the type of the elements in the buffer
- * @param buffer the buffer to synchronize, must not be null
- * @param timeoutMillis the timeout value in milliseconds, zero or less for no timeout
- * @return a blocking buffer backed by that buffer
- * @throws IllegalArgumentException if the Buffer is null
- * @since 3.2
- */
- public static <E> Buffer<E> blockingBuffer(final Buffer<E> buffer, final long timeoutMillis) {
- return BlockingBuffer.blockingBuffer(buffer, timeoutMillis);
- }
-
- /**
- * Returns a synchronized buffer backed by the given buffer that will
- * block on {@link Buffer#add(Object)} and
- * {@link Buffer#addAll(java.util.Collection)} until enough object(s) are
- * removed from the buffer to allow the object(s) to be added and still
- * maintain the maximum size.
- *
- * @param <E> the type of the elements in the buffer
- * @param buffer the buffer to make bounded, must not be null
- * @param maximumSize the maximum size
- * @return a bounded buffer backed by the given buffer
- * @throws IllegalArgumentException if the given buffer is null
- * @since 3.2
- */
- public static <E> Buffer<E> boundedBuffer(final Buffer<E> buffer, final int maximumSize) {
- return BoundedBuffer.boundedBuffer(buffer, maximumSize);
- }
/**
- * Returns a synchronized buffer backed by the given buffer that will
- * block on {@link Buffer#add(Object)} and
- * {@link Buffer#addAll(java.util.Collection)} until enough object(s) are
- * removed from the buffer to allow the object(s) to be added and still
- * maintain the maximum size or the timeout expires.
+ * Returns an unmodifiable queue backed by the given queue.
*
- * @param <E> the type of the elements in the buffer
- * @param buffer the buffer to make bounded, must not be null
- * @param maximumSize the maximum size
- * @param timeoutMillis the timeout value in milliseconds, zero or less for no timeout
- * @return a bounded buffer backed by the given buffer
- * @throws IllegalArgumentException if the given buffer is null
- * @since 3.2
+ * @param <E> the type of the elements in the queue
+ * @param queue the queue to make unmodifiable, must not be null
+ * @return an unmodifiable queue backed by that queue
+ * @throws IllegalArgumentException if the Queue is null
*/
- public static <E> Buffer<E> boundedBuffer(final Buffer<E> buffer, final int maximumSize, final long timeoutMillis) {
- return BoundedBuffer.boundedBuffer(buffer, maximumSize, timeoutMillis);
+ public static <E> Queue<E> unmodifiableQueue(final Queue<E> queue) {
+ return UnmodifiableQueue.unmodifiableQueue(queue);
}
/**
- * Returns an unmodifiable buffer backed by the given buffer.
- *
- * @param <E> the type of the elements in the buffer
- * @param buffer the buffer to make unmodifiable, must not be null
- * @return an unmodifiable buffer backed by that buffer
- * @throws IllegalArgumentException if the Buffer is null
- */
- public static <E> Buffer<E> unmodifiableBuffer(final Buffer<E> buffer) {
- return UnmodifiableBuffer.unmodifiableBuffer(buffer);
- }
-
- /**
- * Returns a predicated (validating) buffer backed by the given buffer.
+ * Returns a predicated (validating) queue backed by the given queue.
* <p>
- * Only objects that pass the test in the given predicate can be added to the buffer.
+ * Only objects that pass the test in the given predicate can be added to the queue.
* Trying to add an invalid object results in an IllegalArgumentException.
- * It is important not to use the original buffer after invoking this method,
+ * It is important not to use the original queue after invoking this method,
* as it is a backdoor for adding invalid objects.
*
- * @param <E> the type of the elements in the buffer
- * @param buffer the buffer to predicate, must not be null
+ * @param <E> the type of the elements in the queue
+ * @param queue the queue to predicate, must not be null
* @param predicate the predicate used to evaluate new elements, must not be null
- * @return a predicated buffer
- * @throws IllegalArgumentException if the Buffer or Predicate is null
+ * @return a predicated queue
+ * @throws IllegalArgumentException if the Queue or Predicate is null
*/
- public static <E> Buffer<E> predicatedBuffer(final Buffer<E> buffer, final Predicate<? super E> predicate) {
- return PredicatedBuffer.predicatedBuffer(buffer, predicate);
+ public static <E> Queue<E> predicatedQueue(final Queue<E> queue, final Predicate<? super E> predicate) {
+ return PredicatedQueue.predicatedQueue(queue, predicate);
}
/**
- * Returns a transformed buffer backed by the given buffer.
+ * Returns a transformed queue backed by the given queue.
* <p>
* Each object is passed through the transformer as it is added to the
- * Buffer. It is important not to use the original buffer after invoking this
+ * Queue. It is important not to use the original queue after invoking this
* method, as it is a backdoor for adding untransformed objects.
* <p>
- * Existing entries in the specified buffer will not be transformed.
- * If you want that behaviour, see {@link TransformedBuffer#transformedBuffer}.
+ * Existing entries in the specified queue will not be transformed.
+ * If you want that behaviour, see {@link TransformedQueue#transformedQueue}.
*
- * @param <E> the type of the elements in the buffer
- * @param buffer the buffer to predicate, must not be null
- * @param transformer the transformer for the buffer, must not be null
- * @return a transformed buffer backed by the given buffer
- * @throws IllegalArgumentException if the Buffer or Transformer is null
- */
- public static <E> Buffer<E> transformingBuffer(final Buffer<E> buffer,
- final Transformer<? super E, ? extends E> transformer) {
- return TransformedBuffer.transformingBuffer(buffer, transformer);
+ * @param <E> the type of the elements in the queue
+ * @param queue the queue to predicate, must not be null
+ * @param transformer the transformer for the queue, must not be null
+ * @return a transformed queue backed by the given queue
+ * @throws IllegalArgumentException if the Queue or Transformer is null
+ */
+ public static <E> Queue<E> transformingQueue(final Queue<E> queue,
+ final Transformer<? super E, ? extends E> transformer) {
+ return TransformedQueue.transformingQueue(queue, transformer);
}
/**
- * Get an empty <code>Buffer</code>.
+ * Get an empty <code>Queue</code>.
*
- * @param <E> the type of the elements in the buffer
- * @return an empty {@link Buffer}
+ * @param <E> the type of the elements in the queue
+ * @return an empty {@link Queue}
*/
- @SuppressWarnings("unchecked") // OK, empty buffer is compatible with any type
- public static <E> Buffer<E> emptyBuffer() {
- return (Buffer<E>) EMPTY_BUFFER;
+ @SuppressWarnings("unchecked") // OK, empty queue is compatible with any type
+ public static <E> Queue<E> emptyQueue() {
+ return (Queue<E>) EMPTY_QUEUE;
}
}
Copied: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/AbstractQueueDecorator.java (from r1457416, commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/AbstractBufferDecorator.java)
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/AbstractQueueDecorator.java?p2=commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/AbstractQueueDecorator.java&p1=commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/AbstractBufferDecorator.java&r1=1457416&r2=1457501&rev=1457501&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/AbstractBufferDecorator.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/AbstractQueueDecorator.java Sun Mar 17 17:50:15 2013
@@ -14,60 +14,72 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.collections.buffer;
+package org.apache.commons.collections.queue;
+
+import java.util.Queue;
-import org.apache.commons.collections.Buffer;
import org.apache.commons.collections.collection.AbstractCollectionDecorator;
/**
- * Decorates another {@link Buffer} to provide additional behaviour.
+ * Decorates another {@link Queue} to provide additional behaviour.
* <p>
- * Methods are forwarded directly to the decorated buffer.
+ * Methods are forwarded directly to the decorated queue.
*
- * @param <E> the type of the elements in the buffer
- * @since 3.0
+ * @param <E> the type of the elements in the queue
+ * @since 4.0
* @version $Id$
*/
-public abstract class AbstractBufferDecorator<E> extends AbstractCollectionDecorator<E>
- implements Buffer<E> {
+public abstract class AbstractQueueDecorator<E> extends AbstractCollectionDecorator<E>
+ implements Queue<E> {
/** Serialization version */
private static final long serialVersionUID = -2629815475789577029L;
/**
* Constructor only used in deserialization, do not use otherwise.
- * @since 3.1
*/
- protected AbstractBufferDecorator() {
+ protected AbstractQueueDecorator() {
super();
}
/**
* Constructor that wraps (not copies).
*
- * @param buffer the buffer to decorate, must not be null
+ * @param queue the queue to decorate, must not be null
* @throws IllegalArgumentException if list is null
*/
- protected AbstractBufferDecorator(final Buffer<E> buffer) {
- super(buffer);
+ protected AbstractQueueDecorator(final Queue<E> queue) {
+ super(queue);
}
/**
- * Gets the buffer being decorated.
+ * Gets the queue being decorated.
*
- * @return the decorated buffer
+ * @return the decorated queue
*/
@Override
- protected Buffer<E> decorated() {
- return (Buffer<E>) super.decorated();
+ protected Queue<E> decorated() {
+ return (Queue<E>) super.decorated();
}
//-----------------------------------------------------------------------
-
- public E get() {
- return decorated().get();
+
+ public boolean offer(E obj) {
+ return decorated().offer(obj);
+ }
+
+ public E poll() {
+ return decorated().poll();
}
+ public E peek() {
+ return decorated().peek();
+ }
+
+ public E element() {
+ return decorated().element();
+ }
+
public E remove() {
return decorated().remove();
}
Copied: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/PredicatedQueue.java (from r1457416, commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/PredicatedBuffer.java)
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/PredicatedQueue.java?p2=commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/PredicatedQueue.java&p1=commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/PredicatedBuffer.java&r1=1457416&r2=1457501&rev=1457501&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/PredicatedBuffer.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/PredicatedQueue.java Sun Mar 17 17:50:15 2013
@@ -14,49 +14,48 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.collections.buffer;
+package org.apache.commons.collections.queue;
+
+import java.util.Queue;
-import org.apache.commons.collections.Buffer;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.collection.PredicatedCollection;
/**
- * Decorates another {@link Buffer} to validate that additions
+ * Decorates another {@link Queue} to validate that additions
* match a specified predicate.
* <p>
- * This buffer exists to provide validation for the decorated buffer.
- * It is normally created to decorate an empty buffer.
- * If an object cannot be added to the buffer, an IllegalArgumentException is thrown.
- * <p>
- * One usage would be to ensure that no null entries are added to the buffer.
- * <pre>Buffer buffer = PredicatedBuffer.decorate(new UnboundedFifoBuffer(), NotNullPredicate.INSTANCE);</pre>
+ * This queue exists to provide validation for the decorated queue.
+ * It is normally created to decorate an empty queue.
+ * If an object cannot be added to the queue, an IllegalArgumentException is thrown.
* <p>
- * This class is Serializable from Commons Collections 3.1.
+ * One usage would be to ensure that no null entries are added to the queue.
+ * <pre>Queue queue = PredicatedQueue.predicatedQueue(new UnboundedFifoQueue(), NotNullPredicate.INSTANCE);</pre>
*
- * @since 3.0
+ * @since 4.0
* @version $Id$
*/
-public class PredicatedBuffer<E> extends PredicatedCollection<E> implements Buffer<E> {
+public class PredicatedQueue<E> extends PredicatedCollection<E> implements Queue<E> {
/** Serialization version */
private static final long serialVersionUID = 2307609000539943581L;
/**
- * Factory method to create a predicated (validating) buffer.
+ * Factory method to create a predicated (validating) queue.
* <p>
- * If there are any elements already in the buffer being decorated, they
+ * If there are any elements already in the queue being decorated, they
* are validated.
*
- * @param <E> the type of the elements in the buffer
- * @param buffer the buffer to decorate, must not be null
+ * @param <E> the type of the elements in the queue
+ * @param Queue the queue to decorate, must not be null
* @param predicate the predicate to use for validation, must not be null
- * @return a new predicated Buffer
- * @throws IllegalArgumentException if buffer or predicate is null
- * @throws IllegalArgumentException if the buffer contains invalid elements
+ * @return a new predicated queue
+ * @throws IllegalArgumentException if queue or predicate is null
+ * @throws IllegalArgumentException if the queue contains invalid elements
*/
- public static <E> PredicatedBuffer<E> predicatedBuffer(final Buffer<E> buffer,
- final Predicate<? super E> predicate) {
- return new PredicatedBuffer<E>(buffer, predicate);
+ public static <E> PredicatedQueue<E> predicatedQueue(final Queue<E> Queue,
+ final Predicate<? super E> predicate) {
+ return new PredicatedQueue<E>(Queue, predicate);
}
//-----------------------------------------------------------------------
@@ -66,29 +65,50 @@ public class PredicatedBuffer<E> extends
* If there are any elements already in the collection being decorated, they
* are validated.
*
- * @param buffer the buffer to decorate, must not be null
+ * @param queue the queue to decorate, must not be null
* @param predicate the predicate to use for validation, must not be null
- * @throws IllegalArgumentException if buffer or predicate is null
- * @throws IllegalArgumentException if the buffer contains invalid elements
+ * @throws IllegalArgumentException if Queue or predicate is null
+ * @throws IllegalArgumentException if the Queue contains invalid elements
*/
- protected PredicatedBuffer(final Buffer<E> buffer, final Predicate<? super E> predicate) {
- super(buffer, predicate);
+ protected PredicatedQueue(final Queue<E> queue, final Predicate<? super E> predicate) {
+ super(queue, predicate);
}
/**
- * Gets the buffer being decorated.
+ * Gets the queue being decorated.
*
- * @return the decorated buffer
+ * @return the decorated queue
*/
@Override
- protected Buffer<E> decorated() {
- return (Buffer<E>) super.decorated();
+ protected Queue<E> decorated() {
+ return (Queue<E>) super.decorated();
}
//-----------------------------------------------------------------------
- public E get() {
- return decorated().get();
+ /**
+ * Override to validate the object being added to ensure it matches
+ * the predicate.
+ *
+ * @param object the object being added
+ * @return the result of adding to the underlying queue
+ * @throws IllegalArgumentException if the add is invalid
+ */
+ public boolean offer(E object) {
+ validate(object);
+ return decorated().offer(object);
+ }
+
+ public E poll() {
+ return decorated().poll();
+ }
+
+ public E peek() {
+ return decorated().peek();
+ }
+
+ public E element() {
+ return decorated().element();
}
public E remove() {
Copied: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/TransformedQueue.java (from r1457416, commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/TransformedBuffer.java)
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/TransformedQueue.java?p2=commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/TransformedQueue.java&p1=commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/TransformedBuffer.java&r1=1457416&r2=1457501&rev=1457501&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/TransformedBuffer.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/TransformedQueue.java Sun Mar 17 17:50:15 2013
@@ -14,71 +14,70 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.collections.buffer;
+package org.apache.commons.collections.queue;
+
+import java.util.Queue;
-import org.apache.commons.collections.Buffer;
import org.apache.commons.collections.Transformer;
import org.apache.commons.collections.collection.TransformedCollection;
/**
- * Decorates another {@link Buffer} to transform objects that are added.
+ * Decorates another {@link Queue} to transform objects that are added.
* <p>
- * The add methods are affected by this class.
+ * The add/offer methods are affected by this class.
* Thus objects must be removed or searched for using their transformed form.
* For example, if the transformation converts Strings to Integers, you must
* use the Integer form to remove objects.
- * <p>
- * This class is Serializable from Commons Collections 3.1.
*
- * @since 3.0
+ * @since 4.0
* @version $Id$
*/
-public class TransformedBuffer<E> extends TransformedCollection<E> implements Buffer<E> {
+public class TransformedQueue<E> extends TransformedCollection<E> implements Queue<E> {
/** Serialization version */
private static final long serialVersionUID = -7901091318986132033L;
/**
- * Factory method to create a transforming buffer.
+ * Factory method to create a transforming queue.
* <p>
- * If there are any elements already in the buffer being decorated, they
+ * If there are any elements already in the queue being decorated, they
* are NOT transformed.
- * Contrast this with {@link #transformedBuffer(Buffer, Transformer)}.
+ * Contrast this with {@link #transformedQueue(Queue, Transformer)}.
*
- * @param <E> the type of the elements in the buffer
- * @param buffer the buffer to decorate, must not be null
+ * @param <E> the type of the elements in the queue
+ * @param queue the queue to decorate, must not be null
* @param transformer the transformer to use for conversion, must not be null
- * @return a new transformed Buffer
- * @throws IllegalArgumentException if buffer or transformer is null
+ * @return a new transformed Queue
+ * @throws IllegalArgumentException if queue or transformer is null
*/
- public static <E> TransformedBuffer<E> transformingBuffer(final Buffer<E> buffer,
- final Transformer<? super E, ? extends E> transformer) {
- return new TransformedBuffer<E>(buffer, transformer);
+ public static <E> TransformedQueue<E> transformingQueue(final Queue<E> queue,
+ final Transformer<? super E, ? extends E> transformer) {
+ return new TransformedQueue<E>(queue, transformer);
}
/**
- * Factory method to create a transforming buffer that will transform
- * existing contents of the specified buffer.
+ * Factory method to create a transforming queue that will transform
+ * existing contents of the specified queue.
* <p>
- * If there are any elements already in the buffer being decorated, they
+ * If there are any elements already in the queue being decorated, they
* will be transformed by this method.
- * Contrast this with {@link #transformingBuffer(Buffer, Transformer)}.
+ * Contrast this with {@link #transformingQueue(Queue, Transformer)}.
*
- * @param <E> the type of the elements in the buffer
- * @param buffer the buffer to decorate, must not be null
+ * @param <E> the type of the elements in the queue
+ * @param queue the queue to decorate, must not be null
* @param transformer the transformer to use for conversion, must not be null
- * @return a new transformed Buffer
- * @throws IllegalArgumentException if buffer or transformer is null
+ * @return a new transformed Queue
+ * @throws IllegalArgumentException if queue or transformer is null
* @since 4.0
*/
- public static <E> TransformedBuffer<E> transformedBuffer(final Buffer<E> buffer,
- final Transformer<? super E, ? extends E> transformer) {
- // throws IAE if buffer or transformer is null
- final TransformedBuffer<E> decorated = new TransformedBuffer<E>(buffer, transformer);
- if (buffer.size() > 0) {
- @SuppressWarnings("unchecked") // buffer is type <E>
- final E[] values = (E[]) buffer.toArray();
- buffer.clear();
+ public static <E> TransformedQueue<E> transformedQueue(final Queue<E> queue,
+ final Transformer<? super E, ? extends E> transformer) {
+ // throws IAE if queue or transformer is null
+ final TransformedQueue<E> decorated = new TransformedQueue<E>(queue, transformer);
+ if (queue.size() > 0) {
+ @SuppressWarnings("unchecked") // queue is type <E>
+ final E[] values = (E[]) queue.toArray();
+ queue.clear();
for (final E value : values) {
decorated.decorated().add(transformer.transform(value));
}
@@ -90,34 +89,46 @@ public class TransformedBuffer<E> extend
/**
* Constructor that wraps (not copies).
* <p>
- * If there are any elements already in the buffer being decorated, they
+ * If there are any elements already in the queue being decorated, they
* are NOT transformed.
*
- * @param buffer the buffer to decorate, must not be null
+ * @param queue the queue to decorate, must not be null
* @param transformer the transformer to use for conversion, must not be null
- * @throws IllegalArgumentException if buffer or transformer is null
+ * @throws IllegalArgumentException if queue or transformer is null
*/
- protected TransformedBuffer(final Buffer<E> buffer, final Transformer<? super E, ? extends E> transformer) {
- super(buffer, transformer);
+ protected TransformedQueue(final Queue<E> queue, final Transformer<? super E, ? extends E> transformer) {
+ super(queue, transformer);
}
/**
- * Gets the decorated buffer.
+ * Gets the decorated queue.
*
- * @return the decorated buffer
+ * @return the decorated queue
*/
- protected Buffer<E> getBuffer() {
- return (Buffer<E>) collection;
+ protected Queue<E> getQueue() {
+ return (Queue<E>) collection;
}
//-----------------------------------------------------------------------
-
- public E get() {
- return getBuffer().get();
+
+ public boolean offer(E obj) {
+ return getQueue().offer(transform(obj));
+ }
+
+ public E poll() {
+ return getQueue().poll();
+ }
+
+ public E peek() {
+ return getQueue().peek();
}
+ public E element() {
+ return getQueue().element();
+ }
+
public E remove() {
- return getBuffer().remove();
+ return getQueue().remove();
}
}
Copied: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/UnmodifiableQueue.java (from r1457416, commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/UnmodifiableBuffer.java)
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/UnmodifiableQueue.java?p2=commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/UnmodifiableQueue.java&p1=commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/UnmodifiableBuffer.java&r1=1457416&r2=1457501&rev=1457501&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/buffer/UnmodifiableBuffer.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/UnmodifiableQueue.java Sun Mar 17 17:50:15 2013
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.collections.buffer;
+package org.apache.commons.collections.queue;
import java.io.IOException;
import java.io.ObjectInputStream;
@@ -22,54 +22,52 @@ import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
+import java.util.Queue;
-import org.apache.commons.collections.Buffer;
import org.apache.commons.collections.Unmodifiable;
import org.apache.commons.collections.iterators.UnmodifiableIterator;
/**
- * Decorates another {@link Buffer} to ensure it can't be altered.
- * <p>
- * This class is Serializable from Commons Collections 3.1.
+ * Decorates another {@link Queue} to ensure it can't be altered.
* <p>
* Attempts to modify it will result in an UnsupportedOperationException.
*
- * @since 3.0
+ * @since 4.0
* @version $Id$
*/
-public final class UnmodifiableBuffer<E>
- extends AbstractBufferDecorator<E>
+public final class UnmodifiableQueue<E>
+ extends AbstractQueueDecorator<E>
implements Unmodifiable, Serializable {
/** Serialization version */
private static final long serialVersionUID = 1832948656215393357L;
/**
- * Factory method to create an unmodifiable buffer.
+ * Factory method to create an unmodifiable queue.
* <p>
- * If the buffer passed in is already unmodifiable, it is returned.
+ * If the queue passed in is already unmodifiable, it is returned.
*
- * @param <E> the type of the elements in the buffer
- * @param buffer the buffer to decorate, must not be null
- * @return an unmodifiable Buffer
- * @throws IllegalArgumentException if buffer is null
+ * @param <E> the type of the elements in the queue
+ * @param queue the queue to decorate, must not be null
+ * @return an unmodifiable Queue
+ * @throws IllegalArgumentException if queue is null
*/
- public static <E> Buffer<E> unmodifiableBuffer(final Buffer<E> buffer) {
- if (buffer instanceof Unmodifiable) {
- return buffer;
+ public static <E> Queue<E> unmodifiableQueue(final Queue<E> queue) {
+ if (queue instanceof Unmodifiable) {
+ return queue;
}
- return new UnmodifiableBuffer<E>(buffer);
+ return new UnmodifiableQueue<E>(queue);
}
//-----------------------------------------------------------------------
/**
* Constructor that wraps (not copies).
*
- * @param buffer the buffer to decorate, must not be null
- * @throws IllegalArgumentException if buffer is null
+ * @param queue the queue to decorate, must not be null
+ * @throws IllegalArgumentException if queue is null
*/
- private UnmodifiableBuffer(final Buffer<E> buffer) {
- super(buffer);
+ private UnmodifiableQueue(final Queue<E> queue) {
+ super(queue);
}
//-----------------------------------------------------------------------
@@ -134,9 +132,20 @@ public final class UnmodifiableBuffer<E>
}
//-----------------------------------------------------------------------
+
@Override
- public E remove() {
+ public boolean offer(E obj) {
throw new UnsupportedOperationException();
}
+ @Override
+ public E poll() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public E remove() {
+ throw new UnsupportedOperationException();
+ }
+
}
Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/package-info.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/package-info.java?rev=1457501&r1=1457416&r2=1457501&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/package-info.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/queue/package-info.java Sun Mar 17 17:50:15 2013
@@ -15,26 +15,15 @@
* limitations under the License.
*/
/**
- * This package contains implementations of the
- * {@link org.apache.commons.collections.Buffer Buffer} interface.
- * <p>
- * The following implementations are provided in the package:
- * <ul>
- * <li>PriorityBuffer - provides for removal based on a comparator ordering
- * <li>BoundedFifoBuffer - implements a buffer with a fixed size that throws exceptions when full
- * <li>CircularFifoBuffer - implements a buffer with a fixed size that discards oldest when full
- * <li>UnboundedFifoBuffer - implements a buffer that grows in size if necessary
- * </ul>
+ * This package contains decorators for the {@link java.util.Queue Queue} interface.
* <p>
* The following decorators are provided in the package:
* <ul>
- * <li>Synchronized - synchronizes method access for multi-threaded environments
- * <li>Unmodifiable - ensures the collection cannot be altered
* <li>Predicated - ensures that only elements that are valid according to a predicate can be added
- * <li>Transformed - transforms elements added to the buffer
- * <li>Blocking - blocks on get and remove until an element is available
+ * <li>Transformed - transforms elements added to the queue
+ * <li>Unmodifiable - ensures the collection cannot be altered
* </ul>
*
* @version $Id$
*/
-package org.apache.commons.collections.buffer;
+package org.apache.commons.collections.queue;
Copied: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/PredicatedQueueTest.java (from r1457416, 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/queue/PredicatedQueueTest.java?p2=commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/PredicatedQueueTest.java&p1=commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/PredicatedBufferTest.java&r1=1457416&r2=1457501&rev=1457501&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/queue/PredicatedQueueTest.java Sun Mar 17 17:50:15 2013
@@ -14,96 +14,96 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.collections.buffer;
+package org.apache.commons.collections.queue;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
-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;
/**
* Extension of {@link PredicatedCollectionTest} for exercising the
- * {@link PredicatedBuffer} implementation.
+ * {@link PredicatedQueue} implementation.
*
- * @since 3.0
+ * @since 4.0
* @version $Id$
*/
-public class PredicatedBufferTest<E> extends PredicatedCollectionTest<E> {
+public class PredicatedQueueTest<E> extends PredicatedCollectionTest<E> {
- public PredicatedBufferTest(final String testName) {
+ public PredicatedQueueTest(final String testName) {
super(testName);
}
//---------------------------------------------------------------
- protected Buffer<E> decorateCollection(final Buffer<E> buffer, final Predicate<E> predicate) {
- return PredicatedBuffer.predicatedBuffer(buffer, predicate);
+ protected Queue<E> decorateCollection(final Queue<E> queue, final Predicate<E> predicate) {
+ return PredicatedQueue.predicatedQueue(queue, predicate);
}
@Override
- public Buffer<E> makeObject() {
- return decorateCollection(new ArrayStack<E>(), truePredicate);
+ public Queue<E> makeObject() {
+ return decorateCollection(new LinkedList<E>(), truePredicate);
+ }
+
+ @Override
+ public Collection<E> makeFullCollection() {
+ final Queue<E> queue = new LinkedList<E>();
+ queue.addAll(Arrays.asList(getFullElements()));
+ return decorateCollection(queue, truePredicate);
}
@Override
public Collection<E> makeConfirmedCollection() {
- return new ArrayStack<E>();
+ return new LinkedList<E>();
}
@Override
public Collection<E> makeConfirmedFullCollection() {
- final ArrayStack<E> list = new ArrayStack<E>();
+ final List<E> list = new LinkedList<E>();
list.addAll(java.util.Arrays.asList(getFullElements()));
return list;
}
//------------------------------------------------------------
- public Buffer<E> makeTestBuffer() {
- return decorateCollection(new ArrayStack<E>(), testPredicate);
+ public Queue<E> makeTestQueue() {
+ return decorateCollection(new LinkedList<E>(), testPredicate);
}
@SuppressWarnings("unchecked")
public void testGet() {
- final Buffer<E> buffer = makeTestBuffer();
- try {
- buffer.get();
- fail("Expecting BufferUnderflowException");
- } catch (final BufferUnderflowException ex) {
- // expected
- }
- buffer.add((E) "one");
- buffer.add((E) "two");
- buffer.add((E) "three");
- assertEquals("Buffer get", "three", buffer.get());
+ final Queue<E> queue = makeTestQueue();
+
+ assertNull(queue.peek());
+
+ queue.add((E) "one");
+ queue.add((E) "two");
+ queue.add((E) "three");
+ assertEquals("Queue get", "one", queue.peek());
}
@SuppressWarnings("unchecked")
public void testRemove() {
- final Buffer<E> buffer = makeTestBuffer();
- buffer.add((E) "one");
- assertEquals("Buffer get", "one", buffer.remove());
- try {
- buffer.remove();
- fail("Expecting BufferUnderflowException");
- } catch (final BufferUnderflowException ex) {
- // expected
- }
+ final Queue<E> queue = makeTestQueue();
+ queue.add((E) "one");
+ assertEquals("Queue get", "one", queue.poll());
+ assertNull(queue.peek());
}
@Override
public String getCompatibilityVersion() {
- return "3.1";
+ return "4";
}
// public void testCreate() throws Exception {
// resetEmpty();
-// writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/PredicatedBuffer.emptyCollection.version3.1.obj");
+// writeExternalFormToDisk((java.io.Serializable) getCollection(), "src/test/resources/data/test/PredicatedQueue.emptyCollection.version4.obj");
// resetFull();
-// writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/PredicatedBuffer.fullCollection.version3.1.obj");
+// writeExternalFormToDisk((java.io.Serializable) getCollection(), "src/test/resources/data/test/PredicatedQueue.fullCollection.version4.obj");
// }
}
Copied: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/TransformedQueueTest.java (from r1457416, 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/queue/TransformedQueueTest.java?p2=commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/TransformedQueueTest.java&p1=commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/TransformedBufferTest.java&r1=1457416&r2=1457501&rev=1457501&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/queue/TransformedQueueTest.java Sun Mar 17 17:50:15 2013
@@ -14,60 +14,103 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.collections.buffer;
+package org.apache.commons.collections.queue;
-import junit.framework.TestCase;
-import org.apache.commons.collections.ArrayStack;
-import org.apache.commons.collections.Buffer;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.Queue;
+
+import org.apache.commons.collections.Transformer;
+import org.apache.commons.collections.collection.AbstractCollectionTest;
import org.apache.commons.collections.collection.TransformedCollectionTest;
/**
- * Extension of {@link TestCase} for exercising the {@link TransformedBuffer}
- * implementation.
+ * Extension of {@link AbstractCollectionTest} for exercising the
+ * {@link TransformedQueue} implementation.
*
- * @since 3.0
+ * @since 4.0
* @version $Id$
*/
-public class TransformedBufferTest extends TestCase {
+public class TransformedQueueTest<E> extends AbstractCollectionTest<E> {
- public TransformedBufferTest(final String testName) {
+ public TransformedQueueTest(final String testName) {
super(testName);
}
- public void testTransformedBuffer() {
- final Buffer<Object> buffer = TransformedBuffer.transformingBuffer(new ArrayStack<Object>(), TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
- assertEquals(0, buffer.size());
+ //-----------------------------------------------------------------------
+ @Override
+ public Queue<E> makeConfirmedCollection() {
+ return new LinkedList<E>();
+ }
+
+ @Override
+ public Queue<E> makeConfirmedFullCollection() {
+ final Queue<E> list = new LinkedList<E>();
+ list.addAll(Arrays.asList(getFullElements()));
+ return list;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Queue<E> makeObject() {
+ return TransformedQueue.transformingQueue(new LinkedList<E>(),
+ (Transformer<E, E>) TransformedCollectionTest.NOOP_TRANSFORMER);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Queue<E> makeFullCollection() {
+ final Queue<E> list = new LinkedList<E>();
+ list.addAll(Arrays.asList(getFullElements()));
+ return TransformedQueue.transformingQueue(list, (Transformer<E, E>) TransformedCollectionTest.NOOP_TRANSFORMER);
+ }
+
+ //-----------------------------------------------------------------------
+ public void testTransformedQueue() {
+ final Queue<Object> queue = TransformedQueue.transformingQueue(new LinkedList<Object>(),
+ TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
+ assertEquals(0, queue.size());
final 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());
- assertEquals(true, buffer.contains(new Integer((String) els[i])));
- assertEquals(false, buffer.contains(els[i]));
+ queue.add(els[i]);
+ assertEquals(i + 1, queue.size());
+ assertEquals(true, queue.contains(new Integer((String) els[i])));
+ assertEquals(false, queue.contains(els[i]));
}
- assertEquals(false, buffer.remove(els[0]));
- assertEquals(true, buffer.remove(new Integer((String) els[0])));
+ assertEquals(false, queue.remove(els[0]));
+ assertEquals(true, queue.remove(new Integer((String) els[0])));
}
- public void testTransformedBuffer_decorateTransform() {
- final Buffer originalBuffer = new ArrayStack();
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public void testTransformedQueue_decorateTransform() {
+ final Queue originalQueue = new LinkedList();
final Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (final Object el : els) {
- originalBuffer.add(el);
+ originalQueue.add(el);
}
- final Buffer<?> buffer = TransformedBuffer.transformedBuffer(originalBuffer, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
- assertEquals(els.length, buffer.size());
+ final Queue<?> queue = TransformedQueue.transformedQueue(originalQueue,
+ TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
+ assertEquals(els.length, queue.size());
for (final Object el : els) {
- assertEquals(true, buffer.contains(new Integer((String) el)));
- assertEquals(false, buffer.contains(el));
+ assertEquals(true, queue.contains(new Integer((String) el)));
+ assertEquals(false, queue.contains(el));
}
- assertEquals(false, buffer.remove(els[0]));
- assertEquals(true, buffer.remove(new Integer((String) els[0])));
+ assertEquals(false, queue.remove(els[0]));
+ assertEquals(true, queue.remove(new Integer((String) els[0])));
}
public String getCompatibilityVersion() {
- return "3.1";
+ return "4";
}
+
+// public void testCreate() throws Exception {
+// resetEmpty();
+// writeExternalFormToDisk((java.io.Serializable) getCollection(), "src/test/resources/data/test/TransformedQueue.emptyCollection.version4.obj");
+// resetFull();
+// writeExternalFormToDisk((java.io.Serializable) getCollection(), "src/test/resources/data/test/TransformedQueue.fullCollection.version4.obj");
+// }
+
}
Copied: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/UnmodifiableQueueTest.java (from r1457416, commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/UnmodifiableBufferTest.java)
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/UnmodifiableQueueTest.java?p2=commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/UnmodifiableQueueTest.java&p1=commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/UnmodifiableBufferTest.java&r1=1457416&r2=1457501&rev=1457501&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/buffer/UnmodifiableBufferTest.java (original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/queue/UnmodifiableQueueTest.java Sun Mar 17 17:50:15 2013
@@ -14,49 +14,49 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.collections.buffer;
+package org.apache.commons.collections.queue;
import java.util.Arrays;
import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Queue;
-import org.apache.commons.collections.ArrayStack;
-import org.apache.commons.collections.Buffer;
import org.apache.commons.collections.collection.AbstractCollectionTest;
/**
* Extension of {@link AbstractCollectionTest} for exercising the
- * {@link UnmodifiableBuffer} implementation.
+ * {@link UnmodifiableQueue} implementation.
*
- * @since 3.1
+ * @since 4.0
* @version $Id$
*/
-public class UnmodifiableBufferTest<E> extends AbstractCollectionTest<E> {
+public class UnmodifiableQueueTest<E> extends AbstractCollectionTest<E> {
- public UnmodifiableBufferTest(final String testName) {
+ public UnmodifiableQueueTest(final String testName) {
super(testName);
}
//-----------------------------------------------------------------------
@Override
public Collection<E> makeObject() {
- return UnmodifiableBuffer.unmodifiableBuffer(new UnboundedFifoBuffer<E>());
+ return UnmodifiableQueue.unmodifiableQueue(new LinkedList<E>());
}
@Override
public Collection<E> makeFullCollection() {
- final Buffer<E> buffer = new UnboundedFifoBuffer<E>();
- buffer.addAll(Arrays.asList(getFullElements()));
- return UnmodifiableBuffer.unmodifiableBuffer(buffer);
+ final Queue<E> queue = new LinkedList<E>();
+ queue.addAll(Arrays.asList(getFullElements()));
+ return UnmodifiableQueue.unmodifiableQueue(queue);
}
@Override
public Collection<E> makeConfirmedCollection() {
- return new ArrayStack<E>();
+ return new LinkedList<E>();
}
@Override
public Collection<E> makeConfirmedFullCollection() {
- final ArrayStack<E> list = new ArrayStack<E>();
+ final LinkedList<E> list = new LinkedList<E>();
list.addAll(Arrays.asList(getFullElements()));
return list;
}
@@ -76,7 +76,7 @@ public class UnmodifiableBufferTest<E> e
return false;
}
- public void testBufferRemove() {
+ public void testQueueRemove() {
resetEmpty();
try {
getCollection().remove();
@@ -86,21 +86,21 @@ public class UnmodifiableBufferTest<E> e
@Override
public String getCompatibilityVersion() {
- return "3.1";
+ return "4";
}
// public void testCreate() throws Exception {
// resetEmpty();
-// writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/UnmodifiableBuffer.emptyCollection.version3.1.obj");
+// writeExternalFormToDisk((java.io.Serializable) getCollection(), "src/test/resources/data/test/UnmodifiableQueue.emptyCollection.version4.obj");
// resetFull();
-// writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/UnmodifiableBuffer.fullCollection.version3.1.obj");
+// writeExternalFormToDisk((java.io.Serializable) getCollection(), "src/test/resources/data/test/UnmodifiableQueue.fullCollection.version4.obj");
// }
/**
* {@inheritDoc}
*/
@Override
- public Buffer<E> getCollection() {
- return (Buffer<E>) super.getCollection();
+ public Queue<E> getCollection() {
+ return (Queue<E>) super.getCollection();
}
}
Added: commons/proper/collections/trunk/src/test/resources/data/test/PredicatedQueue.emptyCollection.version4.obj
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/resources/data/test/PredicatedQueue.emptyCollection.version4.obj?rev=1457501&view=auto
==============================================================================
Binary file - no diff available.
Propchange: commons/proper/collections/trunk/src/test/resources/data/test/PredicatedQueue.emptyCollection.version4.obj
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: commons/proper/collections/trunk/src/test/resources/data/test/PredicatedQueue.fullCollection.version4.obj
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/resources/data/test/PredicatedQueue.fullCollection.version4.obj?rev=1457501&view=auto
==============================================================================
Binary file - no diff available.
Propchange: commons/proper/collections/trunk/src/test/resources/data/test/PredicatedQueue.fullCollection.version4.obj
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: commons/proper/collections/trunk/src/test/resources/data/test/TransformedQueue.emptyCollection.version4.obj
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/resources/data/test/TransformedQueue.emptyCollection.version4.obj?rev=1457501&view=auto
==============================================================================
Binary file - no diff available.
Propchange: commons/proper/collections/trunk/src/test/resources/data/test/TransformedQueue.emptyCollection.version4.obj
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: commons/proper/collections/trunk/src/test/resources/data/test/TransformedQueue.fullCollection.version4.obj
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/resources/data/test/TransformedQueue.fullCollection.version4.obj?rev=1457501&view=auto
==============================================================================
Binary file - no diff available.
Propchange: commons/proper/collections/trunk/src/test/resources/data/test/TransformedQueue.fullCollection.version4.obj
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: commons/proper/collections/trunk/src/test/resources/data/test/UnmodifiableQueue.emptyCollection.version4.obj
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/resources/data/test/UnmodifiableQueue.emptyCollection.version4.obj?rev=1457501&view=auto
==============================================================================
Binary file - no diff available.
Propchange: commons/proper/collections/trunk/src/test/resources/data/test/UnmodifiableQueue.emptyCollection.version4.obj
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: commons/proper/collections/trunk/src/test/resources/data/test/UnmodifiableQueue.fullCollection.version4.obj
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/resources/data/test/UnmodifiableQueue.fullCollection.version4.obj?rev=1457501&view=auto
==============================================================================
Binary file - no diff available.
Propchange: commons/proper/collections/trunk/src/test/resources/data/test/UnmodifiableQueue.fullCollection.version4.obj
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream