Community
Participate
Working Groups
Build Identifier: I20100608-0911 The WritableList and WritableSet classes have functions clear(), removeAll(Collection) and addAll(Collection) methods. It would be nice to also have some kind of replaceWith(Collection) method, that replaces the current content with the specified content. (Currently this could be done only when using the calls sequence clear() and addAll(Collection), however at the cost of firing two events.) Having a method that does this computation in one step would be better if the event listeners do some expensive operations. Reproducible: Always
Created attachment 178811 [details] An example implementation We use the attached class to provide that feature. Maybe you can reuse that code.
Could you provide this as a patch for WritableList/WritableSet?
Created attachment 178816 [details] Patch for writable set
Hmm, seems that I can't change the description anymore: Instead of "using the calls sequence clear() and addAll(Collection)" it should be "using the calls sequence removeAll(Collection) and addAll(Collection)". (In reply to comment #0) > Build Identifier: I20100608-0911 > > The WritableList and WritableSet classes have functions clear(), > removeAll(Collection) and addAll(Collection) methods. It would be nice to also > have some kind of replaceWith(Collection) method, that replaces the current > content with the specified content. (Currently this could be done only when > using the calls sequence clear() and addAll(Collection), however at the cost of > firing two events.) Having a method that does this computation in one step > would be better if the event listeners do some expensive operations. > > Reproducible: Always
I don't have an implemention for WritableList yet. Should I provide one, too?
Ulli, I think I have a workaround for your use case that doesn't require new API: List backingList = ... // the original list contents IObservableValue listHolder = new WritableValue(backingList, List.class); IObservableList list = Properties.selfList(SomeElementType.class).observeDetail(listHolder); You can now modify list at will. If you want to batch replace the contents of the list, you can do so by calling listHolder.setValue(theNewList). Does this achieve what you're looking for?
This is not exactly what I want but that is still an interesting aproach! The drawback of your approach is that you don't get the removed and new elements in the event, just the new list. And a second drawback: as an application programmer I would like to work with just one object, i.e., I would like to access the list as such. If you would like to keep the API as small as possible, then I'm ok with the current implementation. (Even when you are adding the new methods I still need to provide a sub-class. Since the writable list/set is not Java 5 ready we will provide a generic wrapper for our team anyway)