You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2009/09/15 07:54:29 UTC

svn commit: r815029 - /commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java

Author: bayard
Date: Tue Sep 15 05:54:29 2009
New Revision: 815029

URL: http://svn.apache.org/viewvc?rev=815029&view=rev
Log:
Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified; mostly in r738956.

Also see the following revisions:

    ------------------------------------------------------------------------
    r471579 | scolebourne | 2006-11-05 16:14:58 -0800 (Sun, 05 Nov 2006) | 1 line
    
    Generify, remove getBuffer() - use covariant decorated()
    ------------------------------------------------------------------------

Modified:
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java?rev=815029&r1=815028&r2=815029&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java Tue Sep 15 05:54:29 2009
@@ -45,7 +45,7 @@
  * @version $Revision$ $Date$
  * @since Commons Collections 3.2
  */
-public class BoundedBuffer extends SynchronizedBuffer implements BoundedCollection {
+public class BoundedBuffer<E> extends SynchronizedBuffer<E> implements BoundedCollection<E> {
 
     /** The serialization version. */
     private static final long serialVersionUID = 1536432911093974264L;
@@ -67,8 +67,8 @@
      * @throws IllegalArgumentException if the buffer is null
      * @throws IllegalArgumentException if the maximum size is zero or less
      */
-    public static BoundedBuffer decorate(Buffer buffer, int maximumSize) {
-        return new BoundedBuffer(buffer, maximumSize, 0L);
+    public static <E> BoundedBuffer<E> decorate(Buffer<E> buffer, int maximumSize) {
+        return new BoundedBuffer<E>(buffer, maximumSize, 0L);
     }
 
     /**
@@ -82,8 +82,8 @@
      * @throws IllegalArgumentException if the buffer is null
      * @throws IllegalArgumentException if the maximum size is zero or less
      */
-    public static BoundedBuffer decorate(Buffer buffer, int maximumSize, long timeout) {
-        return new BoundedBuffer(buffer, maximumSize, timeout);
+    public static <E> BoundedBuffer<E> decorate(Buffer<E> buffer, int maximumSize, long timeout) {
+        return new BoundedBuffer<E>(buffer, maximumSize, timeout);
     }
 
     //-----------------------------------------------------------------------
@@ -97,7 +97,7 @@
      * @throws IllegalArgumentException if the buffer is null
      * @throws IllegalArgumentException if the maximum size is zero or less
      */
-    protected BoundedBuffer(Buffer buffer, int maximumSize, long timeout) {
+    protected BoundedBuffer(Buffer<E> buffer, int maximumSize, long timeout) {
         super(buffer);
         if (maximumSize < 1) {
             throw new IllegalArgumentException();
@@ -107,29 +107,29 @@
     }
 
     //-----------------------------------------------------------------------
-    public Object remove() {
+    public E remove() {
         synchronized (lock) {
-            Object returnValue = getBuffer().remove();
+            E returnValue = decorated().remove();
             lock.notifyAll();
             return returnValue;
         }
     }
 
-    public boolean add(Object o) {
+    public boolean add(E o) {
         synchronized (lock) {
             timeoutWait(1);
-            return getBuffer().add(o);
+            return decorated().add(o);
         }
     }
 
-    public boolean addAll(final Collection c) {
+    public boolean addAll(final Collection<? extends E> c) {
         synchronized (lock) {
             timeoutWait(c.size());
-            return getBuffer().addAll(c);
+            return decorated().addAll(c);
         }
     }
 
-    public Iterator iterator() {
+    public Iterator<E> iterator() {
         return new NotifyingIterator(collection.iterator());
     }
 
@@ -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");
         }
     }
@@ -178,9 +178,9 @@
     /**
      * BoundedBuffer iterator.
      */
-    private class NotifyingIterator extends AbstractIteratorDecorator {
+    private class NotifyingIterator extends AbstractIteratorDecorator<E> {
 
-        public NotifyingIterator(Iterator it) {
+        public NotifyingIterator(Iterator<E> it) {
             super(it);
         }