Created
October 17, 2017 04:33
-
-
Save takaki/8f86ee83473a86d4e5a61f2dbc95dba6 to your computer and use it in GitHub Desktop.
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
import java.util.HashMap; | |
public enum SampleEnum { | |
AAA(1), | |
BBB(2), | |
CCC(3); | |
public static final int SIZE = java.lang.Integer.SIZE; | |
private int intValue; | |
private static HashMap<Integer, SampleEnum> mappings = new HashMap<>(); | |
private static HashMap<Integer, SampleEnum> getMappings() { | |
return mappings; | |
} | |
SampleEnum(int value) { | |
intValue = value; | |
getMappings().put(value, this); | |
} | |
public int getValue() { | |
return intValue; | |
} | |
public static SampleEnum forValue(int value) { | |
return getMappings().get(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment