import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
/** * * Define the error code and the error message * * Attention:Error code before 300 is reserve for system define error.Add you * error code after 300. * * @author c_rli * * @version 1.0 Apr 3, 2009 */
public enum ErrorCode {
/** The <tt>enum</tt> of the CONTACT_ID_EMPTY */
CONTACT_ID_EMPTY("CM01",
"The member Id must not be empty", ""),
/** The <tt>enum</tt> of the NO_EXCHANGE_HISTORY */
NO_EXCHANGE_HISTORY("CM02", "No Exchange History Found",
""),
UNABLE_TO_INSERT_A_RECORD("ERR0419",
"Unable to insert a record.", ""),
UNABLE_TO_UPDATE_A_RECORD("ERR0420",
"Unable to update a record.", ""),
UNABLE_TO_DELETE_A_RECODE("ERR0421",
"Unable to delete a Record.", "");
/** The error code */
private String code;
/** The error description */
private String description;
/** The error type */
private String type;
/** * * The <tt>Map</tt> of the error code */
private static final Map<String, ErrorCode> LOOKUP = new HashMap<String, ErrorCode>();
static {
for (ErrorCode s : EnumSet.allOf(ErrorCode.class)) {
LOOKUP.put(s.getCode(), s);
}
}
/** * * @param code * The error code * * @param description * The error description * * @param type * the error type */
private ErrorCode(String code, String description, String type) {
this.description = description;
this.code = code;
this.type = type;
}
public String getDescription() {
return description;
}
public String getCode() {
return code;
}
public String getType() {
return type;
}
/** * * The static method to get <tt>ErrorCode</tt> instance by the error code * * * * @param code * The error code * * @return the instance of the <tt>ErrorCode</tt> */
public static ErrorCode get(String code) {
return LOOKUP.get(code);
}
public static void main(String[] args){ ErrorCode error=ErrorCode.get("ERR0419"); System.out.println(error.getDescription()+error.CREDIT_CARD_CITY_EMPTY); }}
相关资源:Java枚举类使用场景及实例解析