Example usage for java.util HashMap keySet

List of usage examples for java.util HashMap keySet

Introduction

In this page you can find the example usage for java.util HashMap keySet.

Prototype

public Set<K> keySet() 

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:coolmapplugin.util.CMCyCommunicationUtil.java

public static boolean addColumnToNodeTable(String networkSUID, HashMap<String, Double> selectedElements,
        String columnName) {/*from w w  w  .j a v  a  2 s  .c  o  m*/

    try {
        JSONObject jsonBody = new JSONObject();

        JSONArray jsonNodesToBeUpdated = new JSONArray();
        for (String nodeName : selectedElements.keySet()) {
            JSONObject jsonNode = new JSONObject();
            jsonNode.put("name", nodeName);
            jsonNode.put(columnName, selectedElements.get(nodeName));
            jsonNodesToBeUpdated.put(jsonNode);
        }

        jsonBody.put("data", jsonNodesToBeUpdated);
        jsonBody.put("dataKey", "name");
        jsonBody.put("key", "name");

        return CyRESTAPI.updateTableData(networkSUID, TABLETYPE_NODE, jsonBody.toString());

    } catch (JSONException e) {
        return false;
    }

}

From source file:com.bigtobster.pgnextractalt.commands.TestCommandContext.java

/**
 * Builds a command string up from a basic command plus a Hash Map of Option, Argument value pairs to get "command [--&lt;option&gt; &lt;
 * arg&gt;]*"/*  ww  w  .ja va  2  s. c om*/
 *
 * @param command         The base command
 * @param optionValuesMap The hash map of Option, Argument pairs
 * @return The fully constructed command
 */
static String buildCommand(final String command, final HashMap<String, String> optionValuesMap) {
    final StringBuilder newCommandBuilder = new StringBuilder(50);
    newCommandBuilder.append(command);
    if (optionValuesMap != null) {
        for (final String key : optionValuesMap.keySet()) {
            newCommandBuilder.append(" --");
            newCommandBuilder.append(key);
            newCommandBuilder.append(TestContext.SPACE);
            newCommandBuilder.append(optionValuesMap.get(key));
        }
    }
    return newCommandBuilder.toString();
}

From source file:Main.java

/**
 * Method that merges 2 data structures into 1
 * //from  w  ww  . ja va  2 s  . c  o  m
 * @param featureSet:
 *            the structure containing all features
 * @param featureSet2:
 *            the structure containing Pairwise Correlation features
 * @return the concatenated data structure
 */
public static HashMap<Integer, ArrayList<HashMap<String, Double>>> mergeStructures(
        HashMap<Integer, ArrayList<HashMap<String, Double>>> featureSet,
        ArrayList<ArrayList<HashMap<String, Double>>> featureSet2) {

    HashMap<Integer, ArrayList<HashMap<String, Double>>> featureSet_final = new HashMap<Integer, ArrayList<HashMap<String, Double>>>();

    for (int i = 0; i < featureSet.size(); i++) {
        ArrayList<HashMap<String, Double>> featuresPerChann = featureSet.get(i);
        ArrayList<HashMap<String, Double>> featuresPerChann2 = featureSet2.get(i);
        if (featuresPerChann2 == null)
            continue;

        ArrayList<HashMap<String, Double>> featuresPerChann_final = new ArrayList<HashMap<String, Double>>();

        for (int ii = 0; ii < featuresPerChann.size(); ii++) {
            HashMap<String, Double> h1 = new HashMap<String, Double>();
            HashMap<String, Double> h2 = new HashMap<String, Double>();
            // System.out.println("s:: "+String.format("%03d", ii));
            h1 = featuresPerChann.get(ii);
            for (int j = 0; j < featuresPerChann2.size(); j++) {
                h2 = featuresPerChann2.get(j);
                // System.out.println("h2:"+h2);
                String s = h2.keySet().toString();

                if (s.contains("s" + String.format("%04d", ii))) {
                    // System.out.println("sss"+s.substring(1,14));
                    String new_s = s.substring(1, 17);
                    if (h2.get(new_s) != null) {
                        double v = h2.get(new_s);
                        HashMap<String, Double> h = new HashMap<String, Double>();
                        h.put(new_s.substring(0, 11), v);
                        h1.putAll(h);
                    }
                }
            }
            featuresPerChann_final.add(h1);

        }
        featureSet_final.put(i, featuresPerChann_final);
    }

    return featureSet_final;
}

From source file:es.sm2.openppm.core.plugin.PluginTemplate.java

/**
 * Load template for plugin/* w ww. ja  v a2 s . c  o  m*/
 * 
 * @param templateName
 * @param data
 * @return
 * @throws IOException
 * @throws TemplateException
 */
public static String getTemplate(String templateName, HashMap<String, Object> data)
        throws IOException, TemplateException {

    Logger log = LogManager.getLog(PluginTemplate.class);

    // Print data to logger
    if (log.isDebugEnabled()) {
        log.debug("Create Template: " + templateName);

        if (data != null && !data.isEmpty()) {

            for (String key : data.keySet()) {
                log.debug("Parameter: " + key + " Value: " + data.get(key));
            }
        }
    }

    // Load template
    InputStream stream = PluginTemplate.class.getResourceAsStream(templateName);
    String teamplate = IOUtils.toString(stream);

    // Create loader
    StringTemplateLoader stringLoader = new StringTemplateLoader();
    stringLoader.putTemplate("template", teamplate);

    // Create configuration
    Configuration cfg = new Configuration();
    cfg.setTemplateLoader(stringLoader);

    Template template = cfg.getTemplate("template");

    StringWriter writer = new StringWriter();
    template.process(data, writer);

    return writer.toString();
}

From source file:com.sds.acube.ndisc.mts.xserver.util.XNDiscConfig.java

/**
 *  variable? ? value  /*w w  w.ja  v  a  2 s.c om*/
 * 
 * @param value  ?
 * @return ? ?
 */
@SuppressWarnings("unchecked")
private static String replaceValueByVariables(String value) {
    HashMap<String, String> variables = configuration.getVariables();
    Iterator<String> iterator = variables.keySet().iterator();
    String key = "";
    String keyval = "";
    String repkeyval = "";
    while (iterator.hasNext()) {
        key = (String) iterator.next();
        keyval = "${".concat(key).concat("}");
        repkeyval = "\\$\\{".concat(key).concat("\\}");
        if (value.indexOf(keyval) != -1) {
            value = value.replaceAll(repkeyval, variables.get(key));
            break;
        }
    }
    return value;
}

From source file:com.sencko.basketball.stats.advanced.FIBAJsonParser.java

static void analyzeGame(Game game) {
    HashSet[] playersInGameTeam = { new HashSet<String>(5), new HashSet<String>(5) };
    HashSet[] playersInRest = { new HashSet<String>(5), new HashSet<String>(5) };
    HashMap[][] plusMinusPlayers = { { new HashMap<String, Integer>(), new HashMap<String, Integer>() },
            { new HashMap<String, Integer>(), new HashMap<String, Integer>() } };
    for (int i = game.getPbp().size() - 1; i >= 0; i--) {
        Event event = game.getPbp().get(i);
        if (EventType.sub.equals(event.getTyp())) {
            HashSet<String> teamSet = playersInGameTeam[event.getTno() - 1];
            HashSet<String> restSet = playersInRest[event.getTno() - 1];
            String actor = event.getActor().toString();
            if (teamSet.contains(actor)) {
                teamSet.remove(actor);/*from ww  w  .  j  a v a2  s  .c om*/
                restSet.add(actor);
            } else {
                teamSet.add(actor);
                if (restSet.contains(actor)) {
                    restSet.remove(actor);
                } else {
                    //add plus minus on bench
                    HashMap<String, Integer> bench = plusMinusPlayers[event.getTno() - 1][1];
                    int change = (event.getTno() == 1) ? (event.getS1() - event.getS2())
                            : (event.getS2() - event.getS1());
                    bench.put(actor, change);
                }
            }

            //   System.out.println(Arrays.toString(playersInGameTeam));
        } else if (i != game.getPbp().size() - 1) {
            Event previousEvent = game.getPbp().get(i + 1);
            int change = 0;
            if (previousEvent.getS1() != event.getS1()) {
                change += event.getS1() - previousEvent.getS1();
            }
            if (previousEvent.getS2() != event.getS2()) {
                change -= event.getS2() - previousEvent.getS2();
            }
            for (int j = 0; j < 2; j++) {
                HashSet<String> teamSet = playersInGameTeam[j];
                for (String player : teamSet) {
                    HashMap<String, Integer> prev = plusMinusPlayers[j][0];
                    Integer previous = prev.get(player);
                    if (previous == null) {
                        previous = 0;
                    }
                    previous = previous + change;
                    prev.put(player, previous);
                }

                HashSet<String> restSet = playersInRest[j];
                for (String player : restSet) {
                    HashMap<String, Integer> prev = plusMinusPlayers[j][1];
                    Integer previous = prev.get(player);
                    if (previous == null) {
                        previous = 0;
                    }
                    previous = previous + change;
                    prev.put(player, previous);
                }

                change = -change;
            }
        }
    }
    //     System.out.println(Arrays.deepToString(plusMinusPlayers));

    for (int i = 0; i < 2; i++) {
        HashMap<String, Integer> board = plusMinusPlayers[i][0];
        HashMap<String, Integer> bench = plusMinusPlayers[i][1];
        int checkSum = 0;
        for (String name : board.keySet()) {
            int plusS = board.get(name);
            int plusB = bench.get(name);
            int total = plusS - plusB;
            System.out.printf("%20s\t%4d\t%4d\t%4d\n", name, plusS, plusB, total);
            checkSum += total;
        }

        System.out.println(checkSum + "----------------------------------------");
    }
}

From source file:eu.digitisation.idiomaident.utils.CorpusFilter.java

private static void eliminateNames(HashSet<String> posibleNames, HashMap<String, String> actualFile) {
    for (String name : posibleNames) {
        //Check if the name is in allmost the others languages
        double totalLenguages = actualFile.size();

        int goal = (int) (totalLenguages * 0.8); //80% of the lenguages

        int contains = 0;

        for (String lang : actualFile.keySet()) {
            if (actualFile.get(lang).contains(name)) {
                contains++;//from ww w  .j  av  a  2s.  co  m
            }
        }

        if (contains >= goal) //Eliminate the name
        {
            //System.out.println(name);

            for (String lang : actualFile.keySet()) {
                String text = actualFile.get(lang);

                String replacement = "(\\p{Space}|\\p{Punct})+" + name + "(\\p{Space}|\\p{Punct})+";

                text = text.replaceAll(replacement, " ");

                actualFile.put(lang, text);
            }
        }

    }
}

From source file:com.marklogic.contentpump.utilities.TransformHelper.java

private static String mapToElement(HashMap<String, String> map) {
    StringBuilder sb = new StringBuilder();
    sb.append(MAP_ELEM_START_TAG);/*from  w  w w .j  a  va 2 s.  c om*/
    Set<String> keys = map.keySet();
    for (String k : keys) {
        addKeyValue(sb, k, map.get(k));
    }
    sb.append("</map:map>");
    return sb.toString();
}

From source file:com.impetus.kundera.rest.common.EntityUtils.java

/**
 * @param queryString/*  ww w.j  a v a2s .  c  o  m*/
 * @param q
 */
public static void setQueryParameters(String queryString, HashMap<String, String> paramsMap, Query q) {
    KunderaQuery kq = ((QueryImpl) q).getKunderaQuery();
    Set<Parameter<?>> parameters = kq.getParameters();
    for (String paramName : paramsMap.keySet()) {
        String value = paramsMap.get(paramName);

        if (StringUtils.isNumeric(paramName)) {
            for (Parameter param : parameters) {
                if (param.getPosition() == Integer.parseInt(paramName)) {
                    Class<?> paramClass = param.getParameterType();
                    PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor(paramClass);
                    Object paramValue = accessor.fromString(paramClass, value);
                    q.setParameter(Integer.parseInt(paramName), paramValue);
                    break;
                }
            }
        } else {
            for (Parameter param : parameters) {
                if (param.getName().equals(paramName)) {
                    Class<?> paramClass = param.getParameterType();
                    PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor(paramClass);
                    Object paramValue = accessor.fromString(paramClass, value);
                    if (paramName.equalsIgnoreCase("firstResult")) {
                        q.setFirstResult(Integer.parseInt((String) paramValue));
                    } else if (paramName.equalsIgnoreCase("maxResult")) {
                        q.setMaxResults(Integer.parseInt((String) paramValue));
                    } else {
                        q.setParameter(paramName, paramValue);
                    }
                    break;
                }
            }

        }
    }
}

From source file:com.savor.ads.core.ApiRequestFactory.java

public static HashMap<String, Object> getFormRequestWithoutSign(AppApi.Action action, Object params,
        Session appSession) throws UnsupportedEncodingException {
    if (params == null) {
        return null;
    }//w ww .j a va  2s  .co m
    HashMap<String, Object> requestParams;
    if (params instanceof HashMap) {
        requestParams = (HashMap<String, Object>) params;
    } else {
        return null;
    }
    final Iterator<String> keySet = requestParams.keySet().iterator();
    //        ArrayList<NameValuePair> pm = new ArrayList<>();
    JSONObject jsonObject = new JSONObject();
    try {
        while (keySet.hasNext()) {
            final String key = keySet.next();
            //                pm.add(new BasicNameValuePair(key, (String) requestParams
            //                        .get(key)));
            jsonObject.put(key, requestParams.get(key));
        }

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return requestParams;
    //        return new UrlEncodedFormEntity(pm, HTTP.UTF_8);
}