Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top