yf0994 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Observable{CollectionType} decorators #1077

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be very useful if Guava provided decorators for the Collection 
interfaces (and the Multi{Collection} extensions) which turn a Collection into 
an Observable one, i.e. Listeners could be registered to receive changes to the 
underlying collection.

Example use case 1:

Set<String> strings = Sets.newHashSet();
ObservableSet<String> observable = ObservableSets.decorate(strings);
observable.addSetListener(new SetListener(){
  @Override
  public void elementAddedToSet(String element) {
     ...
  }

  @Override
  public void elementRemovedFromSet(String element) {
     ...
  }
});

Example use case 2: for JavaBeans, a Listener could hook back into the 
PropertyChangeSupport and therefore allow changes in mutable Collections (of 
immutable objects) to be seen by PropertyChangeListeners!

https://groups.google.com/forum/?fromgroups#!topic/guava-discuss/OwlKDIPVRdU

Original issue reported on code.google.com by Sam.Hall...@gmail.com on 20 Jul 2012 at 1:30

GoogleCodeExporter commented 9 years ago
NOTE: obviously the "observable" variable would need to be used from here on - 
the Listener wouldn't receive changes made directly to "strings".

Original comment by Sam.Hall...@gmail.com on 20 Jul 2012 at 1:32

GoogleCodeExporter commented 9 years ago
Hi,

Can't Glazed Lists help you on this one? The Guava team has made it clear in 
the past that they don't want to overlap with good and open source libraries.

Original comment by ogregoire on 20 Jul 2012 at 8:12

GoogleCodeExporter commented 9 years ago
Indeed.  What you can't do with e.g. the Forwarding collection decorators, I 
think we've always leaned towards not overlapping functionality with Glazed 
Lists.

Original comment by wasserman.louis on 20 Jul 2012 at 9:41

GoogleCodeExporter commented 9 years ago
.+1 for Glazed Lists.

Original comment by kurt.kluever on 24 Jul 2012 at 5:15

GoogleCodeExporter commented 9 years ago
I'm not entirely in agreement with this assessment. GlazedLists is a very 
specialist (and good) library for manipulating (usually filtering) tabular data 
and is focused on List manipulation.

However, GlazedLists lacks support for decorating other Collection types and 
even stands as an alternative to standard List implementations. My RFE is for a 
decorator on top of arbitrary Collection types. Indeed, my current requirement 
is for an ObservableSet.

Since I consider GlazedLists to fail at this task, I might just have to 
maintain a hacky internal implementation myself.

Original comment by Sam.Hall...@gmail.com on 27 Jul 2012 at 10:41

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:13

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08