枚举——实践中的应用搜集

public enum XXXXEnum {

DRAFT(1,"草稿"),
ONE_LEVEL_AUDIT(2,"待一级"),
ONE_LEVEL_AUDIT_REJECT(3,"一级驳回"),
TWO_LEVEL_AUDIT(4,"待二级"),
TWO_LEVEL_AUDIT_REJECT(5,"二级驳回"),

BUSINESS_AUDIT(9,"业务"),
INFO_UPDATE_BUSINESS_AUDIT(10,"信息更新审核"),

INFO_UPDATE_AUDIT(6,"待更新审核"),
INFO_UPDATE_AUDIT_REJECT(8,"信息更新驳回") ,

AUDIT_APPROVAL(7,"通过"),;

private int key;
private String value;

private XXXXEnum(int key, String value) {
    this.key = key;
    this.value = value;
}

public static XXXXEnum getEnumByKey(int key) {
for (XXXXEnum c : XXXXEnum.values()) {
if (key == c.getKey()) {
return c;
}
}
return null;
}

public static XXXXEnum getEnumByVal(String val) {
    for (XXXXEnum c : XXXXEnum.values()) {
        if (val.equals(c.getValue())) {
            return c;
        }
    }
    return null;
}


public static List getListEnum(){
    List enumList = new ArrayList();
    for (XXXXEnum c : XXXXEnum.values()) {
        enumList.add(c);
    }
    return enumList;
}

public static List getListKeyEnum(){
    List enumListKey = new ArrayList();
    for (XXXXEnum c : XXXXEnum.values()) {
        enumListKey.add(c.getKey());
    }
    return enumListKey;
}

public static XXXXEnum changeXXXXStatus(SupplierCommon supplierCommon){
    int status = supplierCommon.getSupplierType();
    switch (status){
        case 0:
            return ONE_LEVEL_AUDIT;
        case 1:
            return ONE_LEVEL_AUDIT;
        case 2:
            return ONE_LEVEL_AUDIT;
        case 5:
            return TWO_LEVEL_AUDIT;
        case 7:
            return INFO_UPDATE_AUDIT;
        default:
            return DRAFT;
    }

}


//获取枚举map
public static HashMap getMapStates(){
    HashMap hashMap = new HashMap();
    for(XXXXEnum s:XXXXEnum.values()){
        hashMap.put(s.getKey()+"",s.getValue());
    }
    return hashMap;
}

public int getKey() {
    return key;
}

public String getValue() {
    return value;
}

}

你可能感兴趣的:(枚举——实践中的应用搜集)