@Test public void fireEvent( ) { Object other = new Object( ); EventManager eventManager = new EventManager( this ); assertThrows( NullPointerException.class, ( ) -> eventManager.fireEvent( null ) ); Event event = new Event( EventType.ROOT, other ); assertEquals( other, event.getSource( ) ); TestHandler handler = new TestHandler( ); eventManager.registerEventHandler( EventType.ROOT, handler ); eventManager.fireEvent( event ); assertEquals( 1, handler.getEventList( ).size( ) ); Event newEvent = handler.getEventList( ).get( 0 ); assertNotEquals( event, newEvent ); assertEquals( this, newEvent.getSource( ) ); }
public void fireEvent(Event fireEvent) { final EventType<? extends Event> type = fireEvent.getType(); Event event; if (fireEvent.getSource()!=source) { event = fireEvent.copyFor(source); } else { event = fireEvent; } for (EventType<? extends Event> handlerType : handlerMap.keySet()) { if (EventType.isInstanceOf(type, handlerType)) { for (EventHandler handler : handlerMap.get(handlerType)) { try { handler.handle(event); } catch (Exception e) { LOG.error("An error occured during event handling: {}", e.getMessage(), e); } } } } }
EventManager implements EventSource { public void fireEvent(Event fireEvent) { final EventType<? extends Event> type = fireEvent.getType(); Event event; if (fireEvent.getSource()!=source) { event = fireEvent.copyFor(source); } else { event = fireEvent; } for (EventType<? extends Event> handlerType : handlerMap.keySet()) { if (EventType.isInstanceOf(type, handlerType)) { for (EventHandler handler : handlerMap.get(handlerType)) { try { handler.handle(event); } catch (Exception e) { LOG.error("An error occured during event handling: {}", e.getMessage(), e); } } } } } }
EventManager implements EventSource { public void fireEvent(Event fireEvent) { final EventType<? extends Event> type = fireEvent.getType(); Event event; if (fireEvent.getSource()!=source) { event = fireEvent.copyFor(source); } else { event = fireEvent; } for (EventType<? extends Event> handlerType : handlerMap.keySet()) { if (EventType.isInstanceOf(type, handlerType)) { for (EventHandler handler : handlerMap.get(handlerType)) { try { handler.handle(event); } catch (Exception e) { LOG.error("An error occured during event handling: {}", e.getMessage(), e); } } } } } EventManager(Object source); }
EventManager implements EventSource { public void fireEvent(Event fireEvent) { final EventType<? extends Event> type = fireEvent.getType(); Event event; if (fireEvent.getSource()!=source) { event = fireEvent.copyFor(source); } else { event = fireEvent; } for (EventType<? extends Event> handlerType : handlerMap.keySet()) { if (EventType.isInstanceOf(type, handlerType)) { for (EventHandler handler : handlerMap.get(handlerType)) { try { handler.handle(event); } catch (Exception e) { LOG.error("An error occured during event handling: {}", e.getMessage(), e); } } } } } EventManager(Object source); @Override void registerEventHandler(EventType<T> type, EventHandler<? super T> eventHandler); @Override void unregisterEventHandler(EventType<T> type, EventHandler<? super T> eventHandler); void fireEvent(Event fireEvent); }
EventManager implements EventSource { public void fireEvent(Event fireEvent) { final EventType<? extends Event> type = fireEvent.getType(); Event event; if (fireEvent.getSource()!=source) { event = fireEvent.copyFor(source); } else { event = fireEvent; } for (EventType<? extends Event> handlerType : handlerMap.keySet()) { if (EventType.isInstanceOf(type, handlerType)) { for (EventHandler handler : handlerMap.get(handlerType)) { try { handler.handle(event); } catch (Exception e) { LOG.error("An error occured during event handling: {}", e.getMessage(), e); } } } } } EventManager(Object source); @Override void registerEventHandler(EventType<T> type, EventHandler<? super T> eventHandler); @Override void unregisterEventHandler(EventType<T> type, EventHandler<? super T> eventHandler); void fireEvent(Event fireEvent);  }