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:cz.filmtit.userspace.Emailer.java

/**
 * Loads the configuration from project configuration to the Emailer properties.
 *//*from  ww  w.j a v  a 2 s  .  c o m*/
private void fetchConfig() {
    java.io.InputStream input = null;

    // read configuration from configuration.xml
    HashMap<String, String> mailconfig = ConfigurationSingleton.conf().configMail();
    for (String key : mailconfig.keySet()) {
        configuration.setProperty(key, mailconfig.get(key));
    }

}

From source file:mml.handler.get.MMLGetImgHandler.java

/**
 * Create the list of images/*from w  w  w .  j av  a2 s  .  c  o m*/
 * @param req the http request
 * @param map the page reference to dimensions map
 * @return the images as a sequence of IMGs inside divs
 */
String createImgs(HttpServletRequest req, HashMap<String, String> map) {
    Element images = new Element("div");
    images.addAttribute("id", "images");
    Set<String> keys = map.keySet();
    String[] names = new String[keys.size()];
    keys.toArray(names);
    if (pageRefs == null) {
        ImageComparator comp = new ImageComparator();
        Arrays.sort(names, comp);
    } else {
        names = sortByPageRefs(names);
    }
    for (String name : names) {
        String jDoc = map.get(name);
        JSONObject info = (JSONObject) JSONValue.parse(jDoc);
        Element wrap = new Element("div");
        wrap.addAttribute("class", "image");
        Element img = new Element("img");
        String jDocId = (String) info.get(JSONKeys.DOCID);
        String src = "/" + jDocId;
        img.addAttribute("src", src);
        img.addAttribute("id", "image_" + name);
        //String mimetype = (String)info.get("mimetype");
        int width = ((Number) info.get("width")).intValue();
        int height = ((Number) info.get("height")).intValue();
        img.addAttribute("style", "width: 100%; max-width: " + width + "px");
        img.addAttribute("data-width", Integer.toString(width));
        img.addAttribute("data-height", Integer.toString(height));
        img.addAttribute("data-ref", name);
        wrap.addChild(img);
        images.addChild(wrap);
    }
    return images.toString();
}

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

public static JSONArray get(MongoDB db, Set<Node> nodes, Set<Edge> edges) throws JSONException {
    // init the json object with structure:
    // {/* w w w. j a v  a 2 s.com*/
    //   "nodeMapping":[
    //     { "name":"Myriel", "group":1 }, ...
    //   ],
    //   "links":[
    //     { "source":1, "target":0, "value":1 }, ...
    //   ]
    // }
    // nodeMapping.group specifies the node color
    // links.value specifies the edge weight
    JSONArray json = new JSONArray();

    HashMap<Long, Set<Node>> treenodes = new HashMap<Long, Set<Node>>();
    HashMap<Long, Set<Edge>> treeedges = new HashMap<Long, Set<Edge>>();
    for (Node n : nodes) {
        Long k = (Long) n.getAttribute("under_root");
        if (!treenodes.containsKey(k)) {
            treenodes.put(k, new HashSet<Node>());
            treeedges.put(k, new HashSet<Edge>());
        }
        treenodes.get(k).add(n);
    }

    for (Edge e : edges) {
        Long k = (Long) e.getAttribute("under_root");
        if (!treeedges.containsKey(k)) {
            throw new RuntimeException("Fatal: Edge found rooted under a tree (under_root) that has no node!");
        }
        treeedges.get(k).add(e);
    }

    for (Long root : treenodes.keySet()) {
        JSONObject tree = new JSONObject();
        HashMap<Node, Integer> nodeOrder = new HashMap<Node, Integer>();
        tree.put("nodeMapping", nodeListObj(db, treenodes.get(root), nodeOrder /*inits this ordering*/));
        tree.put("links", edgeListObj(treeedges.get(root), nodeOrder /* uses the ordering */));

        json.put(tree);
    }

    return json;

}

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

/**
 * What does this do? Largely calls CountWeightedAlignmentsHelper
 * @param word1//from ww w. j a  v  a2 s  . com
 * @param word2
 * @param maxSubstringLength1
 * @param maxSubstringLength2
 * @param probs
 * @param internTable
 * @param normalization
 * @param weightByContextOnly
 * @return
 */
public static HashMap<Production, Double> CountWeightedAlignments(String word1, String word2,
        int maxSubstringLength1, int maxSubstringLength2, HashMap<Production, Double> probs,
        InternDictionary<String> internTable, NormalizationMode normalization, Boolean weightByContextOnly) {
    //HashMap<Pair<String, String>, double> weights = new HashMap<Pair<String, String>, double>();
    //HashMap<Pair<String, String>, double> weightCounts = new HashMap<Pair<String, String>, double>();
    //FindWeightedAlignmentsAverage(1, new List<Pair<String, String>>(), word1, word2, maxSubstringLength1, maxSubstringLength2, probs, weights, weightCounts, new HashMap<Pair<String, String>, Pair<double, double>>(), weightByOthers);
    Pair<HashMap<Production, Double>, Double> Q = CountWeightedAlignmentsHelper(word1, word2,
            maxSubstringLength1, maxSubstringLength2, probs,
            new HashMap<Production, Pair<HashMap<Production, Double>, Double>>());
    HashMap<Production, Double> weights = Q.getFirst();
    double probSum = Q.getSecond(); //the sum of the probabilities of all possible alignments

    // this is where the 1/y normalization happens for this word pair.
    HashMap<Production, Double> weights_norm = new HashMap<>(weights.size());
    for (Production key : weights.keySet()) {
        Double value = weights.get(key);
        if (weightByContextOnly) {
            double originalProb = probs.get(key);
            weights_norm.put(key,
                    value == 0 ? 0 : (value / originalProb) / (probSum - value + (value / originalProb)));
        } else
            weights_norm.put(key, value == 0 ? 0 : value / probSum);
    }

    return Normalize(word1, word2, weights_norm, internTable, normalization);
}

From source file:com.apatar.core.ApatarHttpClient.java

public String sendPostHttpQuery(String url, HashMap<String, String> params) throws IOException {
    int size = params.size();
    Part[] parts = new Part[size];
    int i = 0;/*from  w ww.j a v a  2  s  . c om*/
    for (String param : params.keySet()) {
        parts[i++] = new StringPart(param, params.get(param));
    }

    PostMethod method = new PostMethod(url);

    method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));

    return sendHttpQuery(method);

}

From source file:de.tudarmstadt.ukp.dkpro.core.ixa.internal.IxaLemmatizerTagsetDescriptionProvider.java

@Override
public Set<String> listTags(String aLayer, String aTagsetName) {
    try {//from   w  w w .jav a  2s. co m
        AbstractModel innerModel = (AbstractModel) FieldUtils.readField(model, "model", true);
        HashMap<String, Integer> pmap = (HashMap<String, Integer>) FieldUtils.readField(innerModel, "pmap",
                true);

        Set<String> tagSet = new TreeSet<String>();
        String prefix = feature + separator;
        for (Object key : pmap.keySet()) {
            if (key instanceof String && ((String) key).startsWith(prefix)) {
                tagSet.add(StringUtils.substringAfter(((String) key), separator));
            }
        }

        return tagSet;
    } catch (IllegalAccessException e) {
        throw new IllegalStateException(e);
    }
}

From source file:de.uzk.hki.da.metadata.LidoMetadataStructure.java

public void replaceRefResources(HashMap<String, String> linkResourceReplacements) throws IOException {
    for (String sourceLinkResource : linkResourceReplacements.keySet()) {
        for (int i = 0; i < lidoLinkResources.size(); i++) {
            if (sourceLinkResource.equals(lidoLinkResources.get(i).getValue())) {
                lidoLinkResources.get(i).setText(linkResourceReplacements.get(sourceLinkResource));
            }/* w  ww  . j  a v  a  2  s  . co  m*/
        }
    }

    /*   XMLOutputter outputter = new XMLOutputter();
       outputter.setFormat(Format.getPrettyFormat());
       outputter.output(doc, new FileWriter(Path.makeFile(workPath,lidoFile.getPath())));
       */
    writeDocumentToFile(doc, Path.makeFile(workPath, lidoFile.getPath()));
}

From source file:gsn.wrappers.general.CSVWrapperTest.java

public boolean compare(HashMap<String, Serializable> a, HashMap<String, Serializable> b) {
    if (a.size() != b.size())
        return false;
    for (String key : a.keySet())
        if (!a.get(key).equals(b.get(key)))
            return false;
    return true;//from  w ww.  j  a v a 2s .c o  m
}

From source file:com.greenpepper.maven.plugin.FixtureGeneratorMojo.java

private void generateFixturesForDocument(Document doc) throws Exception {
    SpySystemUnderDevelopment spySut = new SpySystemUnderDevelopment();
    GreenPepperInterpreterSelector interpreterSelector = new GreenPepperInterpreterSelector(spySut);
    doc.addFilter(new CommentTableFilter());
    doc.addFilter(new GreenPepperTableFilter(false));
    doc.execute(interpreterSelector);//from w ww.  j  a v  a  2s  . c  om

    HashMap<String, SpyFixture> fixtures = spySut.getFixtures();
    for (String fixtureName : fixtures.keySet()) {
        SpyFixture spyFixture = fixtures.get(fixtureName);
        FixtureGenerator.Result result = actualFixtureGenerator.generateFixture(spyFixture, spySut,
                getFixtureSourceDirectory());
        File classSource = result.getFixtureFile();
        switch (result.getAction()) {
        case CREATED:
            getLog().info(format("\t %s: %s", "Generated",
                    difference(basedir.getAbsolutePath() + separator, classSource.getAbsolutePath())));
            break;
        case UPDATED:
            getLog().info(format("\t %s: %s", "Updated",
                    difference(basedir.getAbsolutePath() + separator, classSource.getAbsolutePath())));
            break;
        case NONE:
            getLog().debug(format("\t %s: %s", "Nothing done for",
                    difference(basedir.getAbsolutePath() + separator, classSource.getAbsolutePath())));
            break;
        }
        if (getLog().isDebugEnabled()) {
            getLog().debug(format("\t Code of fixtureName :\n %s", readFileToString(classSource)));
        }
    }
}