Skip to content

Instantly share code, notes, and snippets.

@idefixcert
Created April 28, 2013 12:45
Show Gist options
  • Save idefixcert/5476786 to your computer and use it in GitHub Desktop.
Save idefixcert/5476786 to your computer and use it in GitHub Desktop.
Parse Enum
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