枚举类:
public enum ActionType {
WALK("walk", "走路"),
SLEEP("sleep", "睡觉"),
EAT("eat", "吃饭"),
BATH("bath", "洗澡"),
NONE("none", "无");
private final String action;
private final String type;
ActionType(String action, String type) {
this.action = action;
this.type = type;
}
public static ActionType getActionType(String action){
for (ActionType value : ActionType.values()) {
if (value.getType().equals(action)){
return value;
}
}
return NONE;
}
public String getAction() {
return action;
}
public String getType() {
return type;
}
}
业务类
import com.example.ActionType;
public class Executor {
public void execute(){
ActionType eat = ActionType.getActionType("吃饭");
switch (eat){
case WALK:
return;
case EAT:
}
}
}