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

exchange.apexpro.connector.impl.utils.EnumLookup Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
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);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy