jtstate.java
来自「Java Pattern Oriented Framework (Jt) 是为了」· Java 代码 · 共 106 行
JAVA
106 行
package Jt;
/**
* Jt Implementation of the State pattern.
*/
public class JtState extends JtObject {
public static final String JtCLASS_NAME = JtState.class.getName();
private static final long serialVersionUID = 1L;
private Object concreteState;
public JtState () {
}
/**
* Specifies the concrete state.
*
* @param state state
*/
public void setConcreteState (Object state) {
this.concreteState = state;
}
/**
* Returns the concrete state.
*/
public Object getConcreteState () {
return (concreteState);
}
/**
* Process object messages.
* <ul>
* </ul>
*/
public Object processMessage (Object event) {
String msgid = null;
JtMessage e = (JtMessage) event;
//Object content;
//Object data;
if (e == null)
return null;
msgid = (String) e.getMsgId ();
if (msgid == null)
return null;
//content = e.getMsgContent();
//data = e.getMsgData ();
//return (super.processMessage (event));
if (msgid.equals (JtObject.JtREMOVE)) {
return (null);
}
if (concreteState == null) {
handleError ("processMessage: concreteState attribute must be set");
return (null);
}
return (((JtInterface) concreteState).processMessage (event));
}
/**
* Demonstrates the messages processed by JtState
*/
public static void main(String[] args) {
JtFactory factory = new JtFactory ();
JtState state;
// Create an instance of JtState
state = (JtState) factory.createObject (JtState.JtCLASS_NAME, "state");
// Remove the object
factory.removeObject (state);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?