Created
August 5, 2014 04:31
-
-
Save fsarradin/0f4b16938e0c010ce40c to your computer and use it in GitHub Desktop.
IntelliJ IDEA live template for enum with by-name behavior
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
private static final Map<String, $CLASS_NAME$> $VAR_CLASS_NAME$sByName = create$CLASS_NAME$sByName(); | |
private final String name; | |
$CLASS_NAME$() { | |
this(null); | |
} | |
$CLASS_NAME$(String name) { | |
this.name = name; | |
} | |
protected static Map<String, $CLASS_NAME$> create$CLASS_NAME$sByName() { | |
Map<String, $CLASS_NAME$> $VAR_CLASS_NAME$s = new HashMap<>(); | |
for ($CLASS_NAME$ $VAR_CLASS_NAME$ : $CLASS_NAME$.values()) { | |
if ($VAR_CLASS_NAME$.name != null) { | |
$VAR_CLASS_NAME$s.put($VAR_CLASS_NAME$.name, $VAR_CLASS_NAME$); | |
} | |
} | |
return Collections.unmodifiableMap($VAR_CLASS_NAME$s); | |
} | |
public static $CLASS_NAME$ of(String name) { | |
if (!$VAR_CLASS_NAME$sByName.containsKey(name)) { | |
return $END$; | |
} | |
return $VAR_CLASS_NAME$sByName.get(name); | |
} |
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
CLASS_NAME: className() | |
VAR_CLASS_NAME: decapitalize(CLASS_NAME) / item |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment