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.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesManifestLabeler.java

private static void storeLabel(Map<String, String> labels, String key, String value) {
    if (value == null) {
        return;//from  ww w .j  a v  a2  s.  co  m
    }

    if (labels.containsKey(key)) {
        return;
    }

    labels.put(key, value);
}

From source file:Main.java

public static List<String> checkMapDiff(Map<String, List<String>> m1, Map<String, List<String>> m2) {
    List<String> diff = new ArrayList<>();
    //m2-m1/*from w  w  w  .j  ava2s.  co  m*/
    for (String k : m1.keySet()) {
        if (m2.containsKey(k)) {
            diff.addAll(getDiff(m1.get(k), m2.get(k)));
        } else {//m1 have, but m2 don't
            diff.addAll(m1.get(k));
        }
    }

    //m1-m2
    for (String k : m2.keySet()) {
        if (!m1.containsKey(k)) {//m2 have, but m1 don't
            diff.addAll(m2.get(k));
        }
    }

    return diff;
}

From source file:Main.java

public static List<String> getDiff(List<String> source, List<String> target) {
    if (source.size() == 0 || target.size() == 0) {
        return null;
    }//from ww  w  . j ava 2 s  . c o m
    if (source == null || target == null) {
        return null;
    }
    int frequency = 1;
    List<String> max;
    List<String> min;
    List<String> diff = new ArrayList<>();
    if (source.size() > target.size()) {
        max = source;
        min = target;
    } else {
        max = target;
        min = source;
    }

    Map<String, Integer> map = new HashMap<>();
    max.stream().forEach(s -> map.put(s, frequency));

    min.stream().forEach(s -> {
        if (map.containsKey(s)) {
            map.put(s, map.get(s) + 1);//rewrite value
        } else {
            map.put(s, frequency);
        }
    });

    //get value=1
    map.forEach((k, v) -> {
        if (v == 1) {
            diff.add(k);
        }
    });

    return diff;
}

From source file:org.apache.streams.elasticsearch.ElasticsearchMetadataUtil.java

public static String getId(StreamsDatum datum) {

    String id = datum.getId();//from  www.j  a  va  2  s .  com

    Map<String, Object> metadata = datum.getMetadata();

    if (id == null && metadata != null && metadata.containsKey("id"))
        id = (String) datum.getMetadata().get("id");

    return id;
}

From source file:fr.zcraft.zbanque.structure.items_groups.ItemsGroup.java

@ConfigurationValueHandler
public static ItemsGroup handleItemsGroup(Map map) throws ConfigurationParseException {
    if (!map.containsKey("name"))
        throw new ConfigurationParseException("Key 'name' required.", map);

    if (!map.containsKey("icon"))
        throw new ConfigurationParseException("Key 'icon' required.", map);

    final String name = map.get("name").toString();
    final BlockType icon = BlockType.handleBlockType(map.get("icon"));

    final ItemsGroup group = new ItemsGroup(name, icon);

    if (map.containsKey("relative_amounts")) {
        for (Map.Entry<BlockType, Double> entry : ConfigurationValueHandlers
                .handleMapValue(map.get("relative_amounts"), BlockType.class, Double.class).entrySet()) {
            group.registerRelativeAmount(entry.getKey(), entry.getValue());
        }/*from   w ww .j a v  a2  s .co  m*/
    }

    return group;
}

From source file:com.github.pmerienne.trident.state.cassandra.CassandraConfig.java

@SuppressWarnings({ "rawtypes" })
public static CassandraConfig getFromStormConfig(Map conf) {
    CassandraConfig cassandraConfig;//  w w w.ja va  2s  .com
    if (conf.containsKey(STORM_CONFIG_KEY)) {
        cassandraConfig = (CassandraConfig) conf.get(STORM_CONFIG_KEY);
    } else {
        cassandraConfig = new CassandraConfig();
    }
    return cassandraConfig;
}

From source file:com.surevine.gateway.scm.gatewayclient.MetadataUtil.java

public static boolean metadataValid(final Map<String, String> metadata) {
    final boolean containsRequiredKeys = metadata.containsKey(KEY_SOURCE) && metadata.containsKey(KEY_PROJECT)
            && metadata.containsKey(KEY_REPO) && metadata.containsKey(KEY_DISTRIBUTION_TYPE)
            && metadata.containsKey(KEY_ORGANISATION) && metadata.containsKey(KEY_CLASSIFICATION)
            && metadata.containsKey(KEY_DECORATOR) && metadata.containsKey(KEY_GROUPS)
            && metadata.containsKey(KEY_FILENAME);

    final boolean valuesAreValid = InputValidator
            .partnerNameIsValid(metadata.get(MetadataUtil.KEY_ORGANISATION))
            && InputValidator.projectKeyIsValid(metadata.get(MetadataUtil.KEY_PROJECT))
            && InputValidator.repoSlugIsValid(metadata.get(MetadataUtil.KEY_REPO));

    return containsRequiredKeys && valuesAreValid;
}

From source file:org.apache.streams.elasticsearch.ElasticsearchMetadataUtil.java

public static String getParent(StreamsDatum datum) {

    String parent = null;// w  ww  . ja  v a  2  s.  c  om

    Map<String, Object> metadata = datum.getMetadata();

    if (parent == null && metadata != null && metadata.containsKey("parent"))
        parent = (String) datum.getMetadata().get("parent");

    return parent;
}

From source file:gemlite.core.support.SyncListenerTool.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void EntryChangeEventOnView(EntryEvent event, EventStatus status) {
    try {// w ww  .  j a  v  a  2s. c om
        String regionName = event.getRegion().getName();
        GemliteViewContext context = GemliteViewContext.getInstance();
        Map<String, Set<String>> regionToView = context.getRegionToView();
        if (regionToView.containsKey(regionName)) {
            SimpleEntryEvent sevent = new SimpleEntryEvent(event);
            Map<String, ViewItem> viewMap = context.getViewContext();
            Set<String> itemSet = regionToView.get(regionName);
            for (String itemName : itemSet) {
                ViewItem viewItem = viewMap.get(itemName);
                ViewTool viewTool = viewItem.getViewTool();
                if (viewTool != null) {
                    if (status == EventStatus.AfterRegionCreate)
                        viewTool.afterInsert(sevent);
                    else if (status == EventStatus.AfterRegionUpdate)
                        viewTool.afterUpdate(sevent);
                    else if (status == EventStatus.AfterRegionDestroy)
                        viewTool.afterDelete(sevent);
                }
            }
        }
    } catch (Exception e) {
        LogUtil.getMqSyncLog().error(">>" + event.getRegion().getName() + " key:" + event.getKey(), e);
        throw new RuntimeException(e);
    }

}

From source file:org.springframework.cloud.netflix.turbine.amqp.Aggregator.java

public static Map<String, Object> getPayloadData(Map<String, Object> jsonMap) {
    @SuppressWarnings("unchecked")
    Map<String, Object> origin = (Map<String, Object>) jsonMap.get("origin");
    String instanceId = null;/*from w ww.j  a v a  2 s .co  m*/
    if (origin.containsKey("id")) {
        instanceId = origin.get("id").toString();
    }
    if (!StringUtils.hasText(instanceId)) {
        // TODO: instanceid template
        instanceId = origin.get("serviceId") + ":" + origin.get("host") + ":" + origin.get("port");
    }
    @SuppressWarnings("unchecked")
    Map<String, Object> data = (Map<String, Object>) jsonMap.get("data");
    data.put("instanceId", instanceId);
    return data;
}