aQute.bnd.build.model.conversions.EnumConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of biz.aQute.bndlib Show documentation
Show all versions of biz.aQute.bndlib Show documentation
bndlib: A Swiss Army Knife for OSGi
package aQute.bnd.build.model.conversions;
public class EnumConverter> implements Converter {
private final Class enumType;
private final E defaultValue;
public static > EnumConverter create(Class enumType) {
return new EnumConverter(enumType, null);
}
public static > EnumConverter create(Class enumType, E defaultValue) {
return new EnumConverter(enumType, defaultValue);
}
private EnumConverter(Class enumType, E defaultValue) {
this.enumType = enumType;
this.defaultValue = defaultValue;
}
public E convert(String input) throws IllegalArgumentException {
if (input == null)
return defaultValue;
return Enum.valueOf(enumType, input);
}
@Override
public E error(String msg) {
return null;
}
}