Author: scolebourne
Date: Sun Nov 5 16:14:58 2006
New Revision: 471579
URL: http://svn.apache.org/viewvc?view=rev&rev=471579
Log:
Generify, remove getBuffer() - use covariant decorated()
Modified:
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/AbstractBufferDecorator.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/BlockingBuffer.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/SynchronizedBuffer.java
Modified:
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/AbstractBufferDecorator.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/AbstractBufferDecorator.java?view=diff&rev=471579&r1=471578&r2=471579
==============================================================================
---
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/AbstractBufferDecorator.java
(original)
+++
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/AbstractBufferDecorator.java
Sun Nov 5 16:14:58 2006
@@ -24,12 +24,15 @@
* <p>
* Methods are forwarded directly to the decorated buffer.
*
+ * @param <E> the type of the elements in the buffer
* @since Commons Collections 3.0
* @version $Revision$ $Date$
*
* @author Stephen Colebourne
*/
-public abstract class AbstractBufferDecorator extends
AbstractCollectionDecorator implements Buffer {
+public abstract class AbstractBufferDecorator<E>
+ extends AbstractCollectionDecorator<E>
+ implements Buffer<E> {
/**
* Constructor only used in deserialization, do not use otherwise.
@@ -45,7 +48,7 @@
* @param buffer the buffer to decorate, must not be null
* @throws IllegalArgumentException if list is null
*/
- protected AbstractBufferDecorator(Buffer buffer) {
+ protected AbstractBufferDecorator(Buffer<E> buffer) {
super(buffer);
}
@@ -53,27 +56,17 @@
* Gets the buffer being decorated.
*
* @return the decorated buffer
- * @deprecated use decorated()
*/
- protected Buffer getBuffer() {
- return decorated();
- }
-
- /**
- * Gets the buffer being decorated.
- *
- * @return the decorated buffer
- */
- protected Buffer decorated() {
- return (Buffer) super.decorated();
+ protected Buffer<E> decorated() {
+ return (Buffer<E>) super.decorated();
}
//-----------------------------------------------------------------------
- public Object get() {
+ public E get() {
return decorated().get();
}
- public Object remove() {
+ public E remove() {
return decorated().remove();
}
Modified:
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/BlockingBuffer.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/BlockingBuffer.java?view=diff&rev=471579&r1=471578&r2=471579
==============================================================================
---
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/BlockingBuffer.java
(original)
+++
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/BlockingBuffer.java
Sun Nov 5 16:14:58 2006
@@ -45,10 +45,11 @@
* @author Janek Bogucki
* @author Phil Steitz
* @author James Carman
+ * @param <E> the type of the elements in the buffer
* @version $Revision$ $Date$
* @since Commons Collections 3.0
*/
-public class BlockingBuffer extends SynchronizedBuffer {
+public class BlockingBuffer<E> extends SynchronizedBuffer<E> {
/** Serialization version. */
private static final long serialVersionUID = 1719328905017860541L;
@@ -58,25 +59,27 @@
/**
* Factory method to create a blocking buffer.
*
+ * @param <t> the type of the elements in the buffer
* @param buffer the buffer to decorate, must not be null
* @return a new blocking Buffer
* @throws IllegalArgumentException if buffer is null
*/
- public static Buffer decorate(Buffer buffer) {
- return new BlockingBuffer(buffer);
+ public static <T> Buffer<T> decorate(Buffer<T> buffer) {
+ return new BlockingBuffer<T>(buffer);
}
/**
* Factory method to create a blocking buffer with a timeout value.
*
+ * @param <t> the type of the elements in the buffer
* @param buffer the buffer to decorate, must not be null
* @param timeoutMillis the timeout value in milliseconds, zero or less
for no timeout
* @return a new blocking buffer
* @throws IllegalArgumentException if the buffer is null
* @since Commons Collections 3.2
*/
- public static Buffer decorate(Buffer buffer, long timeoutMillis) {
- return new BlockingBuffer(buffer, timeoutMillis);
+ public static <T> Buffer<T> decorate(Buffer<T> buffer, long timeoutMillis)
{
+ return new BlockingBuffer<T>(buffer, timeoutMillis);
}
//-----------------------------------------------------------------------
@@ -86,7 +89,7 @@
* @param buffer the buffer to decorate, must not be null
* @throws IllegalArgumentException if the buffer is null
*/
- protected BlockingBuffer(Buffer buffer) {
+ protected BlockingBuffer(Buffer<E> buffer) {
super(buffer);
this.timeout = 0;
}
@@ -99,13 +102,13 @@
* @throws IllegalArgumentException if the buffer is null
* @since Commons Collections 3.2
*/
- protected BlockingBuffer(Buffer buffer, long timeoutMillis) {
+ protected BlockingBuffer(Buffer<E> buffer, long timeoutMillis) {
super(buffer);
this.timeout = (timeoutMillis < 0 ? 0 : timeoutMillis);
}
//-----------------------------------------------------------------------
- public boolean add(Object o) {
+ public boolean add(E o) {
synchronized (lock) {
boolean result = collection.add(o);
lock.notifyAll();
@@ -113,7 +116,7 @@
}
}
- public boolean addAll(Collection c) {
+ public boolean addAll(Collection<? extends E> c) {
synchronized (lock) {
boolean result = collection.addAll(c);
lock.notifyAll();
@@ -128,7 +131,7 @@
*
* @throws BufferUnderflowException if an interrupt is received
*/
- public Object get() {
+ public E get() {
synchronized (lock) {
while (collection.isEmpty()) {
try {
@@ -143,7 +146,7 @@
throw new BufferUnderflowException("Caused by
InterruptedException: " + out.toString());
}
}
- return getBuffer().get();
+ return decorated().get();
}
}
@@ -156,7 +159,7 @@
* @throws BufferUnderflowException if the timeout expires
* @since Commons Collections 3.2
*/
- public Object get(final long timeout) {
+ public E get(final long timeout) {
synchronized (lock) {
final long expiration = System.currentTimeMillis() + timeout;
long timeLeft = expiration - System.currentTimeMillis();
@@ -173,7 +176,7 @@
if (collection.isEmpty()) {
throw new BufferUnderflowException("Timeout expired");
}
- return getBuffer().get();
+ return decorated().get();
}
}
@@ -184,7 +187,7 @@
*
* @throws BufferUnderflowException if an interrupt is received
*/
- public Object remove() {
+ public E remove() {
synchronized (lock) {
while (collection.isEmpty()) {
try {
@@ -199,7 +202,7 @@
throw new BufferUnderflowException("Caused by
InterruptedException: " + out.toString());
}
}
- return getBuffer().remove();
+ return decorated().remove();
}
}
@@ -212,7 +215,7 @@
* @throws BufferUnderflowException if the timeout expires
* @since Commons Collections 3.2
*/
- public Object remove(final long timeout) {
+ public E remove(final long timeout) {
synchronized (lock) {
final long expiration = System.currentTimeMillis() + timeout;
long timeLeft = expiration - System.currentTimeMillis();
@@ -229,7 +232,7 @@
if (collection.isEmpty()) {
throw new BufferUnderflowException("Timeout expired");
}
- return getBuffer().remove();
+ return decorated().remove();
}
}
Modified:
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java?view=diff&rev=471579&r1=471578&r2=471579
==============================================================================
---
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java
(original)
+++
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java
Sun Nov 5 16:14:58 2006
@@ -109,7 +109,7 @@
//-----------------------------------------------------------------------
public Object remove() {
synchronized (lock) {
- Object returnValue = getBuffer().remove();
+ Object returnValue = decorated().remove();
lock.notifyAll();
return returnValue;
}
@@ -118,14 +118,14 @@
public boolean add(Object o) {
synchronized (lock) {
timeoutWait(1);
- return getBuffer().add(o);
+ return decorated().add(o);
}
}
public boolean addAll(final Collection c) {
synchronized (lock) {
timeoutWait(c.size());
- return getBuffer().addAll(c);
+ return decorated().addAll(c);
}
}
@@ -141,7 +141,7 @@
}
if (timeout <= 0) {
// no wait period (immediate timeout)
- if (getBuffer().size() + nAdditions > maximumSize) {
+ if (decorated().size() + nAdditions > maximumSize) {
throw new BufferOverflowException(
"Buffer size cannot exceed " + maximumSize);
}
@@ -149,7 +149,7 @@
}
final long expiration = System.currentTimeMillis() + timeout;
long timeLeft = expiration - System.currentTimeMillis();
- while (timeLeft > 0 && getBuffer().size() + nAdditions > maximumSize) {
+ while (timeLeft > 0 && decorated().size() + nAdditions > maximumSize) {
try {
lock.wait(timeLeft);
timeLeft = expiration - System.currentTimeMillis();
@@ -160,7 +160,7 @@
"Caused by InterruptedException: " + out.toString());
}
}
- if (getBuffer().size() + nAdditions > maximumSize) {
+ if (decorated().size() + nAdditions > maximumSize) {
throw new BufferOverflowException("Timeout expired");
}
}
Modified:
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/SynchronizedBuffer.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/SynchronizedBuffer.java?view=diff&rev=471579&r1=471578&r2=471579
==============================================================================
---
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/SynchronizedBuffer.java
(original)
+++
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/SynchronizedBuffer.java
Sun Nov 5 16:14:58 2006
@@ -27,12 +27,15 @@
* <p>
* This class is Serializable from Commons Collections 3.1.
*
+ * @param <E> the type of the elements in the buffer
* @since Commons Collections 3.0
* @version $Revision$ $Date$
*
* @author Stephen Colebourne
*/
-public class SynchronizedBuffer extends SynchronizedCollection implements
Buffer {
+public class SynchronizedBuffer<E>
+ extends SynchronizedCollection<E>
+ implements Buffer<E> {
/** Serialization version */
private static final long serialVersionUID = -6859936183953626253L;
@@ -40,14 +43,15 @@
/**
* Factory method to create a synchronized buffer.
*
+ * @param <T> the type of the elements in the buffer
* @param buffer the buffer to decorate, must not be null
* @return a new synchronized Buffer
* @throws IllegalArgumentException if buffer is null
*/
- public static Buffer decorate(Buffer buffer) {
- return new SynchronizedBuffer(buffer);
+ public static <T> Buffer<T> decorate(Buffer<T> buffer) {
+ return new SynchronizedBuffer<T>(buffer);
}
-
+
//-----------------------------------------------------------------------
/**
* Constructor that wraps (not copies).
@@ -55,7 +59,7 @@
* @param buffer the buffer to decorate, must not be null
* @throws IllegalArgumentException if the buffer is null
*/
- protected SynchronizedBuffer(Buffer buffer) {
+ protected SynchronizedBuffer(Buffer<E> buffer) {
super(buffer);
}
@@ -66,7 +70,7 @@
* @param lock the lock object to use, must not be null
* @throws IllegalArgumentException if the buffer is null
*/
- protected SynchronizedBuffer(Buffer buffer, Object lock) {
+ protected SynchronizedBuffer(Buffer<E> buffer, Object lock) {
super(buffer, lock);
}
@@ -75,21 +79,21 @@
*
* @return the decorated buffer
*/
- protected Buffer getBuffer() {
- return (Buffer) collection;
+ protected Buffer<E> decorated() {
+ return (Buffer<E>) super.decorated();
}
//-----------------------------------------------------------------------
- public Object get() {
+ public E get() {
synchronized (lock) {
- return getBuffer().get();
+ return decorated().get();
}
}
- public Object remove() {
+ public E remove() {
synchronized (lock) {
- return getBuffer().remove();
+ return decorated().remove();
}
}
-
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]