枚举的使用(限foton)

使用:

/**
* 服务真实性标签
* 
* @param realRepairs
* 真实维修单数
* @param totalRepairs
* 总单数
* @return
*/
public static AuthenticityType getAuthenticityTag(int realRepairs, int totalRepairs) {
double rate = ArithUtil.div(realRepairs, totalRepairs);
if (rate >= 0.9) {
return AuthenticityType.TOP90;
} else if (rate >= 0.6) {
return AuthenticityType.TOP60;
} else {
return AuthenticityType.UNDER60;
}
}

 

POJO

public class ServicerProfile {

private Long servicerId;
private String servicerCode;
private String servicerName;

public enum AuthenticityType {

TOP90(31, "优秀"), TOP60(32, "良好"), UNDER60(33, "不及格");

private final int value;
private final String description;

private static final Map<Integer, AuthenticityType> valuesMap = Maps.newHashMap();
private static final Map<String, AuthenticityType> namesMap = Maps.newHashMap();
static {
for (AuthenticityType type : AuthenticityType.values()) {
valuesMap.put(type.getValue(), type);
namesMap.put(type.name(), type);
}
}

private AuthenticityType(int value, String description) {
this.value = value;
this.description = description;
}

public static AuthenticityType parse(Integer value) {
if (value == null) {
return null;
}

return valuesMap.get(value);
}

public static AuthenticityType parse(String name) {
if (name == null) {
return null;
}

return namesMap.get(name);
}

public Integer getValue() {
return value;
}

public String getDescription() {
return description;
}
}

}

  

posted @ 2019-05-31 10:18  蔡徐坤1987  阅读(136)  评论(0编辑  收藏  举报