From: "Michael Heuer" <[EMAIL PROTECTED]>
> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to