You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Herve Quiroz <he...@esil.univ-mrs.fr> on 2002/11/12 17:57:14 UTC

[collections] BoundedCollection ?

I have recently switched to the Jakarta Commons Collections 2.1 library. I
am mostly using it for Buffer implementations as I am working on a network
simulator using queues of messages. Unfortunately there is no method to
know if a buffer is full other than adding an object and catching a
BufferOverflowException... Which is quite annoying for me as the simulator
should only simulate the latency from some data tranfer only if the target
buffer is not full. And I can't predict if a given buffer will a bounded
one or not (depending on the scenario used for simulation).

So, I was planning on coding some utils to test whether a buffer is full
or not.  But then I thought of another alternative, the BoundedCollection
interface :

public interface BoundedCollection extends java.util.Collection
{
    public boolean isFull();
    public int maxSize();
}

... of course implemented by the BoundedBuffer class.

So to test if a buffer if full :

if (myBuffer instanceof BoundedCollection)
{
    bufferFull=((BoundedCollection)myBuffer).isFull();
}
else
{
    bufferFull=false; // as long as there is some free memory left
}

Maybe I am just reinventing the wheel but if someone as a
{cheap,quick,simple} solution, please tell me. I had my own queue library
working until I changed all my sources to use commons-collections just to
realize I am stuck with this issue.

Regards


Herve Quiroz


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [collections] Re: BoundedCollection

Posted by Stephen Colebourne <sc...@btopenworld.com>.
BoundedCollection has been added to CVS. I added the maxSize method
originally suggested, as I wanted that done before the interface gets
'frozen'. If there are any more 'bounded' methods let us know.

I put the static methods on CollectionUtils, to allow for non-buffer
implementations of BoundedCollection.

thanks
Stephen

----- Original Message -----
From: "Herve Quiroz" <he...@esil.univ-mrs.fr>
> 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)
> >
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


[collections] Re: BoundedCollection

Posted by Herve Quiroz <he...@esil.univ-mrs.fr>.
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)
>

Re: [collections] BoundedCollection ?

Posted by Stephen Colebourne <sc...@btopenworld.com>.
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)

Stephen

----- Original Message -----
From: "Herve Quiroz" <he...@esil.univ-mrs.fr>
> I have recently switched to the Jakarta Commons Collections 2.1 library. I
> am mostly using it for Buffer implementations as I am working on a network
> simulator using queues of messages. Unfortunately there is no method to
> know if a buffer is full other than adding an object and catching a
> BufferOverflowException... Which is quite annoying for me as the simulator
> should only simulate the latency from some data tranfer only if the target
> buffer is not full. And I can't predict if a given buffer will a bounded
> one or not (depending on the scenario used for simulation).
>
> So, I was planning on coding some utils to test whether a buffer is full
> or not.  But then I thought of another alternative, the BoundedCollection
> interface :
>
> public interface BoundedCollection extends java.util.Collection
> {
>     public boolean isFull();
>     public int maxSize();
> }
>
> ... of course implemented by the BoundedBuffer class.
>
> So to test if a buffer if full :
>
> if (myBuffer instanceof BoundedCollection)
> {
>     bufferFull=((BoundedCollection)myBuffer).isFull();
> }
> else
> {
>     bufferFull=false; // as long as there is some free memory left
> }
>
> Maybe I am just reinventing the wheel but if someone as a
> {cheap,quick,simple} solution, please tell me. I had my own queue library
> working until I changed all my sources to use commons-collections just to
> realize I am stuck with this issue.
>
> Regards
>
>
> Herve Quiroz
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>