Created
April 28, 2013 12:45
-
-
Save idefixcert/5476786 to your computer and use it in GitHub Desktop.
Parse Enum
This file contains hidden or 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; | |
import java.util.Map; | |
@SuppressWarnings("boxing") | |
public enum IndexStrategy { | |
DEFAULT(0), FASTINDEX(1), FINEGRAINED(2); | |
private final int value; | |
private IndexStrategy(int value) { | |
this.value = value; | |
} | |
public int getValue() { | |
return value; | |
} | |
private static final Map<Integer, IndexStrategy> intToEnum = new HashMap<Integer, IndexStrategy>(); | |
static { // Initialize map from constant int to enum constant | |
for (IndexStrategy op : values()) | |
intToEnum.put(op.getValue(), op); | |
} | |
// Returns Operation for int, or null if int is invalid | |
public static IndexStrategy fromInt(int value) { | |
return intToEnum.get(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment