-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
452d1a7
commit 3536441
Showing
1 changed file
with
21 additions
and
5 deletions.
There are no files selected for viewing
26 changes: 21 additions & 5 deletions
26
common/src/main/java/journeymap/common/api/event/impl/EventFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,40 @@ | ||
package journeymap.common.api.event.impl; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class EventFactory | ||
public class EventFactory<T extends JourneyMapEvent> | ||
{ | ||
public static final Map<Class<?>, List<EventImpl<?>>> EVENTS; | ||
private final Map<Class<T>, EventImpl<T>> events; | ||
|
||
private static final EventFactory INSTANCE; | ||
|
||
static | ||
{ | ||
EVENTS = new HashMap<>(); | ||
INSTANCE = new EventFactory<>(); | ||
} | ||
|
||
public EventFactory() | ||
{ | ||
this.events = new HashMap<>(); | ||
} | ||
|
||
public static <E> Event<E> create(Class<E> clazz) | ||
{ | ||
EventImpl<E> impl = new EventImpl<>(clazz); | ||
EVENTS.putIfAbsent(clazz, List.of(impl)); | ||
INSTANCE.events.putIfAbsent(clazz, impl); | ||
return impl; | ||
} | ||
|
||
public Map<Class<T>, EventImpl<T>> getEvents() | ||
{ | ||
return this.events; | ||
} | ||
|
||
public static <K extends JourneyMapEvent> EventFactory<K> getInstance() | ||
{ | ||
return INSTANCE; | ||
} | ||
} | ||
|
||
|