Skip to content

Instantly share code, notes, and snippets.

@magmax
Created August 15, 2011 01:52
Show Gist options
  • Save magmax/1145589 to your computer and use it in GitHub Desktop.
Save magmax/1145589 to your computer and use it in GitHub Desktop.
Enumerados con relación doble en Java
public enum NaveInterestelar {
PATRULLERA(-1),
ESCOLTA(0),
RESERVA(1000),
;
private int value;
private static final Map<Integer,NaveInterestelar> lookup
= new HashMap<Integer,NaveInterestelar>();
static {
for (NaveInterestelar each : EnumSet.allOf(NaveInterestelar.class)) {
lookup.put(each.value, each);
}
}
NaveInterestelar(int value) {
this.value = value;
}
public static NaveInterestelar get(int v) {
return lookup.get(v);
}
public int getCode() {
return value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment