Don't try to bake handlers when there are no more handlers. Remove them instead!

This commit is contained in:
Dabo Ross 2013-09-05 21:59:31 -07:00 committed by md_5
parent 07e330b005
commit d0e5ee4e09

View File

@ -176,22 +176,28 @@ public class EventBus
private void bakeHandlers(Class<?> eventClass)
{
Map<EventPriority, Map<Object, Method[]>> handlersByPriority = byListenerAndPriority.get( eventClass );
List<EventHandlerMethod> handlersList = new ArrayList<>( handlersByPriority.size() * 2 );
for ( EventPriority value : EventPriority.values() )
if ( handlersByPriority != null )
{
Map<Object, Method[]> handlersByListener = handlersByPriority.get( value );
if ( handlersByListener != null )
List<EventHandlerMethod> handlersList = new ArrayList<>( handlersByPriority.size() * 2 );
for ( EventPriority value : EventPriority.values() )
{
for ( Map.Entry<Object, Method[]> listenerHandlers : handlersByListener.entrySet() )
Map<Object, Method[]> handlersByListener = handlersByPriority.get( value );
if ( handlersByListener != null )
{
for ( Method method : listenerHandlers.getValue() )
for ( Map.Entry<Object, Method[]> listenerHandlers : handlersByListener.entrySet() )
{
EventHandlerMethod ehm = new EventHandlerMethod( listenerHandlers.getKey(), method );
handlersList.add( ehm );
for ( Method method : listenerHandlers.getValue() )
{
EventHandlerMethod ehm = new EventHandlerMethod( listenerHandlers.getKey(), method );
handlersList.add( ehm );
}
}
}
}
byEventBaked.put( eventClass, handlersList.toArray( new EventHandlerMethod[ handlersList.size() ] ) );
} else
{
byEventBaked.put( eventClass, null );
}
byEventBaked.put( eventClass, handlersList.toArray( new EventHandlerMethod[ handlersList.size() ] ) );
}
}