org.dspace.authority.util.EnumUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dspace-api Show documentation
Show all versions of dspace-api Show documentation
DSpace core data model and service APIs.
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.authority.util;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
/**
* @author Antoine Snyers (antoine at atmire.com)
* @author Kevin Van de Velde (kevin at atmire dot com)
* @author Ben Bosman (ben at atmire dot com)
* @author Mark Diggory (markd at atmire dot com)
*/
public class EnumUtils {
/**
* log4j logger
*/
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(EnumUtils.class);
/**
* Default constructor
*/
private EnumUtils() { }
private static String getEnumName(String value) {
return StringUtils.isNotBlank(value) ?
value.toUpperCase().trim().replaceAll("[^a-zA-Z]", "_")
: null;
}
public static > E lookup(Class enumClass, String enumName) {
try {
return Enum.valueOf(enumClass, getEnumName(enumName));
} catch (Exception ex) {
log.warn("Did not find an " + enumClass.getSimpleName() + " for value '" + enumName + "'");
return null;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy