From 245554d88898209c2de5a6bef686d83ba4e42971 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 19 May 2005 22:17:10 +0000 Subject: [PATCH] Fix formatting issues from previous commit git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@171005 13f79535-47bb-0310-9956-ffa450edef68 --- .../collections/buffer/BlockingBuffer.java | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src/java/org/apache/commons/collections/buffer/BlockingBuffer.java b/src/java/org/apache/commons/collections/buffer/BlockingBuffer.java index e92579f97..5159970ff 100644 --- a/src/java/org/apache/commons/collections/buffer/BlockingBuffer.java +++ b/src/java/org/apache/commons/collections/buffer/BlockingBuffer.java @@ -25,17 +25,17 @@ import org.apache.commons.collections.BufferUnderflowException; /** * Decorates another Buffer to make {@link #get()} and * {@link #remove()} block when the Buffer is empty. - *

+ *

* If either get or remove is called on an empty * Buffer, the calling thread waits for notification that * an add or addAll operation has completed. - *

+ *

* When one or more entries are added to an empty Buffer, * all threads blocked in get or remove are notified. * There is no guarantee that concurrent blocked get or * remove requests will be "unblocked" and receive data in the * order that they arrive. - *

+ *

* This class is Serializable from Commons Collections 3.1. * * @author Stephen Colebourne @@ -74,7 +74,7 @@ public class BlockingBuffer extends SynchronizedBuffer { //----------------------------------------------------------------------- public boolean add(Object o) { - synchronized(lock) { + synchronized (lock) { boolean result = collection.add(o); notifyAll(); return result; @@ -82,7 +82,7 @@ public class BlockingBuffer extends SynchronizedBuffer { } public boolean addAll(Collection c) { - synchronized(lock) { + synchronized (lock) { boolean result = collection.addAll(c); notifyAll(); return result; @@ -90,12 +90,11 @@ public class BlockingBuffer extends SynchronizedBuffer { } public Object get() { - synchronized(lock) { - while(collection.isEmpty()) { + synchronized (lock) { + while (collection.isEmpty()) { try { wait(); - } - catch(InterruptedException e) { + } catch (InterruptedException e) { PrintWriter out = new PrintWriter(new StringWriter()); e.printStackTrace(out); throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString()); @@ -106,21 +105,20 @@ public class BlockingBuffer extends SynchronizedBuffer { } public Object get(final long timeout) { - synchronized(lock) { + synchronized (lock) { final long expiration = System.currentTimeMillis() + timeout; long timeLeft = expiration - System.currentTimeMillis(); - while(timeLeft > 0 && collection.isEmpty()) { + while (timeLeft > 0 && collection.isEmpty()) { try { wait(timeLeft); timeLeft = expiration - System.currentTimeMillis(); - } - catch(InterruptedException e) { + } catch(InterruptedException e) { PrintWriter out = new PrintWriter(new StringWriter()); e.printStackTrace(out); throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString()); } } - if(collection.isEmpty()) { + if (collection.isEmpty()) { throw new BufferUnderflowException("Timeout expired."); } return getBuffer().get(); @@ -128,12 +126,11 @@ public class BlockingBuffer extends SynchronizedBuffer { } public Object remove() { - synchronized(lock) { - while(collection.isEmpty()) { + synchronized (lock) { + while (collection.isEmpty()) { try { wait(); - } - catch(InterruptedException e) { + } catch (InterruptedException e) { PrintWriter out = new PrintWriter(new StringWriter()); e.printStackTrace(out); throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString()); @@ -144,24 +141,24 @@ public class BlockingBuffer extends SynchronizedBuffer { } public Object remove(final long timeout) { - synchronized(lock) { + synchronized (lock) { final long expiration = System.currentTimeMillis() + timeout; long timeLeft = expiration - System.currentTimeMillis(); - while(timeLeft > 0 && collection.isEmpty()) { + while (timeLeft > 0 && collection.isEmpty()) { try { wait(timeLeft); timeLeft = expiration - System.currentTimeMillis(); - } - catch(InterruptedException e) { + } catch(InterruptedException e) { PrintWriter out = new PrintWriter(new StringWriter()); e.printStackTrace(out); throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString()); } } - if(collection.isEmpty()) { + if (collection.isEmpty()) { throw new BufferUnderflowException("Timeout expired."); } return getBuffer().remove(); } } + }