package io.github.phantamanta44.shlgl.event;

import java.util.HashMap;
import java.util.Map;

/**
 * Handles the dispatching of events to individual {@link EventStream}s.
 * @author Evan Geng
 */
public class EventBus { // TODO Document

    private final Map<Class<? extends Event>, EventStream<?>> eventStreams;

    public EventBus() {
        eventStreams = new HashMap<>();
        // TODO Register default event types
    }

    public void registerEvent(Class<? extends Event> eventType) {
        eventStreams.put(eventType, new EventStream<>());
    }

    public void post(Event event) {
        eventStreams.entrySet().stream()
                .filter(e -> e.getKey().isAssignableFrom(event.getClass()))
                .forEach(e -> e.getValue().post(event)); // FIXME Cast this somehow
    }

}

@@ -217,26 +217,84 @@
 us %7B
- // TODO Document%0A
+%0A%0A    /**%0A     * The mapping of event types to %7B@link EventStream%7Ds.%0A     */
 %0A   
@@ -351,11 +351,8 @@
 ream
-%3C?%3E
 %3E ev
@@ -364,16 +364,78 @@
 reams;%0A%0A
+    /**%0A     * Creates and initializes the event bus.%0A     */%0A
     publ
@@ -534,32 +534,124 @@
 nt types%0A    %7D%0A%0A
+    /**%0A     * Registers an event type.%0A     * @param eventType The new event type.%0A     */%0A
     public void 
@@ -761,24 +761,168 @@
 ());%0A    %7D%0A%0A
+    /**%0A     * Dispatches an event to all eligible listeners.%0A     * @param event The event to post.%0A     */%0A    @SuppressWarnings(%22unchecked%22)%0A
     public v
@@ -1122,35 +1122,8 @@
 t));
- // FIXME Cast this somehow
 %0A   

Fix casting issue and document event bus