ListIterator "fast-forward" :
final ListIterator<Listener<E>> li = listenerList.listIterator();
if (li.hasNext()) {
do{
li.next();
} while (li.hasNext());
}
while (li.hasPrevious()) {
li.previous().changed(event);
}
EDIT . I switched the fancy exception handling from my previous answer to the do / while loop, which places the cursor ListIteratorafter the last element to be ready for the next previous.
RE-EDIT As pointed out by @MikeFHay, the do / while loop on the iterator will throw NoSuchElementExceptioninto an empty list. To prevent this from happening, I wrapped the do / while loop with if (li.hasNext()).
source
share