Created
June 12, 2019 05:11
-
-
Save codethereforam/b722eccaba1e41acbe48c1d3070525e5 to your computer and use it in GitHub Desktop.
IDEA枚举文件模板
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end | |
#parse("File Header.java") | |
public enum ${NAME} { | |
; | |
/** | |
* enum value | |
*/ | |
private final int value; | |
/** | |
* enum desc | |
*/ | |
private final String desc; | |
${NAME}(int value, String desc) { | |
this.value = value; | |
this.desc = desc; | |
} | |
/** | |
* get value | |
* | |
* @return value | |
*/ | |
public int getValue() { | |
return this.value; | |
} | |
/** | |
* get desc | |
* | |
* @return desc | |
*/ | |
public String getDesc() { | |
return desc; | |
} | |
/** | |
* static map {'key': 'value', 'value': '${NAME}'} | |
*/ | |
private static final Map<Integer, ${NAME}> MAP = Arrays.stream(${NAME}.values()) | |
.collect(Collectors.toMap(${NAME}::getValue, e -> e)); | |
/** | |
* get ${NAME} by value | |
* | |
* @param value value | |
* @return ${NAME} | |
*/ | |
public static ${NAME} getByValue(Integer value) { | |
return MAP.get(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment