org.unix4j.convert.EnumConverters Maven / Gradle / Ivy
package org.unix4j.convert;
public class EnumConverters {
public static class StringToEnumConverter> implements ValueConverter {
private final Class enumClass;
public StringToEnumConverter(Class enumClass) {
this.enumClass = enumClass;
}
@Override
public E convert(Object value) throws IllegalArgumentException {
if (value != null) {
final String name = value.toString();
try {
return Enum.valueOf(enumClass, name);
} catch (IllegalArgumentException e) {
return null;
}
}
return null;
}
};
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy