Skip to content

Instantly share code, notes, and snippets.

@gastaldi
Last active December 21, 2015 21:28
Show Gist options
  • Select an option

  • Save gastaldi/6368034 to your computer and use it in GitHub Desktop.

Select an option

Save gastaldi/6368034 to your computer and use it in GitHub Desktop.
/**
* A CommandRegistry stores all the available Command objects
*/
public interface CommandRegistry{
/**
* Queries the CommandRegistry for a command
* @param name The command name
* @return Command associated with the name
* @throws CommandNotFoundException if no command can be found for the given name
*/
Command getCommand(String name) throws CommandNotFoundException;
/**
* Returns a read-only Map of this registry.
*/
Map<String, Command> asMap();
}
@gastaldi

Copy link
Copy Markdown
Author
public class MutableCommandRegistry implements CommandRegistry {
      private Map<String, Command> registry = new HashMap<String,Command>();   

     public Command getCommand(String name)  throws CommandNotFoundException {      
          Command cmd = registry.get(name);
         if (cmd == null) throw new CommandNotFoundException(name);
         return cmd;
      }

     public void addCommand(String name, Command cmd) {
         registry.put(name,cmd);
     }
    public removeCommand(String name) {
       registry.remove(name);
    }




}

@gastaldi

Copy link
Copy Markdown
Author

MutableCommandRegistry registry = new MutableCommandRegistry();
registry.add ....
....
AeshConsoleBuilder.commandRegistry(registry);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment