I've recently coded an event manager with performance as the main factor. I'd like to know what you think of it and what could be made better.
public class EventManager {
public static EventManager mouseRightClick = new EventManager(EventType.mouseRightClick), mouseLeftClick = new EventManager(EventType.mouseLeftClick);
public final EventType type;
public List<Listener> listeners = new ArrayList<Listener>();
private EventManager(EventType type){
this.type = type;
}
public void registerListener(Listener l){
if (!listeners.contains(l)){
listeners.add(l);
}
}
public void unregisterListener(Listener l){
listeners.remove(l);
}
public void dispatchEvent(Event e){
for (int i = listeners.size() - 1; i >= 0; i--){
listeners.get(i).onEvent(e, type);
}
}
}
That's basically all the code, and I've tried to keep it as simple as possible.