// No point in adding an event if it has no listeners.
if(listenersCollection == null || listenersCollection.size() > 0) {
// If the event can be merged, attempt to do so.
if(event instanceof IMergeCapableEvent) {
// Search for an existing event that can be merged with the new one using the canMerge method.
IMergeCapableEvent mergeCapableEvent = (IMergeCapableEvent) event;
ListIterator<EventAndListeners<IEvent>> eventsIterator = this.eventsList.listIterator();
EventAndListeners<IEvent> existingEventAndListeners;
boolean merged = false;
while(eventsIterator.hasNext()) {
existingEventAndListeners = eventsIterator.next();
IEvent existingEvent = existingEventAndListeners.getEvent();
if(mergeCapableEvent.canMerge(existingEvent)) {
// If the new event can be merged with an existing one, do so.
IEvent mergedEvent = mergeCapableEvent.merge(existingEvent);
Set<IListener<IEvent>> existingListenersSet = existingEventAndListeners.getListenersSet();
Set<IListener<IEvent>> mergedListenersSet
= new HashSet<IListener<IEvent>>(listenersCollection.size() + existingListenersSet.size());
mergedListenersSet.addAll(existingListenersSet);
for(IListener<E> listener : listenersCollection) {