1 package net.pterodactylus.irc.connection;
3 import java.util.HashMap;
7 import net.pterodactylus.irc.Reply;
8 import net.pterodactylus.irc.Source;
10 import com.google.common.base.Optional;
11 import com.google.common.eventbus.EventBus;
14 * Handler that can send events associated with commands to an {@link
17 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
19 public class SimpleCommandHandler implements Handler {
21 private final Map<String, EventProcessor> commandEventSenders =
23 private final EventBus eventBus;
25 public SimpleCommandHandler(EventBus eventBus) {
26 this.eventBus = eventBus;
29 public SimpleCommandHandler addCommand(String command,
30 EventProcessor eventProcessor) {
31 commandEventSenders.put(command.toLowerCase(), eventProcessor);
36 public boolean willHandle(Reply reply) {
37 return commandEventSenders.containsKey(reply.command().toLowerCase());
41 public void handleReply(Reply reply) {
42 EventProcessor eventProcessor =
43 commandEventSenders.get(reply.command().toLowerCase());
44 eventBus.post(eventProcessor.createEvent(reply.source(),
49 * Interface for event creators.
51 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
54 public static interface EventProcessor {
56 Object createEvent(Optional<Source> source, List<String> parameters);