views:

182

answers:

1

Hi,

I need to implement List decorator class, which notify registered listeners in case of any change in list. I have subclassed AbstractListDecorator from org.apache.commons.collections15 and override methods like add(), addAll(), remove(int), remove(E) and so on with my notifying.

But there are some holes in -- for example when iterating through List by default AbstractListDecorator.iterator() and call Iterator.remove() method, either overridden methods remove(int) or remove(E) doesn't call.

Is there any standard and safety practice for decorating such things?

Thank you.

+2  A: 

override the iterator() and listIterator() methods, and provide a decorated iterator that will notify your listeners whenever remove() is called.

David Rabinowitz
Thank you. That is what are `AbstractIteratorDecorator` and `AbstractListIteratorDecorator` for.
mschayna