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:amie.keys.CombinationsExplorationNew.java

private static HashMap<Rule, HashSet<String>> discoverConditionalKeysFirstLevel(
        HashMap<Rule, GraphNew> ruleToGraphNew, HashMap<Integer, GraphNew> instantiatedProperty2GraphNew) {
    Rule rule = new Rule();
    for (int conditionProperty : instantiatedProperty2GraphNew.keySet()) {
        GraphNew graph = instantiatedProperty2GraphNew.get(conditionProperty);
        String prop = id2Property.get(conditionProperty);

        Iterable<Rule> conditions = Utilities.getConditions(rule, prop, (int) support, kb);
        for (Rule conditionRule : conditions) {
            GraphNew newGraph = new GraphNew();
            discoverConditionalKeysForCondition(newGraph, graph, graph.topGraphNodes(), conditionRule);
            if (newGraph != null) {
                ruleToGraphNew.put(conditionRule, newGraph);
            }//w ww  . j a  v  a 2  s. c o m
        }
    }

    HashMap<Rule, HashSet<String>> newRuleToExtendWith = new HashMap<>();
    for (Rule conRule : ruleToGraphNew.keySet()) {
        GraphNew newGraph = ruleToGraphNew.get(conRule);
        HashSet<String> properties = new HashSet<>();
        for (Node node : newGraph.topGraphNodes()) {
            if (node.toExplore) {
                Iterator<Integer> it = node.set.iterator();
                int prop = it.next();
                String propertyStr = id2Property.get(prop);
                properties.add(propertyStr);
            }

        }
        if (properties.size() != 0) {
            newRuleToExtendWith.put(conRule, properties);
        }
    }
    return newRuleToExtendWith;
}

From source file:gr.wavesoft.webng.io.web.WebStreams.java

public static HttpResponse httpGET(URL url, HashMap<String, String> headers) throws IOException {
    try {/*from   w  ww  . j  a  v  a2  s  . c om*/

        // WebRequest connection
        ClientConnectionRequest connRequest = connectionManager.requestConnection(
                new HttpRoute(new HttpHost(url.getHost(), url.getPort(), url.getProtocol())), null);

        ManagedClientConnection conn = connRequest.getConnection(10, TimeUnit.SECONDS);
        try {

            // Prepare request
            BasicHttpRequest request = new BasicHttpRequest("GET", url.getPath());

            // Setup headers
            if (headers != null) {
                for (String k : headers.keySet()) {
                    request.addHeader(k, headers.get(k));
                }
            }

            // Send request
            conn.sendRequestHeader(request);

            // Fetch response
            HttpResponse response = conn.receiveResponseHeader();
            conn.receiveResponseEntity(response);

            HttpEntity entity = response.getEntity();
            if (entity != null) {
                BasicManagedEntity managedEntity = new BasicManagedEntity(entity, conn, true);
                // Replace entity
                response.setEntity(managedEntity);
            }

            // Do something useful with the response
            // The connection will be released automatically 
            // as soon as the response content has been consumed
            return response;

        } catch (IOException ex) {
            // Abort connection upon an I/O error.
            conn.abortConnection();
            throw ex;
        }

    } catch (HttpException ex) {
        throw new IOException("HTTP Exception occured", ex);
    } catch (InterruptedException ex) {
        throw new IOException("InterruptedException", ex);
    } catch (ConnectionPoolTimeoutException ex) {
        throw new IOException("ConnectionPoolTimeoutException", ex);
    }

}

From source file:EmailAliases.java

private EmailAliases(HashMap<String, String> h) {
    aliases = h.keySet();
}

From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java

public static HashMap<String, Double> GetNgramProbs(int minN, int maxN, Iterable<String> examples) {
    HashMap<String, Double> result = new HashMap<>();

    for (int i = minN; i <= maxN; i++) {
        HashMap<String, Double> map = GetFixedSizeNgramProbs(i, examples);
        for (String key : map.keySet()) {
            double value = map.get(key);
            result.put(key, value);/*from   w w  w . jav  a  2s  . c o m*/
        }
    }

    return result;
}

From source file:org.samjoey.graphing.GraphUtility.java

public static HashMap<String, ChartPanel> getGraphs(LinkedList<Game> games) {
    HashMap<String, XYSeriesCollection> datasets = new HashMap<>();
    for (int j = 0; j < games.size(); j++) {
        Game game = games.get(j);//from   w ww  .  j a  v  a2s . co m
        if (game == null) {
            continue;
        }
        for (String key : game.getVarData().keySet()) {
            if (datasets.containsKey(key)) {
                try {
                    datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
                } catch (Exception e) {
                }
            } else {
                datasets.put(key, new XYSeriesCollection());
                datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
            }
        }
    }
    HashMap<String, ChartPanel> chartPanels = new HashMap<>();
    for (String key : datasets.keySet()) {
        JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title
                "X", // x axis label
                "Y", // y axis label
                datasets.get(key), // data
                PlotOrientation.VERTICAL, false, // include legend
                true, // tooltips
                false // urls
        );
        XYPlot plot = chart.getXYPlot();
        XYItemRenderer rend = plot.getRenderer();
        for (int i = 0; i < games.size(); i++) {
            Game g = games.get(i);
            if (g.getWinner() == 1) {
                rend.setSeriesPaint(i, Color.RED);
            }
            if (g.getWinner() == 2) {
                rend.setSeriesPaint(i, Color.BLACK);
            }
            if (g.getWinner() == 0) {
                rend.setSeriesPaint(i, Color.PINK);
            }
        }
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanels.put(key, chartPanel);
    }
    return chartPanels;
}

From source file:org.matsim.contrib.parking.parkingchoice.lib.GeneralLib.java

public static void writeHashMapToFile(HashMap hm, String headerLine, String fileName) {
    ArrayList<String> list = new ArrayList<String>();
    list.add(headerLine);/*from  ww w  . j  av  a2 s. c  om*/

    for (Object key : hm.keySet()) {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(key.toString());
        stringBuffer.append("\t");
        stringBuffer.append(hm.get(key).toString());
        list.add(stringBuffer.toString());
    }

    GeneralLib.writeList(list, fileName);
}

From source file:com.google.gwt.emultest.java.util.HashMapTest.java

/**
 * Check the state of a newly constructed, empty HashMap.
 *
 * @param hashMap/*  w  w  w.j  a v a2  s .  co  m*/
 */
private static void checkEmptyHashMapAssumptions(HashMap<?, ?> hashMap) {
    assertNotNull(hashMap);
    assertTrue(hashMap.isEmpty());

    assertNotNull(hashMap.values());
    assertTrue(hashMap.values().isEmpty());
    assertTrue(hashMap.values().size() == 0);

    assertNotNull(hashMap.keySet());
    assertTrue(hashMap.keySet().isEmpty());
    assertTrue(hashMap.keySet().size() == 0);

    assertNotNull(hashMap.entrySet());
    assertTrue(hashMap.entrySet().isEmpty());
    assertTrue(hashMap.entrySet().size() == 0);

    assertEmptyIterator(hashMap.entrySet().iterator());
}

From source file:it.acubelab.smaph.SmaphAnnotator.java

/**
 * Add all records contained in the cache passed by argument to the static
 * cache, overwriting in case of conflicting keys.
 * //from w  w  w.  j av a  2  s . c om
 * @param newCache
 *            the cache whose records are added.
 */
public static void mergeCache(HashMap<String, byte[]> newCache) {
    for (String key : newCache.keySet()) {
        url2jsonCache.put(key, newCache.get(key));
        flushCounter++;
    }
}

From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java

/**
 * This is the same as probs, only in a more convenient format. Does not include weights on productions.
 * @param probs production probabilities
 * @return hashmap mapping from Production[0] => Production[1]
 */// w  w w . ja  va2  s  .c  o m
public static HashMap<String, HashSet<String>> GetProbMap(HashMap<Production, Double> probs) {
    HashMap<String, HashSet<String>> result = new HashMap<>();
    for (Production pair : probs.keySet()) {
        if (!result.containsKey(pair.getFirst())) {
            result.put(pair.getFirst(), new HashSet<String>());
        }
        HashSet<String> set = result.get(pair.getFirst());
        set.add(pair.getSecond());

        result.put(pair.getFirst(), set);
    }

    return result;
}

From source file:com.act.reachables.Network.java

public static JSONObject get(MongoDB db, Set<Node> nodes, Set<Edge> edges, HashMap<Long, Long> parentIds,
        HashMap<Long, Edge> toParentEdges) throws JSONException {
    // init the json object with structure:
    // {/*from ww w. ja  v  a 2s.  c o m*/
    //   "name": "nodeid"
    //   "children": [
    //     { "name": "childnodeid", toparentedge: {}, nodedata:.. }, ...
    //   ]
    // }

    HashMap<Long, Node> nodeById = new HashMap<>();
    for (Node n : nodes)
        nodeById.put(n.id, n);

    HashMap<Long, JSONObject> nodeObjs = new HashMap<>();
    // un-deconstruct tree...
    for (Long nid : parentIds.keySet()) {
        JSONObject nObj = JSONHelper.nodeObj(db, nodeById.get(nid));
        nObj.put("name", nid);

        if (toParentEdges.get(nid) != null) {
            JSONObject eObj = JSONHelper.edgeObj(toParentEdges.get(nid),
                    null /* no ordering reqd for referencing nodeMapping */);
            nObj.put("edge_up", eObj);
        } else {
        }
        nodeObjs.put(nid, nObj);
    }

    // now that we know that each node has an associated obj
    // link the objects together into the tree structure
    // put each object inside its parent
    HashSet<Long> unAssignedToParent = new HashSet<>(parentIds.keySet());
    for (Long nid : parentIds.keySet()) {
        JSONObject child = nodeObjs.get(nid);
        // append child to "children" key within parent
        JSONObject parent = nodeObjs.get(parentIds.get(nid));
        if (parent != null) {
            parent.append("children", child);
            unAssignedToParent.remove(nid);
        } else {
        }
    }

    // outputting a single tree makes front end processing easier
    // we can always remove the root in the front end and get the forest again

    // if many trees remain, assuming they indicate a disjoint forest,
    //    add then as child to a proxy root.
    // if only one tree then return it

    JSONObject json;
    if (unAssignedToParent.size() == 0) {
        json = null;
        throw new RuntimeException("All nodeMapping have parents! Where is the root? Abort.");
    } else if (unAssignedToParent.size() == 1) {
        json = unAssignedToParent.toArray(new JSONObject[0])[0]; // return the only element in the set
    } else {
        json = new JSONObject();
        for (Long cid : unAssignedToParent) {
            json.put("name", "root");
            json.append("children", nodeObjs.get(cid));
        }
    }

    return json;
}