Stephen,
Here is the patch.
bounded-support.diff:
patch file for BufferUtils.java and BoundedFifoBuffer.java
BoundedCollection.java:
new file
I have tried to find a way of including the new file in the diff but
there's nothing about it on the Jakarta project "Getting involved" web
page (at least I didn't see any).
Sorry, no unit test :( I know I should have done so but I wouldn't have
learnt JUnit just for a small patch. Anyway, I will have to learn it so
hopefuly I will provide unit tests with my next contribution :)
But it works AFAIK, with support for SynchronizedBuffers also.
Regards,
-Herve
On Thu, 14 Nov 2002, Stephen Colebourne wrote:
> I like this idea, and can see no problems with implementation. Would you
> like to code it up as a new interface and patches to existing files (from
> CVS head) ? Its the best way to get it included ;-)
>
> In addition you could add convenience static methods to BufferUtils to do
> this code
>
> public static boolean isFull(Buffer buffer) {
> if (myBuffer instanceof BoundedCollection)
> bufferFull=((BoundedCollection)myBuffer).isFull();
> else
> bufferFull=false; // as long as there is some free memory left
> }
> (and also maxsize)
>
? src/java/org/apache/commons/collections/.BufferUtils.java.swp
? src/java/org/apache/commons/collections/BoundedCollection.java
Index: src/java/org/apache/commons/collections/BoundedFifoBuffer.java
===================================================================
RCS file:
/home/cvspublic/jakarta-commons/collections/src/java/org/apache/commons/collections/BoundedFifoBuffer.java,v
retrieving revision 1.5
diff -u -r1.5 BoundedFifoBuffer.java
--- src/java/org/apache/commons/collections/BoundedFifoBuffer.java 13 Oct 2002
12:59:04 -0000 1.5
+++ src/java/org/apache/commons/collections/BoundedFifoBuffer.java 22 Nov 2002
+13:07:10 -0000
@@ -92,7 +92,7 @@
* @since 2.1
* @version $Id: BoundedFifoBuffer.java,v 1.5 2002/10/13 12:59:04 scolebourne Exp $
*/
-public class BoundedFifoBuffer extends AbstractCollection implements Buffer {
+public class BoundedFifoBuffer extends AbstractCollection implements Buffer,
+BoundedCollection {
private final Object[] m_elements;
private int m_start = 0;
private int m_end = 0;
@@ -158,6 +158,15 @@
*/
public boolean isEmpty() {
return size() == 0;
+ }
+
+ /**
+ * Returns true if this buffer cannot be added any new element.
+ *
+ * @return true if the buffer is full
+ */
+ public boolean isFull() {
+ return size() == m_elements.length;
}
/**
Index: src/java/org/apache/commons/collections/BufferUtils.java
===================================================================
RCS file:
/home/cvspublic/jakarta-commons/collections/src/java/org/apache/commons/collections/BufferUtils.java,v
retrieving revision 1.9
diff -u -r1.9 BufferUtils.java
--- src/java/org/apache/commons/collections/BufferUtils.java 13 Oct 2002 00:38:36
-0000 1.9
+++ src/java/org/apache/commons/collections/BufferUtils.java 22 Nov 2002 13:07:11
+-0000
@@ -79,6 +79,22 @@
/**
+ * Returns true if this buffer cannot be added any new element.
+ *
+ * @return true if the buffer is full
+ */
+ public static boolean isFull(Buffer buffer) {
+ Buffer theBuffer=buffer;
+ if (buffer instanceof SynchronizedBuffer) {
+ theBuffer=(Buffer)((SynchronizedBuffer)buffer).collection;
+ }
+ if (theBuffer instanceof BoundedCollection) {
+ return ((BoundedCollection)theBuffer).isFull();
+ }
+ return false;
+ }
+
+ /**
* 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 Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections;
import java.util.Collection;
/**
* A BoundedCollection is a collection that is bounded as of its size.
* It can indeed only contain a maximum number of elements at a given time.
*
* @author <a href="[EMAIL PROTECTED]">Herve Quiroz</a>
*/
public interface BoundedCollection extends Collection {
/**
* Returns true if this collection cannot be added any new element.
*
* @return true if the collection is full
*/
boolean isFull();
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>