database enum handle implementation
This commit is contained in:
parent
bd2807fbdf
commit
419c4d64f8
|
@ -0,0 +1,16 @@
|
|||
package eu.eudat.commons.enums;
|
||||
|
||||
import eu.eudat.data.converters.enums.DatabaseEnum;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class EnumUtils {
|
||||
public static <EnumType extends Enum<EnumType> & DatabaseEnum<EnumValue>, EnumValue> Map<EnumValue, EnumType> getEnumValueMap(Class<EnumType> enumType){
|
||||
HashMap<EnumValue, EnumType> map = new HashMap<>();
|
||||
for (EnumType v : enumType.getEnumConstants()) {
|
||||
map.put(v.getValue(), v);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
|
@ -27,13 +27,7 @@ public enum ProviderType implements DatabaseEnum<Integer> {
|
|||
|
||||
public Integer getValue() { return this.value; }
|
||||
|
||||
private static final Map<Integer, ProviderType> map;
|
||||
static {
|
||||
map = new HashMap<>();
|
||||
for (ProviderType v : ProviderType.values()) {
|
||||
map.put(v.getValue(), v);
|
||||
}
|
||||
}
|
||||
private static final Map<Integer, ProviderType> map = EnumUtils.getEnumValueMap(ProviderType.class);
|
||||
public static ProviderType of(Integer i) {
|
||||
return map.get(i);
|
||||
}
|
||||
|
|
|
@ -20,13 +20,7 @@ public enum Status implements DatabaseEnum<Integer> {
|
|||
return value;
|
||||
}
|
||||
|
||||
private static final Map<Integer, Status> map;
|
||||
static {
|
||||
map = new HashMap<>();
|
||||
for (Status v : Status.values()) {
|
||||
map.put(v.getValue(), v);
|
||||
}
|
||||
}
|
||||
private static final Map<Integer, Status> map = EnumUtils.getEnumValueMap(Status.class);
|
||||
|
||||
public static Status of(Integer i) {
|
||||
return map.get(i);
|
||||
|
|
Loading…
Reference in New Issue