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:com.thesmartweb.swebrank.DataManipulation.java

/**
 * Method that sorts a HashMap according to their values
 * @param map the HashMap to be sorted/*  ww w.ja va2  s .c o  m*/
 * @return a List that contains the keys in sorted (descending) fashion
 */
public List<String> sortHashmap(final HashMap<String, Double> map) {
    Set<String> set = map.keySet();
    List<String> keys = new ArrayList<String>(set);
    Collections.sort(keys, new Comparator<String>() {
        @Override
        public int compare(String s1, String s2) {
            return Double.compare(map.get(s2), map.get(s1));
        }
    });
    return keys;
}

From source file:com.aspire.mandou.framework.http.HttpPost.java

HttpPost(AbstractHttpClient httpClient, String url, HttpEntity payload,
        HashMap<String, String> defaultHeaders) {
    super(httpClient);
    this.request = new org.apache.http.client.methods.HttpPost(url);
    ((HttpEntityEnclosingRequest) request).setEntity(payload);

    request.setHeader(HTTP_CONTENT_TYPE_HEADER, payload.getContentType().getValue());
    for (String header : defaultHeaders.keySet()) {
        request.setHeader(header, defaultHeaders.get(header));
    }/*from  w  ww .  jav  a 2s . c o m*/
}

From source file:info.plugmania.mazemania.Util.java

public boolean compare(HashMap<String, String> event, HashMap<String, String> entry) {
    for (String s : entry.keySet()) {
        if (!event.containsKey(s))
            return false;
        if ((event.get(s) != entry.get(s)) && (entry.get(s) != "*"))
            return false;
    }/*  w w  w .j  av  a2  s. co m*/
    return true;
}

From source file:com.aquest.emailmarketing.web.service.SendEmail.java

/**
 * Send email./*  ww w  .j  a va  2s.  c  om*/
 *
 * @param broadcast the broadcast
 * @param emailConfig the email config
 * @param emailList the email list
 * @throws EmailException the email exception
 * @throws MalformedURLException the malformed url exception
 * @throws InterruptedException the interrupted exception
 */
@Async
public void sendEmail(Broadcast broadcast, EmailConfig emailConfig, EmailList emailList)
        throws EmailException, MalformedURLException, InterruptedException {

    Timestamp curTimestamp = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime());
    // email configuration part
    HtmlEmail email = new HtmlEmail();
    email.setSmtpPort(emailConfig.getPort());
    email.setHostName(emailConfig.getHostname());
    email.setAuthenticator(new DefaultAuthenticator(emailConfig.getUsername(), emailConfig.getPassword()));
    email.setSSLOnConnect(emailConfig.isSslonconnect());
    email.setDebug(emailConfig.isDebug());
    email.setFrom(emailConfig.getFrom_address()); //ovde dodati i email from description

    System.out.println(emailList);
    HashMap<String, String> variables = processVariableService.ProcessVariable(emailList);

    for (String keys : variables.keySet()) {
        System.out.println("key:" + keys + ", value:" + variables.get(keys));
    }

    String processSubject = broadcast.getSubject();
    String newHtml = broadcast.getHtmlbody_embed();
    String newPlainText = broadcast.getPlaintext();

    for (String key : variables.keySet()) {
        processSubject = processSubject.replace("[" + key + "]", variables.get(key));
        System.out.println(key + "-" + variables.get(key));
        newHtml = newHtml.replace("[" + key + "]", variables.get(key));
        newPlainText = newPlainText.replace("[" + key + "]", variables.get(key));
    }
    System.out.println(processSubject);
    email.setSubject(processSubject);
    email.addTo(emailList.getEmail());

    String image = embeddedImageService.getEmbeddedImages(broadcast.getBroadcast_id()).getUrl();
    List<String> images = Arrays.asList(image.split(";"));
    for (int j = 0; j < images.size(); j++) {
        System.out.println(images.get(j));
    }
    for (int i = 0; i < images.size(); i++) {
        String id = email.embed(images.get(i), "Slika" + i);
        newHtml = newHtml.replace("[IMAGE:" + i + "]", "cid:" + id);
    }

    Config config = configService.getConfig("trackingurl");
    //DONE: Create jsp page for tracking server url
    String serverUrl = config.getValue();
    System.out.println(serverUrl);
    Base64 base64 = new Base64(true);

    Pattern pattern = Pattern.compile("<%tracking=(.*?)=tracking%>");
    Matcher matcher = pattern.matcher(newHtml);
    while (matcher.find()) {
        String url = matcher.group(1);
        System.out.println(url);
        logger.debug(url);
        String myEncryptedUrl = new String(base64.encode(url.getBytes()));

        String oldurl = "<%tracking=" + url + "=tracking%>";
        logger.debug(oldurl);
        System.out.println(oldurl);
        String newurl = serverUrl + "tracking?id=" + myEncryptedUrl;
        logger.debug(newurl);
        System.out.println(newurl);
        newHtml = newHtml.replace(oldurl, newurl);
    }
    //        System.out.println(newHtml);

    email.setHtmlMsg(newHtml);
    email.setTextMsg(newPlainText);
    try {
        System.out.println("A ovo ovde?");
        email.send();
        emailList.setStatus("SENT");
        emailList.setProcess_dttm(curTimestamp);
        emailListService.SaveOrUpdate(emailList);
    } catch (Exception e) {
        logger.error(e);
    }
    // time in seconds to wait between 2 mails
    TimeUnit.SECONDS.sleep(emailConfig.getWait());
}

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

/**
 * This is used in the generation process.
 * @param topK number of candidates to return
 * @param word1/* w  w  w  . j av a  2s .  c om*/
 * @param maxSubstringLength
 * @param probMap a hashmap for productions, same as probs, but with no weights
 * @param probs
 * @param memoizationTable
 * @param pruneToSize
 * @return
 */
public static TopList<Double, String> Predict2(int topK, String word1, int maxSubstringLength,
        Map<String, HashSet<String>> probMap, HashMap<Production, Double> probs,
        HashMap<String, HashMap<String, Double>> memoizationTable, int pruneToSize) {
    TopList<Double, String> result = new TopList<>(topK);
    // calls a helper function
    HashMap<String, Double> rProbs = Predict2(word1, maxSubstringLength, probMap, probs, memoizationTable,
            pruneToSize);
    double probSum = 0;

    // gathers the total probability for normalization.
    for (double prob : rProbs.values())
        probSum += prob;

    // this normalizes each value by the total prob.
    for (String key : rProbs.keySet()) {
        Double value = rProbs.get(key);
        result.add(new Pair<>(value / probSum, key));
    }

    return result;
}

From source file:com.imag.nespros.runtime.algoritms.Solution.java

private void setComputer2Op(HashMap<EPUnit, Device> op2Comp) {
    computer2Op.clear();//w  w  w  .ja  v a  2  s  .  c  o m
    for (Device c : op2Comp.values()) {
        ArrayList<EPUnit> operators = new ArrayList<>();
        for (EPUnit op : op2Comp.keySet()) {
            if (op2Comp.get(op) == c) {
                operators.add(op);
            }
        }
        computer2Op.put(c, operators);
    }
}

From source file:com.tealeaf.Downloader.java

public HashMap<String, File> download(HashMap<String, String> uris) {
    HashMap<String, File> files = new HashMap<String, File>();
    if (uris == null) {
        return null;
    }//ww  w . jav a 2s .co m

    String[] urls = new String[uris.size()];
    uris.keySet().toArray(urls);
    for (String url : urls) {
        if (cached(uris.get(url))) {
            logger.log("{downloader}", uris.get(url), "is cached");
            continue;
        }
        File f = http.getFile(URI.create(url), uris.get(url));
        if (f != null) {
            logger.log("{downloader} Downloading updated file", url, "to", f.getAbsolutePath());
            files.put(url, f);
        } else {
            logger.log("{downloader} ERROR: Unable to download file", url);
            return null;
        }
    }
    return files;
}

From source file:com.thesmartweb.swebrank.DataManipulation.java

public HashMap sortHashMapByValuesD(HashMap passedMap) {
    List mapKeys = new ArrayList(passedMap.keySet());
    List mapValues = new ArrayList(passedMap.values());
    Collections.sort(mapValues);//from  w  w  w  .  ja  va  2  s .c om
    Collections.sort(mapKeys);

    HashMap sortedMap = new HashMap();

    Iterator valueIt = mapValues.iterator();
    while (valueIt.hasNext()) {
        Object val = valueIt.next();
        Iterator keyIt = mapKeys.iterator();

        while (keyIt.hasNext()) {
            Object key = keyIt.next();
            String comp1 = passedMap.get(key).toString();
            String comp2 = val.toString();

            if (comp1.equals(comp2)) {
                passedMap.remove(key);
                mapKeys.remove(key);
                sortedMap.put((String) key, (Double) val);
                break;
            }

        }

    }
    return sortedMap;
}

From source file:Exporters.SaveFileExporter.java

public Element getVulnAsElement(Vulnerability vuln, Document doc) {

    Base64 b64 = new Base64();

    Element vulnElement = doc.createElement("vuln");
    if (vuln.isIs_custom_risk() == false) {
        vulnElement.setAttribute("custom-risk", "false");
        vulnElement.setAttribute("cvss", vuln.getCvss_vector_string());
    } else {//ww w.j a v  a2  s.c  om
        vulnElement.setAttribute("custom-risk", "true");
    }
    vulnElement.setAttribute("category", vuln.getRisk_category());
    vulnElement.setAttribute("risk-score", "" + vuln.getRiskScore());

    Element vulnTitle = doc.createElement("title");
    vulnTitle.appendChild(doc.createTextNode(b64.encodeAsString(vuln.getTitle().getBytes())));

    Element identifiersElement = doc.createElement("identifiers");
    HashMap identifiersMap = vuln.getIdentifiers();
    Iterator it = identifiersMap.keySet().iterator();
    while (it.hasNext()) {
        String hashed_title = (String) it.next();
        String import_tool = (String) identifiersMap.get(hashed_title);
        // add a tag mofo!
        Element identifier = doc.createElement("identifier");
        identifier.setAttribute("hash", hashed_title);
        identifier.setAttribute("import_tool", import_tool);
        identifiersElement.appendChild(identifier);
    }

    Element vulnDescription = doc.createElement("description");
    vulnDescription.appendChild(doc.createTextNode(b64.encodeAsString(vuln.getDescription().getBytes())));

    Element vulnRecommendation = doc.createElement("recommendation");
    vulnRecommendation.appendChild(doc.createTextNode(b64.encodeAsString(vuln.getRecommendation().getBytes())));

    //TODO Fill out <References> tag
    Element vulnReferences = doc.createElement("references");
    Enumeration refs_enums = vuln.getReferences().elements();
    while (refs_enums.hasMoreElements()) {
        Reference ref = (Reference) refs_enums.nextElement();
        Element vulnReference = doc.createElement("reference");
        vulnReference.setAttribute("description", ref.getDescription());
        vulnReference.appendChild(doc.createTextNode(ref.getUrl()));
        vulnReferences.appendChild(vulnReference);
    }

    Element affectedHosts = doc.createElement("affected-hosts");
    Enumeration enums = vuln.getAffectedHosts().elements();
    while (enums.hasMoreElements()) {
        Host host = (Host) enums.nextElement();

        // Create all the lovely element nodes
        Element affectedHost = doc.createElement("host");
        Element ipAddress = doc.createElement("ip-address");
        if (host.getIp_address() != null) {
            ipAddress.appendChild(doc.createTextNode(host.getIp_address()));
        }
        Element hostname = doc.createElement("hostname");
        if (host.getHostname() != null) {
            hostname.appendChild(doc.createTextNode(host.getHostname()));
        }
        Element netbios = doc.createElement("netbios-name");
        if (host.getNetbios_name() != null) {
            netbios.appendChild(doc.createTextNode(host.getNetbios_name()));
        }
        Element os = doc.createElement("operating-system");
        if (host.getOperating_system() != null) {
            os.appendChild(doc.createTextNode(host.getOperating_system()));
        }
        Element macAddress = doc.createElement("mac-address");
        if (host.getMac_address() != null) {
            macAddress.appendChild(doc.createTextNode(host.getMac_address()));
        }
        Element portnumber = doc.createElement("portnumber");
        if (host.getPortnumber() != null) {
            portnumber.appendChild(doc.createTextNode(host.getPortnumber()));
        }
        Element protocol = doc.createElement("protocol");
        if (host.getProtocol() != null) {
            protocol.appendChild(doc.createTextNode(host.getProtocol()));
        }

        Element note = doc.createElement("note");
        if (host.getNotes() != null) {
            Note n = host.getNotes();
            note.appendChild(doc.createTextNode(b64.encodeAsString(n.getNote_text().getBytes())));
        }

        // Append them to the affected Host node
        affectedHost.appendChild(ipAddress);
        affectedHost.appendChild(hostname);
        affectedHost.appendChild(netbios);
        affectedHost.appendChild(os);
        affectedHost.appendChild(macAddress);
        affectedHost.appendChild(portnumber);
        affectedHost.appendChild(protocol);
        affectedHost.appendChild(note);

        // Add that host to the affected hosts node
        affectedHosts.appendChild(affectedHost);
    }

    vulnElement.appendChild(vulnTitle);
    vulnElement.appendChild(identifiersElement);
    vulnElement.appendChild(vulnDescription);
    vulnElement.appendChild(vulnRecommendation);
    vulnElement.appendChild(vulnReferences);
    vulnElement.appendChild(affectedHosts);
    return vulnElement;
}

From source file:org.socraticgrid.codeconversion.matchers.DescMatch.java

@Override
protected boolean match_TL_CA_DL(CodeSearch matchCd, List<CodeReference> outList) {
    TargetSystemCodeMap map = tsMap.get(matchCd.getTargetSystem());

    if (map != null) {

        if (map.SrchMap.containsKey(matchCd.getDisplay())) {
            HashMap<String, SourceCoding> sysMap = map.SrchMap.get(matchCd.getDisplay());

            Iterator<String> sysItr = sysMap.keySet().iterator();

            while (sysItr.hasNext()) {
                SourceCoding sc = sysMap.get(sysItr.next());

                outList.add(new CodeReference(matchCd.getTargetSystem(), sc.getTargetCode(), sc.getSourceName(),
                        sc.getSourceNote()));
            }//from   ww w.j a  va 2s . co m
        }
    }

    return true;
}