#3221: Use computeIfAbsent method in EventBus
This commit is contained in:
parent
51eb1ac623
commit
2479fab632
@ -88,18 +88,8 @@ public class EventBus
|
|||||||
} );
|
} );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Map<Byte, Set<Method>> prioritiesMap = handler.get( params[0] );
|
Map<Byte, Set<Method>> prioritiesMap = handler.computeIfAbsent( params[0], k -> new HashMap<>() );
|
||||||
if ( prioritiesMap == null )
|
Set<Method> priority = prioritiesMap.computeIfAbsent( annotation.priority(), k -> new HashSet<>() );
|
||||||
{
|
|
||||||
prioritiesMap = new HashMap<>();
|
|
||||||
handler.put( params[0], prioritiesMap );
|
|
||||||
}
|
|
||||||
Set<Method> priority = prioritiesMap.get( annotation.priority() );
|
|
||||||
if ( priority == null )
|
|
||||||
{
|
|
||||||
priority = new HashSet<>();
|
|
||||||
prioritiesMap.put( annotation.priority(), priority );
|
|
||||||
}
|
|
||||||
priority.add( m );
|
priority.add( m );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,20 +104,10 @@ public class EventBus
|
|||||||
{
|
{
|
||||||
for ( Map.Entry<Class<?>, Map<Byte, Set<Method>>> e : handler.entrySet() )
|
for ( Map.Entry<Class<?>, Map<Byte, Set<Method>>> e : handler.entrySet() )
|
||||||
{
|
{
|
||||||
Map<Byte, Map<Object, Method[]>> prioritiesMap = byListenerAndPriority.get( e.getKey() );
|
Map<Byte, Map<Object, Method[]>> prioritiesMap = byListenerAndPriority.computeIfAbsent( e.getKey(), k -> new HashMap<>() );
|
||||||
if ( prioritiesMap == null )
|
|
||||||
{
|
|
||||||
prioritiesMap = new HashMap<>();
|
|
||||||
byListenerAndPriority.put( e.getKey(), prioritiesMap );
|
|
||||||
}
|
|
||||||
for ( Map.Entry<Byte, Set<Method>> entry : e.getValue().entrySet() )
|
for ( Map.Entry<Byte, Set<Method>> entry : e.getValue().entrySet() )
|
||||||
{
|
{
|
||||||
Map<Object, Method[]> currentPriorityMap = prioritiesMap.get( entry.getKey() );
|
Map<Object, Method[]> currentPriorityMap = prioritiesMap.computeIfAbsent( entry.getKey(), k -> new HashMap<>() );
|
||||||
if ( currentPriorityMap == null )
|
|
||||||
{
|
|
||||||
currentPriorityMap = new HashMap<>();
|
|
||||||
prioritiesMap.put( entry.getKey(), currentPriorityMap );
|
|
||||||
}
|
|
||||||
currentPriorityMap.put( listener, entry.getValue().toArray( new Method[ 0 ] ) );
|
currentPriorityMap.put( listener, entry.getValue().toArray( new Method[ 0 ] ) );
|
||||||
}
|
}
|
||||||
bakeHandlers( e.getKey() );
|
bakeHandlers( e.getKey() );
|
||||||
|
Loading…
Reference in New Issue
Block a user