commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <scolebou...@btopenworld.com>
Subject Re: [collections] UnmodifiableBoundedCollection
Date Wed, 31 Mar 2004 20:12:35 GMT
This misunderstands the BoundedCollection interface, which is an interface
providing extra information about collections with a maximum limited size..

// create a buffer that implements the BoundedCollection interface
BoundedCollection buffer = new BoundedBuffer(16);

// synchronize it, but this loses the BoundedCollection interface
Collection sync = SynchronizedCollection.decorate(buffer);

// get back to the bounded collection interface
BoundedCollection coll = UnmodifiableBoundedCollection.decorateUsing(sync);

Stephen

----- Original Message -----
From: "Torsten Curdt" <tcurdt@vafer.org>
> Quoting from the javadocs
>
> > UnmodifiableBoundedCollection decorates another BoundedCollection  to
> > ensure it can't be altered.
> >
> > If a BoundedCollection is first wrapped in some other collection
> > decorator, such as synchronized or predicated, the BoundedCollection
> > nature is lost. The factory on this class will attempt to retrieve the
> > bounded nature by examining the package scope variables.
>
> I wondered why this should be the case so I gave it a try:
>
>          Map sm = MapUtils.synchronizedMap(new HashMap());
>          Map m = MapUtils.fixedSizeMap(sm);
>          m.put("a","value");
>
>          Map m = MapUtils.fixedSizeMap(new HashMap());
>          Map sm = MapUtils.synchronizedMap(m);
>          sm.put("a","value");
>
> Both examples throw an exception as exspected.
> Can someone explain why the UnmodifiableBoundedCollection
> is needed?
>
> cheers
> --
> Torsten
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message