Skip to content

Instantly share code, notes, and snippets.

@doom369
Created August 18, 2020 16:32
Show Gist options
  • Save doom369/ba8bce7bae49d26b15ae8d2db17e1972 to your computer and use it in GitHub Desktop.
Save doom369/ba8bce7bae49d26b15ae8d2db17e1972 to your computer and use it in GitHub Desktop.
Map<String, T> enumConstantDirectory() {
Map<String, T> directory = enumConstantDirectory;
if (directory == null) {
T[] universe = getEnumConstantsShared();
if (universe == null)
throw new IllegalArgumentException(
getName() + " is not an enum type");
directory = new HashMap<>((int)(universe.length / 0.75f) + 1);
for (T constant : universe) {
directory.put(((Enum<?>)constant).name(), constant);
}
enumConstantDirectory = directory;
}
return directory;
}
private transient volatile Map<String, T> enumConstantDirectory;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment