package org.wanna.jabbot;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wanna.jabbot.command.Command;
import org.wanna.jabbot.command.CommandFactory;
import org.wanna.jabbot.command.CommandNotFoundException;

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

/**
 * @author vmorsiani <vmorsiani>
 * @since 2014-05-31
 */
public class JabbotCommandFactory implements CommandFactory {
	final Logger logger = LoggerFactory.getLogger(JabbotCommandFactory.class);

	public Command create(String commandName) throws CommandNotFoundException {
		Command command = registry.get(commandName);
		if(command == null){
			throw new CommandNotFoundException(commandName);
		}
		return command;
	}

	@Override
	public Map<String, Command> getAvailableCommands() {
		return (registry ==null? new HashMap<String,Command>(): registry);
	}

	private Map<String,Command> registry = new HashMap<>();
	@Override
	public void register(String commandName, Command command) {
		logger.debug("registering command {} with class {}",commandName,command.getClass());
		registry.put(commandName, command);
	}
}

@@ -242,20 +242,16 @@
 va.util.
-Hash
 Map;%0Aimp
@@ -260,24 +260,28 @@
 t java.util.
+Tree
 Map;%0A%0A/**%0A *
@@ -792,28 +792,28 @@
 ==null? new 
-Hash
+Tree
 Map%3CString,C
@@ -886,12 +886,12 @@
 new 
-Hash
+Tree
 Map%3C

use TreeMap instead of HashMap so that commands are sorted