枚举获取值的静态方法

399 阅读1分钟
public enum EndpointType {

    PROCESS(1), DMN(2), FORM(3), CONTENT(4), CMMN(5), APP(6);

    private static Map<Integer, EndpointType> map = new HashMap<>();

    static {
        for (EndpointType endpointType : EndpointType.values()) {
            map.put(endpointType.endpointCode, endpointType);
        }
    }

    private final int endpointCode;

    EndpointType(int endpointCode) {
        this.endpointCode = endpointCode;
    }

    public int getEndpointCode() {
        return this.endpointCode;
    }

    public static EndpointType valueOf(int endpointCode) {
        return map.get(endpointCode);
    }

}