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.aaasec.sigserv.csspserver.utility.SpServerLogic.java

private static String getLegacyJsonData(SignatureResult result) {
    BASE64Decoder b64 = new BASE64Decoder();
    String jsonStatus = "";

    try {/*from   w w  w. ja  v  a 2 s  . c om*/
        //Get Legacy status Json data
        Map<String, String> paramMap = getSignatureResultParamMap(result);
        if (paramMap.containsKey("legacyStatus")) {
            String legacyStatus = paramMap.get("legacyStatus");
            jsonStatus = new String(b64.decodeBuffer(legacyStatus), Charset.forName("UTF-8"));
        }
    } catch (Exception ex) {
    }
    return jsonStatus;
}

From source file:com.senseidb.test.MockServletRequest.java

public static MockServletRequest create(List<NameValuePair> list) {
    Map<String, List<String>> map = new HashMap<String, List<String>>();

    for (NameValuePair pair : list) {
        String name = pair.getName();
        if (!map.containsKey(name)) {
            map.put(name, new ArrayList<String>());
        }/*from  w ww  .  j  a v  a 2 s. co  m*/

        for (String value : pair.getValue().split(",")) {
            map.get(name).add(value);
        }
    }

    return new MockServletRequest(map);
}

From source file:com.etsy.arbiter.config.ConfigurationMerger.java

/**
 * Merge a collection of maps where the values are themselves collections
 * Every value in the values of the resulting map is unique
 *
 * @param actionTypes The collection of ActionTypes
 * @param transformFunction The function that produces a map from an ActionType
 * @param <T> The type of values in the collection that is the value of the map
 * @return A Map representing the merger of all input maps
 *//*from w  w w.  j av a 2  s. c o  m*/
public static <T, U extends Collection<T>> Map<String, U> mergeCollectionMaps(
        Collection<ActionType> actionTypes, Function<ActionType, Map<String, U>> transformFunction) {
    Collection<Map<String, U>> values = Collections2.transform(actionTypes, transformFunction);
    Map<String, U> result = new HashMap<>();

    for (Map<String, U> map : values) {
        for (Map.Entry<String, U> entry : map.entrySet()) {
            if (!result.containsKey(entry.getKey())) {
                result.put(entry.getKey(), entry.getValue());
            } else {
                result.get(entry.getKey()).addAll(entry.getValue());
            }
        }
    }

    return result;
}

From source file:Main.java

/**
 * Determine if the contents of two maps are the same, i.e. the same keys are mapped to the same values in both maps.
 * @param a the first {@link Map}/* ww w .  j a v a 2  s .  c  o m*/
 * @param b the secound {@link Map}
 * @return <code>true</code> if the contents are the same, <code>false</code> otherwise.
 */
public static <K, V> boolean equalContents(Map<? extends K, ? extends V> a, Map<? extends K, ? extends V> b) {
    if (a == b) {
        return true;
    } else if (a.isEmpty() && b.isEmpty()) {
        return true;
    }
    if (a.size() != b.size()) {
        return false;
    } else {

        for (Map.Entry entryA : a.entrySet()) {

            if (!b.containsKey(entryA.getKey()) || !b.get(entryA.getKey()).equals(entryA.getValue())) {
                return false;
            }

        }

        return true;
    }

}

From source file:com.mothsoft.alexis.engine.numeric.President2012DataSetImporter.java

private static void append(final Date date, final PollResults pr, final Map<Date, PollResults> consolidated) {
    if (consolidated.containsKey(date)) {
        final PollResults cpr = consolidated.get(date);

        // append the results
        for (final String choice : pr.getAvailableChoices()) {
            cpr.tally(choice, pr.valueOf(choice));
        }/*w  w w.j av a2s .  c  o m*/

    } else {
        // use the only value we have as-is
        consolidated.put(date, pr);
    }
}

From source file:com.hangum.tadpole.engine.restful.RESTfulAPIUtils.java

/**
 * return argument to java list// ww w .  j  a  v  a2  s. c o m
 * 
 * @param strArgument
 * @return
 * @throws UnsupportedEncodingException
 */
public static List<Object> makeArgumentToJavaList(String strArgument)
        throws RESTFULUnsupportedEncodingException {
    List<Object> listParam = new ArrayList<Object>();

    Map<String, String> params = maekArgumentTOMap(strArgument);

    // assume this count... no way i'll argument is over 100..... --;;
    for (int i = 1; i < 100; i++) {
        if (params.containsKey(String.valueOf(i))) {
            listParam.add(params.get("" + i));
        } else {
            break;
        }
    }

    return listParam;
}

From source file:com.github.strawberry.guice.config.ConfigLoader.java

private static Set<String> getKeys(Map properties, String pattern) {
    if (pattern.indexOf("*") == -1) {
        if (properties.containsKey(pattern)) {
            return Sets.newHashSet(pattern);
        } else {/*from ww w  .j  a v  a2 s .  c o  m*/
            return Sets.newHashSet();
        }
    } else {
        Set keys = Sets.newHashSet();
        pattern = pattern.replace("*", "(.*)");
        Pattern p = Pattern.compile(pattern);
        for (Object kk : properties.keySet()) {
            String k = kk.toString();
            Matcher m = p.matcher(k);
            if (m.matches()) {
                keys.add(kk);
            }

        }
        return keys;
    }
}

From source file:org.springjutsu.validation.util.RequestUtils.java

/**
 * Used by successView and validationFailureView.
 * If the user specifies a path containing RESTful url
 * wildcards, evaluate those wildcard expressions against 
 * the current model map, and plug them into the url.
 * If the wildcard is a multisegmented path, get the top level
 * bean from the model map, and fetch the sub path using 
 * a beanwrapper instance./*from   ww  w  .j a va 2s . c om*/
 * @param viewName The view potentially containing wildcards
 * @param model the model map 
 * @param request the request
 * @return a wildcard-substituted view name
 */
@SuppressWarnings("unchecked")
public static String replaceRestPathVariables(String viewName, Map<String, Object> model,
        HttpServletRequest request) {
    String newViewName = viewName;
    Matcher matcher = Pattern.compile(PATH_VAR_PATTERN).matcher(newViewName);
    while (matcher.find()) {
        String match = matcher.group();
        String varName = match.substring(1, match.length() - 1);
        String baseVarName = null;
        String subPath = null;
        if (varName.contains(".")) {
            baseVarName = varName.substring(0, varName.indexOf("."));
            subPath = varName.substring(varName.indexOf(".") + 1);
        } else {
            baseVarName = varName;
        }
        Map<String, String> uriTemplateVariables = (Map<String, String>) request
                .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        if (uriTemplateVariables != null && uriTemplateVariables.containsKey(varName)) {
            newViewName = newViewName.replace(match, String.valueOf(uriTemplateVariables.get(varName)));
        } else {
            Object resolvedObject = model.get(baseVarName);
            if (resolvedObject == null) {
                throw new IllegalArgumentException(varName + " is not present in model.");
            }
            if (subPath != null) {
                BeanWrapperImpl beanWrapper = new BeanWrapperImpl(resolvedObject);
                resolvedObject = beanWrapper.getPropertyValue(subPath);
            }
            if (resolvedObject == null) {
                throw new IllegalArgumentException(varName + " is not present in model.");
            }
            newViewName = newViewName.replace(match, String.valueOf(resolvedObject));
        }
        matcher.reset(newViewName);
    }
    return newViewName;
}

From source file:com.github.ipaas.ideploy.plugin.util.ConfigUtil.java

public static ProjectInfo getProjectInfo() throws Exception {

    UserInfo userInfo = CrsPreferencePage.getUserInfo();
    ProjectInfo projectInfo = new ProjectInfo();
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    if (userInfo.getPassword() == null || userInfo.getPassword().equals("")) {
        throw new Exception(" AMM???!");
    }/*from w  ww  .  j ava  2s  . c o  m*/
    if (userInfo.getEmail() == null || userInfo.getEmail().equals("")) {
        throw new Exception(" AMM???!");
    }
    params.add(new BasicNameValuePair("userName", userInfo.getEmail()));
    params.add(new BasicNameValuePair("password", userInfo.getPassword()));
    String json = RequestAcion.post(userInfo.getUrl() + "/crs_code/project_list", params, true);
    System.out.println(json);
    if (json != null && !json.equals("")) {
        Map<String, String> result = JsonUtil.toBean(json, Map.class);
        if (result.get("status") != null && result.get("status").equals("success")) {
            try {
                List<String> list = null;
                if (result.containsKey("list")) {
                    list = JsonUtil.toBean(result.get("list"), List.class);
                }
                projectInfo.setProjectList(list);
                if (result.containsKey("groupInfoList")) {
                    List<Map<String, Object>> groupInfoList = JsonUtil.toBean(result.get("groupInfoList"),
                            List.class);
                    List<ServGroup> servGroupList = new ArrayList<ServGroup>();
                    for (Map<String, Object> groupInfoMap : groupInfoList) {
                        ServGroup group = new ServGroup();
                        group.setAppRowId((Integer) groupInfoMap.get("appRowId"));
                        group.setId((String) groupInfoMap.get("id"));
                        group.setSgId((Integer) groupInfoMap.get("sgId"));
                        group.setActName((String) groupInfoMap.get("actName"));
                        servGroupList.add(group);
                    }
                    projectInfo.setServGroupList(servGroupList);
                }

                projectInfo.setUserId(Integer.valueOf(result.get("userId")));
                if (projectInfo.getProjectList().size() < 1) {
                    ConsoleHandler.error("??!");
                }
            } catch (Exception e) {
                ConsoleHandler.error("??:" + result.get("list"));
            }
        } else {
            ConsoleHandler.error("??:" + result.get("info"));
        }
    }
    return projectInfo;
}

From source file:org.imsglobal.lti.LTIUtil.java

public static Map<String, List<String>> setSingleParameter(Map<String, List<String>> parameters, String name,
        String value) {/*from w  w  w  .j  ava  2 s .c  o m*/
    if (parameters.containsKey(name)) {
        //we want a list with only the provided value
        List<String> itemList = parameters.get(name);
        itemList.clear();
        itemList.add(value);
        parameters.put(name, itemList);
    } else {
        List<String> itemList = new ArrayList<String>();
        itemList.add(value);
        parameters.put(name, itemList);
    }
    return parameters;
}