exchange.apexpro.connector.impl.utils.EnumLookup Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apexpro-connector-java Show documentation
Show all versions of apexpro-connector-java Show documentation
A lightweight library to ApeX-Protocol
package exchange.apexpro.connector.impl.utils;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class EnumLookup> {
Logger logger = LoggerFactory.getLogger(EnumLookup.class);
private final Map map = new HashMap<>();
private final String enumName;
public EnumLookup(Class clazz) {
enumName = clazz.getName();
for (T item : EnumSet.allOf(clazz)) {
map.put(item.toString(), item);
}
}
public T lookup(String name) {
if (!map.containsKey(name)) {
logger.error("[Enum] Cannot found " + name + " in Enum " + enumName);
return null;
}
return map.get(name);
}
}