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;
}
}