Skip to content

Instantly share code, notes, and snippets.

@codethereforam
Created June 12, 2019 05:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codethereforam/b722eccaba1e41acbe48c1d3070525e5 to your computer and use it in GitHub Desktop.
Save codethereforam/b722eccaba1e41acbe48c1d3070525e5 to your computer and use it in GitHub Desktop.
IDEA枚举文件模板
#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