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:net.eledge.android.europeana.search.model.record.abstracts.Resource.java

protected static Map<String, String[]> mergeMapArrays(Map<String, String[]> source1,
        Map<String, String[]> source2) {
    Map<String, String[]> merged = new HashMap<>();
    if (source1 != null) {
        merged.putAll(source1);//from   w w w. jav  a 2 s  . c  o m
    } else {
        return source2;
    }
    if (source2 != null) {
        for (String key : source2.keySet()) {
            if (merged.containsKey(key)) {
                merged.put(key, mergeArray(merged.get(key), source2.get(key)));
            } else {
                merged.put(key, source2.get(key));
            }
        }
    }
    return merged;
}

From source file:com.github.stagirs.lingvo.build.MorphStateMachineBuilder.java

private static Collection<RuleMapping> suf2mapping() throws IOException {
    Set<String> suffixes = getSuffixes();
    Map<String, Struct> sufs = new HashMap<String, Struct>();
    for (Map.Entry<String, List<WordForm[]>> raw2WordForms : getRaw2WordForms().entrySet()) {
        String raw = raw2WordForms.getKey();
        int[] index = getCommon(suffixes, raw, raw2WordForms.getValue());
        String common = index[0] < index[1] ? raw.substring(index[0], index[1]) : "";
        String rawPref = raw.substring(0, Math.min(index[0], index[1]));
        String rawSuf = raw.substring(index[1]);
        Map<String, List<RuleItem>> map = new HashMap();
        for (WordForm[] wordForm : raw2WordForms.getValue()) {
            String normSuf = wordForm[1].getWord().substring(common.length());
            if (!map.containsKey(normSuf)) {
                map.put(normSuf, new ArrayList<RuleItem>());
            }/*from  www . j a  v  a2s  .com*/
            map.get(normSuf).add(new RuleItem(normSuf, wordForm[1].getForm(), wordForm[0].getForm()));
        }
        RuleItem[][] items = new RuleItem[map.size()][];
        int i = 0;
        for (List<RuleItem> item : map.values()) {
            items[i++] = item.toArray(new RuleItem[item.size()]);
        }
        Rule rule = new Rule(rawPref, rawSuf, items);
        String ruleId = Rule.serialize(rule);
        if (!sufs.containsKey(rawSuf)) {
            sufs.put(rawSuf, new Struct());
        }
        Struct struct = sufs.get(rawSuf);
        if (!struct.rule2id.containsKey(ruleId)) {
            struct.rule2id.put(ruleId, struct.rule2id.size());
            struct.rules.add(rule);
        }
        struct.prefcommons.put(rawPref + common, struct.rule2id.get(ruleId));
    }
    List<RuleMapping> list = new ArrayList<RuleMapping>();
    for (Map.Entry<String, Struct> entrySet : sufs.entrySet()) {
        list.add(new RuleMapping(entrySet.getKey(), entrySet.getValue().prefcommons,
                entrySet.getValue().rules.toArray(new Rule[entrySet.getValue().rules.size()])));
    }
    return list;
}

From source file:Main.java

/**
 * From http://stackoverflow.com/questions/13592236/parse-a-uri-string-into-name-value-collection
 *//*  w  ww .  j a  v  a  2s.c o m*/
public static Map<String, List<String>> splitQuery(String urlQuery) throws UnsupportedEncodingException {
    final Map<String, List<String>> query_pairs = new LinkedHashMap<>();
    final String[] pairs = urlQuery.split("&");
    for (String pair : pairs) {
        final int idx = pair.indexOf("=");
        final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), "UTF-8") : pair;
        if (!query_pairs.containsKey(key)) {
            query_pairs.put(key, new LinkedList<String>());
        }
        final String value = idx > 0 && pair.length() > idx + 1
                ? URLDecoder.decode(pair.substring(idx + 1), "UTF-8")
                : null;
        query_pairs.get(key).add(value);
    }
    return query_pairs;
}

From source file:com.microsoft.alm.plugin.external.utils.WorkspaceHelper.java

/**
 * This method checks all the current mappings in currentWorkspace to see if they exist in the newWorkspace.
 * If the mapping does not exist at all, it is added to the list of mappings to remove.
 *
 * @param currentWorkspace The current workspace with the current mappings
 * @param newWorkspace     The new workspace with the way you want the mappings to look
 * @return//from   w  w  w.j a  va 2s . co m
 */
public static List<Workspace.Mapping> getMappingsToRemove(final Workspace currentWorkspace,
        final Workspace newWorkspace) {
    ArgumentHelper.checkNotNull(currentWorkspace, "currentWorkspace");
    ArgumentHelper.checkNotNull(newWorkspace, "newWorkspace");
    final List<Workspace.Mapping> mappingsToRemove = new ArrayList<Workspace.Mapping>();
    final Map<String, Workspace.Mapping> map = getMappingsByServerPath(newWorkspace);

    for (final Workspace.Mapping mapping : currentWorkspace.getMappings()) {
        if (!map.containsKey(getServerPathKey(mapping.getServerPath()))) {
            mappingsToRemove.add(mapping);
        }
    }

    return mappingsToRemove;
}

From source file:com.vmware.identity.openidconnect.protocol.AuthenticationSuccessResponse.java

public static AuthenticationSuccessResponse parse(HttpRequest httpRequest) throws ParseException {
    Validate.notNull(httpRequest, "httpRequest");
    Map<String, String> parameters = httpRequest.getParameters();

    State state = State.parse(ParameterMapUtils.getString(parameters, "state"));

    AuthorizationCode code = null;/*  ww  w. jav  a 2  s . c  om*/
    if (parameters.containsKey("code")) {
        code = new AuthorizationCode(ParameterMapUtils.getString(parameters, "code"));
    }

    IDToken idToken = null;
    if (parameters.containsKey("id_token")) {
        idToken = IDToken.parse(parameters);
    }

    AccessToken accessToken = null;
    if (parameters.containsKey("access_token")) {
        accessToken = AccessToken.parse(parameters);
    }

    return new AuthenticationSuccessResponse(ResponseMode.FORM_POST, // we don't really know but it doesn't matter
            httpRequest.getURI(), state, false /* isAjaxRequest, we don't really know but it doesn't matter */,
            code, idToken, accessToken);
}

From source file:de.bund.bfr.jung.JungUtils.java

public static <V, E> Transformer<V, Paint> newNodeFillTransformer(RenderContext<V, E> renderContext,
        Map<V, Paint> nodeColors) {
    return node -> {
        Paint color = nodeColors != null && nodeColors.containsKey(node) ? nodeColors.get(node) : Color.WHITE;

        return renderContext.getPickedVertexState().isPicked(node) ? mixWith(color, Color.BLUE) : color;
    };/*from  ww w.  j a v a  2  s.  com*/
}

From source file:de.bund.bfr.jung.JungUtils.java

public static <V, E> Transformer<E, Paint> newEdgeFillTransformer(RenderContext<V, E> renderContext,
        Map<E, Paint> edgeColors) {
    return edge -> {
        Paint color = edgeColors != null && edgeColors.containsKey(edge) ? edgeColors.get(edge) : Color.BLACK;

        return renderContext.getPickedEdgeState().isPicked(edge) ? mixWith(color, Color.GREEN) : color;
    };/*from  ww w.java  2s .  com*/
}

From source file:com.uber.hoodie.common.util.ParquetUtils.java

private static List<String> readParquetFooter(Configuration configuration, Path parquetFilePath,
        String... footerNames) {/*from   w w  w  . j av  a  2 s.  co m*/
    List<String> footerVals = new ArrayList<>();
    ParquetMetadata footer = readMetadata(configuration, parquetFilePath);
    Map<String, String> metadata = footer.getFileMetaData().getKeyValueMetaData();
    for (String footerName : footerNames) {
        if (metadata.containsKey(footerName)) {
            footerVals.add(metadata.get(footerName));
        } else {
            throw new MetadataNotFoundException("Could not find index in Parquet footer. " + "Looked for key "
                    + footerName + " in " + parquetFilePath);
        }
    }
    return footerVals;
}

From source file:com.palantir.atlasdb.keyvalue.rdbms.utils.AtlasSqlUtils.java

public static <K, V> Map<K, V> listToMap(List<Pair<K, V>> list) {
    Map<K, V> result = Maps.newHashMap();
    for (Pair<K, V> p : list) {
        Preconditions.checkArgument(!result.containsKey(p.lhSide));
        result.put(p.lhSide, p.rhSide);/*  ww  w . ja  v  a 2s .co  m*/
    }
    return result;
}

From source file:com.qmetry.qaf.automation.testng.pro.DataProviderUtil.java

@DataProvider(name = "isfw_json")
public static final Object[][] getJsonData(Method method) {
    Map<String, String> methodParams = getParameters(method);
    if (methodParams.containsKey(params.JSON_DATA_TABLE.name())) {
        return JSONUtil.getJsonArrayOfMaps(methodParams.get(params.JSON_DATA_TABLE.name()));
    }//from   w  w  w  .j  a va  2  s.  c om
    return JSONUtil.getJsonArrayOfMaps(methodParams.get(params.DATAFILE.name()));
}