?? 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
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -