📄 commandfactory.java
字号:
/**
*
*/
package agenda.ctrl;
import java.util.*;
import agenda.cmd.Command;
/**
* class definition for command factory
*
* @author Cyberpet
*
*/
public class CommandFactory {
private HashMap<String, Command> cmdTable = new HashMap<String, Command>();
/*
* add command into the hashmap
*/
public boolean addCmd(Command cmd) {
if (cmd != null)
return this.cmdTable.put(cmd.getName(), cmd) != null;
else
return false;
}
/*
* get command by name
*/
public Command getCmdByName(String name) {
return this.cmdTable.get(name);
}
public String toString() {
String res = new String();
Collection<Command> Col = this.cmdTable.values();
for (Command cmd : Col)
res += cmd.toString();
return res;
}
/**
* static class for Singleton design pattern, instance of CommandFactory
* will be created when the first time you make a call to
* CommandFactory.getInstance
*
* @author Cyberpet
* @see CommandFactory#getInstance()
*/
static class CommandFactorySingletonHolder {
static CommandFactory instance = new CommandFactory();
}
/**
* get the only instance of CommandFactory
*
* @return CommandFactory
* @see CommandFactory
*/
public static CommandFactory getInstance() {
return CommandFactorySingletonHolder.instance;
}
/**
* @param args
* @return void
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -