All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.carrot2.util.EnumUtils Maven / Gradle / Ivy

There is a newer version: 0.2.13
Show newest version
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