Example usage for java.util Map containsKey

List of usage examples for java.util Map containsKey

Introduction

In this page you can find the example usage for java.util Map containsKey.

Prototype

boolean containsKey(Object key);

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:com.iisigroup.cap.utils.CapXmlUtil.java

private static void putValue(Map<String, Object> map, String key, Object value) {
    if (map.containsKey(key)) {
        Object j = map.get(key);/*from   w  ww . j  a  va  2 s  .c om*/
        if (j instanceof JsonArray) {
            ((JsonArray) j).add(GsonUtil.objToJson(value));
        } else {
            JsonArray ja = new JsonArray();
            ja.add(GsonUtil.objToJson(j));
            ja.add(GsonUtil.objToJson(value));
            map.put(key, ja);
        }
    } else {
        map.put(key, value);
    }

}

From source file:Main.java

/**
 * Set the fields' value./*from www . j a  v a2s  . com*/
 * 
 * @param bean
 * @param valMap
 */
public static void setFieldValues(Object bean, Map<String, Object> valMap) {
    Class<?> cls = bean.getClass();
    //Get all fields.
    Field[] fields = cls.getDeclaredFields();

    for (Field field : fields) {
        if (valMap.containsKey(field.getName())) {
            field.setAccessible(true);
            try {
                field.set(bean, valMap.get(field.getName()));
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.stimulus.archiva.language.AnalyzerFactory.java

public static Analyzer getAnalyzer(String language, Operation operation) {

    if (language == null) {
        language = "en";
    }//  w w w .j  ava  2s . co  m
    Analyzer analyzer = null;
    logger.debug("getAnalyzer() {language='" + language + "'}");
    String className = null;

    try {
        Map analyzers = Config.getConfig().getSearch().getSearchAnalyzers();
        if (analyzers.containsKey(language)) {
            className = (String) analyzers.get(language);
            logger.debug("successfully obtained class name for search analyzer {language='" + language
                    + "', class='" + className + "'}");
        } else {
            className = (String) analyzers.get(Config.getConfig().getIndex().getIndexLanguage());
            logger.debug("email language is unsupported. using default language.  {language='" + language
                    + "', class='" + className + "'}");
        }
        Class analyzerClass = Class.forName(className);
        if (analyzerClass == null) {
            logger.error(
                    "failed to return search analyzer. are the analyzers specified correctly in server.conf? {language='"
                            + language + "', class='" + className + "'}");
            logger.error(
                    "recovering by returning default archiver analyzer. indexing and search may be impaired. urgent fix required.");
            analyzer = new ArchivaAnalyzer();
        } else {
            logger.debug("retrieved analyzer class {language='" + language + "', class='" + className + "'}");
            analyzer = (Analyzer) analyzerClass.newInstance();
            logger.debug(
                    "analyzer class instance created {language='" + language + "', class='" + className + "'}");
        }
        logger.debug("successfully returned search analyzer {language='" + language + "', class='" + className
                + "'}");
    } catch (Exception e) {
        logger.error(
                "failed to return search analyzer. are the analyzers specified correctly in server.conf? {language='"
                        + language + "', class='" + className + "'}",
                e);
        logger.error(
                "recovering by returning default archiver analyzer. indexing and search may be impaired. urgent fix required.");
        analyzer = new ArchivaAnalyzer();
    }
    PerFieldAnalyzerWrapper wrapper = new PerFieldAnalyzerWrapper(analyzer);

    if (operation == Operation.INDEX) {
        wrapper.addAnalyzer("to", new EmailAnalyzer());
        wrapper.addAnalyzer("from", new EmailAnalyzer());
        wrapper.addAnalyzer("cc", new EmailAnalyzer());
        wrapper.addAnalyzer("bcc", new EmailAnalyzer());
        wrapper.addAnalyzer("deliveredto", new EmailAnalyzer());
        wrapper.addAnalyzer("attachname", new FileNameAnalyzer());
    } else {
        wrapper.addAnalyzer("to", new WhitespaceAnalyzer());
        wrapper.addAnalyzer("from", new WhitespaceAnalyzer());
        wrapper.addAnalyzer("cc", new WhitespaceAnalyzer());
        wrapper.addAnalyzer("bcc", new WhitespaceAnalyzer());
        wrapper.addAnalyzer("deliveredto", new WhitespaceAnalyzer());
        wrapper.addAnalyzer("attachname", new FileNameAnalyzer());
    }
    return wrapper;
}

From source file:Main.java

public static List convertMapToList(Map map) {
    List list = new ArrayList();

    Object[] o = ((HashMap) map).keySet().toArray();

    Arrays.sort(o);//from w  ww .  jav  a2s.com

    for (int i = 0; i <= o.length - 1; i++) {

        if (map.containsKey(String.valueOf(o[i]))) {

            list.add(map.get(String.valueOf(o[i])));

        } else {
            list.add(map.get(""));
        }
    }
    return list;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static void filtrerDoublonsSurPlace(List<Map> objets, Object filter) {
    Map objetsDejaPresents = new HashMap();
    Map filterDejaPresents = new HashMap();
    for (Iterator i = objets.iterator(); i.hasNext();) {
        Map objet = (Map) i.next();
        if (!objetsDejaPresents.containsKey(objet) && objet != null
                && !filterDejaPresents.containsKey(objet.get(filter))) {
            objetsDejaPresents.put(objet, null);
            filterDejaPresents.put(objet.get(filter), null);
        } else/*  www.  j av a  2s .  co m*/
            i.remove();
    }
}

From source file:NestUtil.java

/**
 * Get all fields of a class.//from   w w  w.jav  a  2  s. co m
 * 
 * @param clazz The class.
 * @return All fields of a class.
 */
public static Collection<Field> getFields(Class<?> clazz) {
    //      if (log.isDebugEnabled()) {
    //      log.debug("getFields(Class<?>) - start");
    //}

    Map<String, Field> fields = new HashMap<String, Field>();
    while (clazz != null) {
        for (Field field : clazz.getDeclaredFields()) {
            if (!fields.containsKey(field.getName())) {
                fields.put(field.getName(), field);
            }
        }

        clazz = clazz.getSuperclass();
    }

    Collection<Field> returnCollection = fields.values();
    //   if (log.isDebugEnabled()) {
    //   log.debug("getFields(Class<?>) - end");
    //   }
    return returnCollection;
}

From source file:org.openremote.server.route.SubflowRoute.java

public static boolean hasCorrelationStack(Map<String, Object> headers) {
    return headers.containsKey(SUBFLOW_CORRELATION_STACK);
}

From source file:Main.java

static <T, K, U> Map<K, U> toMap(List<T> elements, Function<T, K> keyFunction, Function<T, U> valueFunction,
        BinaryOperator<U> mergeFunction) {
    //TODO Implement me
    Map<K, U> map = new HashMap<>();
    K key;// ww  w. ja  va  2  s.  com
    U value;
    for (T element : elements) {
        key = keyFunction.apply(element);
        value = valueFunction.apply(element);
        if (map.containsKey(key)) {
            map.put(key, mergeFunction.apply(map.get(key), value));
        } else {
            map.put(key, value);
        }
    }
    return map;
}

From source file:com.comstar.mars.env.EnvMapperFactoryBean.java

public static Map<String, Object> getAllMappers(Class mapperClazz) {
    Map<String, Object> result = new HashMap<>();
    String clazzName = mapperClazz.getName();

    for (String env : envMappers.keySet()) {
        Map<String, Object> mappers = envMappers.get(env);
        if (mappers.containsKey(clazzName)) {
            result.put(env, mappers.get(clazzName));
        }//from   ww w  .j av a  2s.co m
    }

    return result;
}

From source file:org.hawkular.alerts.actions.webhook.WebHooks.java

public static synchronized void removeWebHook(String tenantId, String url) throws IOException {
    if (!instance.webhooks.containsKey(tenantId)) {
        return;/*from   w  w  w .ja v  a 2  s.  c om*/
    }
    List<Map<String, String>> tenantWebHooks = instance.webhooks.get(tenantId);
    for (int i = 0; i < tenantWebHooks.size(); i++) {
        Map<String, String> item = tenantWebHooks.get(i);
        if (item.containsKey("url") && item.get("url").equals(url)) {
            tenantWebHooks.remove(i);
            break;
        }
    }
    if (instance.supportsFile) {
        File f = new File(instance.webhooksFile);
        instance.mapper.writeValue(f, instance.webhooks);
    }
}