database enum handle implementation

This commit is contained in:
Efstratios Giannopoulos 2023-10-17 13:45:59 +03:00
parent bd2807fbdf
commit 419c4d64f8
3 changed files with 18 additions and 14 deletions

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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);