@Test (expected = IllegalStateException.class) public void testRemoveNotExistentListener () { EventManager manager = new EventManager("test", false); EventListener listener = (eventData -> { }); manager.addListener(2, listener); manager.addListener(2, listener); }
public <T extends EventData> void addListener (int typeID, EventListener<T> listener) { Objects.requireNonNull(listener); Array<EventListener> list = this.listenerMap.get(typeID); if (list == null) { list = new Array<>(10); this.listenerMap.put(typeID, list); } if (list.contains(listener, false)) { throw new IllegalStateException("listener for typeID '" + typeID + "' and hash " + listener + " is already registered."); } list.add(listener); }
EventManager { public <T extends EventData> void addListener (int typeID, EventListener<T> listener) { Objects.requireNonNull(listener); Array<EventListener> list = this.listenerMap.get(typeID); if (list == null) { list = new Array<>(10); this.listenerMap.put(typeID, list); } if (list.contains(listener, false)) { throw new IllegalStateException("listener for typeID '" + typeID + "' and hash " + listener + " is already registered."); } list.add(listener); } }
EventManager { public <T extends EventData> void addListener (int typeID, EventListener<T> listener) { Objects.requireNonNull(listener); Array<EventListener> list = this.listenerMap.get(typeID); if (list == null) { list = new Array<>(10); this.listenerMap.put(typeID, list); } if (list.contains(listener, false)) { throw new IllegalStateException("listener for typeID '" + typeID + "' and hash " + listener + " is already registered."); } list.add(listener); } EventManager(String name, boolean setAsGlobal); }
EventManager { public <T extends EventData> void addListener (int typeID, EventListener<T> listener) { Objects.requireNonNull(listener); Array<EventListener> list = this.listenerMap.get(typeID); if (list == null) { list = new Array<>(10); this.listenerMap.put(typeID, list); } if (list.contains(listener, false)) { throw new IllegalStateException("listener for typeID '" + typeID + "' and hash " + listener + " is already registered."); } list.add(listener); } EventManager(String name, boolean setAsGlobal); void update(); void update(int maxMillis); void queueEvent(EventData event); void triggerEvent(EventData event); void addListener(int typeID, EventListener<T> listener); void removeListener(int typeID, EventListener<T> listener); static final EventManager getInstance(); }
EventManager { public <T extends EventData> void addListener (int typeID, EventListener<T> listener) { Objects.requireNonNull(listener); Array<EventListener> list = this.listenerMap.get(typeID); if (list == null) { list = new Array<>(10); this.listenerMap.put(typeID, list); } if (list.contains(listener, false)) { throw new IllegalStateException("listener for typeID '" + typeID + "' and hash " + listener + " is already registered."); } list.add(listener); } EventManager(String name, boolean setAsGlobal); void update(); void update(int maxMillis); void queueEvent(EventData event); void triggerEvent(EventData event); void addListener(int typeID, EventListener<T> listener); void removeListener(int typeID, EventListener<T> listener); static final EventManager getInstance();  }