Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 97220 invoked from network); 6 Nov 2006 00:45:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Nov 2006 00:45:55 -0000 Received: (qmail 49192 invoked by uid 500); 6 Nov 2006 00:45:38 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 47896 invoked by uid 500); 6 Nov 2006 00:45:27 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 46008 invoked by uid 500); 6 Nov 2006 00:45:15 -0000 Received: (qmail 44609 invoked by uid 99); 6 Nov 2006 00:45:04 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Nov 2006 16:45:04 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Nov 2006 16:15:25 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id D463B1A9846; Sun, 5 Nov 2006 16:14:58 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r471579 - in /jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer: AbstractBufferDecorator.java BlockingBuffer.java BoundedBuffer.java SynchronizedBuffer.java Date: Mon, 06 Nov 2006 00:14:58 -0000 To: commons-cvs@jakarta.apache.org From: scolebourne@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061106001458.D463B1A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ *

* Methods are forwarded directly to the decorated buffer. * + * @param 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 + extends AbstractCollectionDecorator + implements Buffer { /** * 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 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 decorated() { + return (Buffer) 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 the type of the elements in the buffer * @version $Revision$ $Date$ * @since Commons Collections 3.0 */ -public class BlockingBuffer extends SynchronizedBuffer { +public class BlockingBuffer extends SynchronizedBuffer { /** Serialization version. */ private static final long serialVersionUID = 1719328905017860541L; @@ -58,25 +59,27 @@ /** * Factory method to create a blocking buffer. * + * @param 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 Buffer decorate(Buffer buffer) { + return new BlockingBuffer(buffer); } /** * Factory method to create a blocking buffer with a timeout value. * + * @param 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 Buffer decorate(Buffer buffer, long timeoutMillis) { + return new BlockingBuffer(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 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 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 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 @@ *

* This class is Serializable from Commons Collections 3.1. * + * @param 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 + extends SynchronizedCollection + implements Buffer { /** Serialization version */ private static final long serialVersionUID = -6859936183953626253L; @@ -40,14 +43,15 @@ /** * Factory method to create a synchronized buffer. * + * @param 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 Buffer decorate(Buffer buffer) { + return new SynchronizedBuffer(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 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 buffer, Object lock) { super(buffer, lock); } @@ -75,21 +79,21 @@ * * @return the decorated buffer */ - protected Buffer getBuffer() { - return (Buffer) collection; + protected Buffer decorated() { + return (Buffer) 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: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org