Example usage for java.util Map keySet

List of usage examples for java.util Map keySet

Introduction

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

Prototype

Set<K> keySet();

Source Link

Document

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

Usage

From source file:io.s4.comm.util.JSONUtil.java

public static JSONObject toJSONObject(Map<String, Object> map) {
    JSONObject jsonObject = new JSONObject();
    try {/*from   w  w  w.j  a va 2 s  . c  om*/
        for (String key : map.keySet()) {
            Object val = map.get(key);
            if (val instanceof Map) {
                jsonObject.put(key, toJSONObject((Map<String, Object>) val));
            } else if (val instanceof List) {
                jsonObject.put(key, toJSONList((List) val));
            } else {
                jsonObject.put(key, val);
            }
        }
    } catch (JSONException je) {
        je.printStackTrace();
        return null;
    }
    return jsonObject;
}

From source file:org.wso2.dss.integration.test.odata.ODataTestUtils.java

public static int sendDELETE(String endpoint, Map<String, String> headers) throws IOException {
    HttpClient httpClient = new DefaultHttpClient();
    HttpDelete httpDelete = new HttpDelete(endpoint);
    for (String headerType : headers.keySet()) {
        httpDelete.setHeader(headerType, headers.get(headerType));
    }/*from   ww w  .j a v a 2s.  co m*/
    HttpResponse httpResponse = httpClient.execute(httpDelete);
    return httpResponse.getStatusLine().getStatusCode();
}

From source file:com.boyuanitsm.pay.alipay.util.AlipayCore.java

/** 
 * ???/*w  w w. j  a  v  a  2s .c  o m*/
 * @param sArray ???
 * @return ???????
 */
public static Map<String, String> paraFilter(Map<String, String> sArray) {

    Map<String, String> result = new HashMap<String, String>();

    if (sArray == null || sArray.size() <= 0) {
        return result;
    }

    for (String key : sArray.keySet()) {
        String value = sArray.get(key);
        if (value == null || value.equals("") || key.equalsIgnoreCase("sign")
                || key.equalsIgnoreCase("sign_type")) {
            continue;
        }
        result.put(key, value);
    }

    return result;
}

From source file:com.cloudera.flume.handlers.thrift.ThriftEventAdaptor.java

/**
 * This makes a thrift compatible copy of the event. It is here to encapsulate
 * future changes to the Event/ThriftFlumeEvent interface
 *///from www .  ja  v a 2 s.  c  o m
public static ThriftFlumeEvent convert(Event e) {
    ThriftFlumeEvent evt = new ThriftFlumeEvent();
    evt.timestamp = e.getTimestamp();
    evt.priority = convert(e.getPriority());
    ByteBuffer buf = ByteBuffer.wrap(e.getBody());
    evt.body = buf;
    evt.nanos = e.getNanos();
    evt.host = e.getHost();

    Map<String, byte[]> tempMap = e.getAttrs();
    Map<String, ByteBuffer> returnMap = new HashMap<String, ByteBuffer>();
    for (String key : tempMap.keySet()) {
        buf.clear();
        buf = ByteBuffer.wrap(tempMap.get(key));
        returnMap.put(key, buf);
    }

    evt.fields = returnMap;
    return evt;
}

From source file:de.thischwa.pmcms.tool.compression.Zip.java

/**
 * A wrapper to {@link #compress(File, Map, IProgressMonitor)}.
 * //from  w  w  w .j  ava 2  s  .  c  o m
 * @param zip
 * @param entries
 * @param monitor Must be initialized by the caller.
 * @throws IOException
 */
public static void compressFiles(final File zip, final Map<File, String> entries,
        final IProgressMonitor monitor) throws IOException {
    if (zip == null || entries == null || CollectionUtils.isEmpty(entries.keySet()))
        throw new IllegalArgumentException("One ore more parameters are empty!");
    Map<InputStream, String> newEntries = new HashMap<InputStream, String>(entries.size());
    for (File file : entries.keySet()) {
        newEntries.put(new FileInputStream(file), entries.get(file));
    }
    compress(zip, newEntries, monitor);
}

From source file:net.recommenders.rival.evaluation.statistics.EffectSize.java

/**
 *
 * Estimation of effect size based on the distribution of score differences
 * (from paired samples).//from   w  w w  .  jav  a 2 s.com
 *
 * @param <V> type of the keys of each map.
 * @param baselineMetricPerDimension map for the baseline method, one value
 * for each user (dimension)
 * @param testMetricPerDimension map for the test method, one value for each
 * user (dimension)
 * @return the effect size.
 */
public static <V> double getEffectSizePairedT(final Map<V, Double> baselineMetricPerDimension,
        final Map<V, Double> testMetricPerDimension) {
    Set<V> overlap = new HashSet<V>(baselineMetricPerDimension.keySet());
    overlap.retainAll(testMetricPerDimension.keySet());

    SummaryStatistics differences = new SummaryStatistics();
    for (V key : overlap) {
        double diff = testMetricPerDimension.get(key) - baselineMetricPerDimension.get(key);
        differences.addValue(diff);
    }

    return getEffectSizePairedT(differences.getMean(), Math.sqrt(differences.getVariance()));
}

From source file:edu.msu.cme.rdp.rarefaction.RarefactionPlotter.java

public static void plotRarefaction(Map<ClusterSample, List<RarefactionResult>> rarefactionResults,
        File outputDirectory) throws IOException {
    if (!outputDirectory.isDirectory()) {
        throw new IOException(outputDirectory + " isn't a directory!");
    }/*from ww  w  . j  a v  a 2 s. c om*/

    for (ClusterSample sample : rarefactionResults.keySet()) {
        List<RarefactionResult> resultsToPlot = new ArrayList();

        int currCutoff = 0;
        RarefactionResult lastResult = null;
        for (RarefactionResult result : rarefactionResults.get(sample)) {
            if (result.getDistance() <= interestedPoints[currCutoff]) {
                lastResult = result;
            } else {
                if (lastResult != null) {
                    resultsToPlot.add(lastResult);

                    if (++currCutoff >= interestedPoints.length) {
                        break;
                    }
                }
            }
        }

        plotToFile(resultsToPlot, sample.getSeqs(), sample.getName() + " Rarefaction",
                new File(outputDirectory, sample.getName() + "_rarefaction.png"));
    }

}

From source file:com.cloudant.mazha.ClientTestUtils.java

/**
 * Create a conflicts to specified document using bulk api. The document is specified by <code>Response</code>,
 * which usually is the response back from <code>ClientTestUtils.createHelloWorldDoc</code>
 *
 * And, the document tree looks like this:
 *
 * 1 -> 2 -> 3/*from w ww .  ja va  2 s .  c o  m*/
 *  \-> 2*
 *  \-> 2**
 *
 * return all open revisions.
 */
public static String[] createDocumentWithConflicts(CouchClient client, Response res) {

    String rev1 = res.getRev();
    String rev2 = CouchUtils.generateNextRevisionId(rev1);
    String rev3 = CouchUtils.generateNextRevisionId(rev2);
    String rev2Star = CouchUtils.generateNextRevisionId(rev1);
    String rev2StarStar = CouchUtils.generateNextRevisionId(rev1);

    Map<String, Object> revs1 = getRevisionHistory(rev3, rev2, rev1);
    Map<String, Object> revs2 = getRevisionHistory(rev2Star, rev1);
    Map<String, Object> revs3 = getRevisionHistory(rev2StarStar, rev1);

    Map<String, Object> docToUpdate1 = updateDocumentWithRevisionHistory(client, res.getId(), rev3, revs1,
            "Tom");
    Map<String, Object> docToUpdate2 = updateDocumentWithRevisionHistory(client, res.getId(), rev2Star, revs2,
            "Jerry");
    Map<String, Object> docToUpdate3 = updateDocumentWithRevisionHistory(client, res.getId(), rev2StarStar,
            revs3, "Alex");

    List<Response> responses = client.bulk(docToUpdate1, docToUpdate2, docToUpdate3);

    Assert.assertThat("Responses list", responses.size(), is(equalTo(0)));

    Map<String, Object> updatedDoc = client.getDocument(res.getId());
    Assert.assertThat("Updated document", updatedDoc.keySet(), hasItem(CouchConstants._rev));
    Assert.assertThat("Current revision", (String) updatedDoc.get(CouchConstants._rev), startsWith("3-"));
    Assert.assertThat("Updated document", updatedDoc.keySet(), hasItem("name"));
    Assert.assertThat("Updated document", (String) updatedDoc.get("name"), is(equalTo("Tom")));

    return new String[] { rev3, rev2Star, rev2StarStar };
}

From source file:hermes.impl.HTMLBeanHelper.java

public static String format(String text, Map properties) {
    String rval = text;/*from  w w  w . ja v  a  2  s  .c  o  m*/
    StringBuffer buffer = new StringBuffer();

    if (properties != null) {
        if (text == null) {
            buffer.append("<html>");

            for (Iterator iter = properties.keySet().iterator(); iter.hasNext();) {
                String key = (String) iter.next();
                Object val = properties.get(key);

                if (!key.equals("reference")) // TODO huh?
                {
                    buffer.append(key).append("=").append(val);

                    if (iter.hasNext()) {
                        buffer.append("<br>");
                    }
                }
            }

            buffer.append("</html>");
        } else {
            for (Iterator iter = properties.keySet().iterator(); iter.hasNext();) {
                String key = (String) iter.next();
                Object val = properties.get(key);
                rval = rval.replaceAll("\\$" + key, (val == null) ? "null" : val.toString());
            }

            return rval;
        }
    }

    return buffer.toString();
}

From source file:com.rxx.common.util.MailUtil.java

/**
 * html/*from  www.  j av a  2s  .  c  o m*/
 *
 * @param host 
 * @param port
 * @param userName
 * @param password
 * @param title
 * @param contenthtml
 * @param fileslist<Map<key:,value:>>
 * @param toUser
 * @throws javax.mail.MessagingException
 */
public static void sendAttached(String host, int port, String userName, String password, String title,
        String content, List<Map<String, String>> files, String[] toUser)
        throws MessagingException, javax.mail.MessagingException {
    JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();

    // mail server
    senderImpl.setHost(host);
    // ,html
    MimeMessage mailMessage = senderImpl.createMimeMessage();
    // boolean,MimeMessageHelpertrue
    // multipart true html
    MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage, true, "utf-8");

    // 
    messageHelper.setTo(toUser);
    messageHelper.setFrom(userName);
    messageHelper.setSubject(title);
    // true HTML
    messageHelper.setText(content, true);

    for (Map<String, String> filePath : files) {
        Iterator<String> it = filePath.keySet().iterator();
        String fileName = it.next();
        FileSystemResource file = new FileSystemResource(new File(filePath.get(fileName)));
        // 
        messageHelper.addAttachment(fileName, file);
    }

    senderImpl.setUsername(userName); // ,username
    senderImpl.setPassword(password); // , password
    Properties prop = new Properties();
    prop.put("mail.smtp.auth", "true"); // true,
    prop.put("mail.smtp.timeout", "25000");
    senderImpl.setJavaMailProperties(prop);
    // 
    senderImpl.send(mailMessage);
}