Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Why traverse listener lists backwards?

Reply
Thread Tools

Why traverse listener lists backwards?

 
 
J Krugman
Guest
Posts: n/a
 
      08-04-2004



Looking at Swing code I'm surprised that, invariable, when a list
of event listeners needs to be traversed, it is done from last to
first. Why is this?

Thanks,

jill

--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.

 
Reply With Quote
 
 
 
 
xarax
Guest
Posts: n/a
 
      08-05-2004
"J Krugman" <(E-Mail Removed)> wrote in message
news:cequg7$r90$(E-Mail Removed)...
>
>
>
> Looking at Swing code I'm surprised that, invariable, when a list
> of event listeners needs to be traversed, it is done from last to
> first. Why is this?


Unless the JavaDoc specifies the order in which listeners
are called, you cannot rely on the order (LIFO versus FIFO)
of calling listeners. Different vendors make provide
different implementations, and thus call the listeners in
a different order. So, do not design your listeners to
presume a certain order of calling, unless the JavaDoc
of the Swing API specifies a certain order.


 
Reply With Quote
 
 
 
 
Jacob
Guest
Posts: n/a
 
      08-05-2004
J Krugman wrote:

> Looking at Swing code I'm surprised that, invariable, when a list
> of event listeners needs to be traversed, it is done from last to
> first. Why is this?


I don't know the specific case, but in general (as a pattern)
it is useful to traverse this kind of lists backwards in case
the accessed element is deleted along the way. A delete during
a traverse normally affects the remainder of the list, and a
forward iteration might easily be messed up.

As this makes assumptions about the implementation of the
underlaying structure, it is in general better to iterate over
a *copy* of the list.

 
Reply With Quote
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      08-05-2004
J Krugman <(E-Mail Removed)> writes:

> Looking at Swing code I'm surprised that, invariable, when a list
> of event listeners needs to be traversed, it is done from last to
> first. Why is this?


This allows later added listeners (that is, the developer's own
listeners) to e.g. consume the event, so that the default behaviour
can be superseded by the developer's code. If it was the other way
around, then the "standard" listeners would trigger first.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
why so many document listener events? Wizumwalt@gmail.com Java 3 05-18-2006 12:31 AM
List of lists of lists of lists... =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==?= Python 5 05-15-2006 11:47 AM
traverse a directory and subdirectories to find files ' properties Thieum22 Perl 1 08-06-2004 08:01 PM



Advertisments