读书人

Enum良好的自小弟我描述性便于封装业务

发布时间: 2012-09-21 15:47:26 作者: rapoo

Enum良好的自我描述性便于封装业务状态
代码:


public enum RequestFromType {
errorType(0,"errorType"), orderCustomerRefund(1,"orderCustomerRefund"),orderServiceRefund(1,"orderServiceRefund"),afterRefund(3,"afterRefund");

private int code;

private String comments;


RequestFromType(int code,String comments){
this.code=code;
this.comments=comments;
}
public static RequestFromType valueOf(int code){
for(RequestFromType requestFromType : values()){
if(requestFromType.code==code){
return requestFromType;
}
}
return errorType;
}

public static RequestFromType valueOfComments(String comments){
for(RequestFromType requestFromType : values()){
if(requestFromType.comments.equalsIgnoreCase(comments)){
return requestFromType;
}
}
return errorType;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}

}

读书人网 >软件架构设计

热点推荐