public enum IdCardTypeEnum implements ValueObject<IdCardTypeEnum> {居民身份证("0", "居民身份证"),护照("1", "护照"),军官证("2", "军官证"),驾照("3", "驾照"),出生证明("4", "出生证明"),户口簿("5", "户口簿"),港澳居民来往内地通行证("6", "港澳居民来往内地通行证"),台湾居民来往大陆通行证("7", "台湾居民来往大陆通行证"),港澳台身份证("H", "港澳台身份证"),外国人永久居留身份证("I", "外国人永久居留身份证"),港澳台居民居住证("K", "港澳台居民居住证"),其他("8", "其他");private String value;private String label;IdCardTypeEnum(String value, String label) {this.value = value;this.label = label;}public String getLabel() {return label;}public String getValue() {return value;}/*** 根据匹配value的值获取Label** @param value* @return*/public static String getLabelByValue(String value) {if (StringUtils.isBlank(value)) {return "";}for (IdCardTypeEnum s : IdCardTypeEnum.values()) {if (value.equals(s.getValue())) {return s.getLabel();}}return "";}/*** 获取StatusEnum** @param value* @return*/public static IdCardTypeEnum getStatusEnum(String value) {if (StringUtils.isBlank(value)) {return null;}for (IdCardTypeEnum s : IdCardTypeEnum.values()) {if (value.equals(s.getValue())) {return s;}}return null;}@Overridepublic boolean sameValueAs(final IdCardTypeEnum other) {return this.equals(other);} }
public class test {public static void main(String[] args) {System.out.println("________________获得value________________");System.out.println(IdCardTypeEnum.军官证.getValue());System.out.println("_________________获得label________________");System.out.println(IdCardTypeEnum.军官证.getLabel());System.out.println("__________________根据value获得label_________________");System.out.println(IdCardTypeEnum.getLabelByValue("2"));System.out.println("________________获得所有的value___________________");final IdCardTypeEnum[] values = IdCardTypeEnum.values();System.out.println(values.length);for (int i = 0; i < values.length; i++) {System.out.println(values[i]);}System.out.println("__________________判断有没有这个枚举类_________________");System.out.println(IdCardTypeEnum.getStatusEnum("lll").getValue());System.out.println("___________________________________");} }