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] Notifying/Observable design choices
Date Tue, 17 Jun 2003 07:40:11 GMT
From: "Michael Heuer" <heuermh@acm.org>
> On Sat, 7 Jun 2003, Stephen Colebourne wrote:
>
> > Proposal #3 (Colebourne - merged from #1 and #2):
> > --------------------------
> > public boolean addAll(int index, Collection c){
> >   if (preAddAll(index, c)) {
> >     result = backingList.addAll(index, c);
> >     postAddAll(index, c, result);
> >   }
> >   return result;
> >  }
>
> I might be missing something here, but in order to support
> oldSize/newSize in the event object in this design, I think I'd have to
> pass some state from the pre to the post method, e.g.

I was thinking that the decorator could store the info as an instance
variable. It should work fine.

Stephen



>
> class AbstractXxxCollection
>    extends AbstractCollectionDecorator
> {
>   public boolean add(Object o)
>   {
>     boolean result = false;
>     if (preAdd(o))
>     {
>       result = super.add(o);
>       postAdd(o);
>     }
>     return result;
>   }
>   protected boolean preAdd(Object o) { return true; }
>   protected void postAdd(Object o) {}
> }
>
> class ObservableCollection
>    extends AbstractXxxCollection
> {
>   protected boolean preAdd(Object o)
>   {
>     int oldSize = size();
>     return true;
>   }
>   protected void postAdd(Object o)
>   {
>     fireElementAdded(oldSize, size(), o);
>   }
> }
>
> something like,
>
>   protected boolean preAdd(Object o, Map ctx)
>   {
>     ctx.put("oldSize", new Integer(size()));
>     return true;
>   }
>   protected void postAdd(Object o, Map ctx)
>   {
>     int oldSize = ((Integer) ctx.get("oldSize")).intValue();
>     fireElementAdded(oldSize, size(), o);
>   }
>
>    michael
>
>
>
> ---------------------------------------------------------------------
> 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