
org.carrot2.util.EnumUtils Maven / Gradle / Ivy
package org.carrot2.util;
/**
* Various utility methods for working with Java 5 enum types.
*/
public class EnumUtils
{
/**
* Returns the enum instance corresponding to the provided name
or
* defaultValue
if no enum value corresponds to name
.
*/
public static > T valueOf(String name, Class enumClass,
T defaultValue)
{
if (StringUtils.isNotBlank(name))
{
try
{
return Enum.valueOf(enumClass, name);
}
catch (IllegalArgumentException e)
{
return defaultValue;
}
}
else
{
return defaultValue;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy