octavian-nita
2/24/2016 - 4:34 PM

Type-conversion utilities

Type-conversion utilities

public static <TO extends Enum<TO>, FROM extends Enum<FROM>> TO convert(Class<TO> toType, FROM value) {
    return convert(toType, value, null);
}

public static <TO extends Enum<TO>, FROM extends Enum<FROM>> TO convert(Class<TO> toType, FROM value, TO defaultValue) {
    return value == null ? defaultValue : Enum.valueOf(toType, value.name());
}