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] NotifyingCollections - the wrapping problem
Date Fri, 15 Aug 2003 22:01:21 GMT
This isn't the problem case. Think about:

  Collection c = new ArrayList();
  ObservableCollection oc = CollectionUtils.observableCollection(c);
  SynchronizedCollection sc = CollectionUtils.synchronizedCollection(oc);
  oc.addListener(new CollectionListener() {
    public void changed(CollectionEvent e) { Collection eventCollection =
e.getCollection() }
   });

  c.add("");
Fails - but all decorators ban this because c is decorated

  oc.add("");
Sends event OK - eventCollection == oc, but all decorators ban this because
oc is decorated

  sc.add("");
Sends event OK - BUT eventCollection == oc.
This is a problem, as if the listener then uses the collection, it will not
be synchronized. Big problem.

Stephen

----- Original Message -----
From: "Michael Heuer" <heuermh@acm.org>
To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>
Cc: <neilotoole@users.sourceforge.net>
Sent: Thursday, August 14, 2003 11:02 PM
Subject: Re: [collections] NotifyingCollections - capturing rich non-uniform
data


>
> On Thu, 14 Aug 2003, Stephen Colebourne wrote:
>
> > <snip>
> >
> > The biggest problem with all this is that the collection returned by
> > getSource() on the event. If the observed collection is wrapped (eg. by
a
> > SyncronizedCollection) then getSource() SHOULD return the wrapped
> > collection, but it can't as it doesn't know about it. This problem
applies
> > to all designs so far.
>
> Is this also a problem?  It's general to all of the delegation
> implementations.
>
>
>  private boolean heardChange = false;
>
>  public void testChangeToBackingCollection()
>  {
>   Collection c = new ArrayList();
>   ObservableCollection oc = CollectionUtils.observableCollection(c);
>   oc.addListener(new CollectionListener()
>    {
>     public void changed(CollectionEvent e) { heardChange = true; }
>    });
>
>   c.add("hello");
>
>   assertTrue("heardChange == true", heardChange == true);
>  }
>
>
> I don't think it's possible to make this test pass -- just a
> shortcoming of the wrapper design.  That's why I was looking into
> aspect-based implementations.
>
>    michael
>
>
> ---------------------------------------------------------------------
> 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