Example usage for java.util HashMap get

List of usage examples for java.util HashMap get

Introduction

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

Prototype

public V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:cooccurrence.emf.java

/**
 * Method to populate the apache matrix from cooccur hashmap
 *
 * @param matrixR// w ww. j a va2  s. co  m
 * @param cooccur
 * @param rowStrings
 * @param colStrings
 */
private static void populateMatrixR(RealMatrix matrixR, HashMap<String, HashMap<String, Double>> cooccur,
        ArrayList<String> rowStrings, ArrayList<String> colStrings) {
    Iterator iter = cooccur.keySet().iterator();

    while (iter.hasNext()) {
        String row = iter.next().toString();
        int i = rowStrings.indexOf(row);
        HashMap<String, Double> inner = cooccur.get(row);
        for (String col : inner.keySet()) {
            int j = colStrings.indexOf(col);
            double val = inner.get(col);
            matrixR.setEntry(j, i, val); // each column in D represents the vector w-> d_w
        }
        iter.remove();
    }

}

From source file:org.zodiark.protocol.Envelope.java

public final static Envelope newEnvelope(HashMap<String, Object> envelope, ObjectMapper mapper)
        throws IOException {
    HashMap<String, Object> message = (HashMap<String, Object>) envelope.get("message");
    return new Envelope.Builder().path(new Path(notNull(envelope.get("path"))))
            .to(new To(notNull(envelope.get("to"))))

            .from(new From(notNull(envelope.get("from")))).traceId(new TraceId((int) envelope.get("traceId")))
            .message(new Message().setPath(notNull(message.get("path")))
                    .setData(notNull(encodeJSON(message.get("data"), mapper)))
                    .setUUID(notNull(message.get("uuid"))))
            .protocol(new Protocol(notNull(envelope.get("protocol")))).uuid(notNull(envelope.get("uuid")))
            .build();/*from  www.  j a  v  a  2  s. c om*/
}

From source file:org.ofbiz.party.tool.SmsSimpleClient.java

/**
 * ??/*from  w w  w . j  a  va2 s  . c  o m*/
 * @throws Exception
 */
public static Map<String, String> sendSingleMt(String mobileNo, String content) throws Exception {
    String scheduleDate = UtilDateTime.getDateTimeToString(UtilDateTime.nowTimestamp(), "yyyy-MM-dd HH:mm:ss"); //????2010-1-1,???)       
    //?url
    StringBuilder smsUrl = new StringBuilder();
    content = content + " " + shSign;//??        
    smsUrl.append(shUrl);
    //ID:1972 ??jkcs89 ?saic59161000
    //ID:1979 ??chev ?59161000  
    Debug.logInfo(smsUrl.toString(), module);
    HashMap<String, String> contentMap = new HashMap<String, String>();
    contentMap.put("action", shAction);
    contentMap.put("userid", shUserid);
    contentMap.put("account", shAccount);
    contentMap.put("password", shPassword);
    contentMap.put("mobile", mobileNo);
    contentMap.put("content", content);
    contentMap.put("sendTime", scheduleDate);

    String resStr = doPostRequest(smsUrl.toString(), contentMap);
    Debug.logInfo("sms:xmlrst::" + resStr, module);
    //??
    HashMap<String, String> pp = parseResStr(resStr);
    Debug.logInfo("sms:errTag::" + pp.get("errTag"), module);
    Debug.logInfo("sms:errCode::" + pp.get("errCode"), module);
    Debug.logInfo("sms:errMsg::" + pp.get("errMsg"), module);
    return pp;
}

From source file:net.triptech.metahive.model.Submission.java

/**
 * Count the submissions.//from ww w  . j ava2s.com
 *
 * @param filter the filter
 * @return the long
 */
public static long countSubmissions(final SubmissionFilter filter) {

    StringBuilder sql = new StringBuilder("SELECT COUNT(s) FROM Submission s");
    sql.append(buildWhere(filter));

    TypedQuery<Long> q = entityManager().createQuery(sql.toString(), Long.class);

    HashMap<String, Long> variables = buildVariables(filter);
    for (String variable : variables.keySet()) {
        q.setParameter(variable, variables.get(variable));
    }

    return q.getSingleResult();
}

From source file:de.hbz.lobid.helper.CompareJsonMaps.java

private static void handleOrderedValues(final HashMap<String, String> actualMap,
        final Entry<String, String> e) {
    CompareJsonMaps.logger.debug("Test if proper order for: " + e.getKey());
    if (actualMap.containsKey(e.getKey())) {
        CompareJsonMaps.logger.trace("Existing as expected: " + e.getKey());
        if (e.getValue().equals(actualMap.get(e.getKey()))) {
            CompareJsonMaps.logger.trace("Equality:\n" + e.getValue() + "\n" + actualMap.get(e.getKey()));
            actualMap.remove(e.getKey());
        } else//w ww.  ja  v a 2 s .  c  o  m
            CompareJsonMaps.logger.debug("...but not equal! Will fail");
    } else {
        CompareJsonMaps.logger.warn("Missing: " + e.getKey() + " , will fail");
    }
}

From source file:uk.dsxt.voting.tests.TestDataGenerator.java

private static VoteResult generateVote(String id, HashMap<String, BigDecimal> securities, Voting voting) {
    VoteResult vote = new VoteResult(voting.getId(), id, securities.get(SECURITY));
    for (int j = 0; j < voting.getQuestions().length; j++) {
        String questionId = voting.getQuestions()[j].getId();

        if (voting.getQuestions()[j].isCanSelectMultiple()) {
            BigDecimal totalSum = BigDecimal.ZERO;
            for (int i = 0; i < voting.getQuestions()[j].getAnswers().length; i++) {
                String answerId = voting.getQuestions()[j].getAnswers()[i].getId();
                int amount = randomInt(0, vote.getPacketSize().subtract(totalSum).intValue());
                BigDecimal voteAmount = new BigDecimal(amount);
                totalSum = totalSum.add(voteAmount);
                if (voteAmount.compareTo(BigDecimal.ZERO) > 0)
                    vote.setAnswer(questionId, answerId, voteAmount);
            }/*from  w  w w  . jav a 2  s  . c o m*/
        } else {
            String answerId = voting.getQuestions()[j].getAnswers()[randomInt(0,
                    voting.getQuestions()[j].getAnswers().length - 1)].getId();
            BigDecimal voteAmount = new BigDecimal(randomInt(0, vote.getPacketSize().intValue()));
            if (voteAmount.compareTo(BigDecimal.ZERO) > 0)
                vote.setAnswer(questionId, answerId, voteAmount);
        }
    }
    return vote;
}

From source file:com.hoccer.http.AsyncHttpRequest.java

public static void setTypeAndFilename(GenericStreamableContent contentReceiver, HashMap<String, String> headers,
        String uri) {/*from w  w  w  .  j  a v a  2  s.com*/
    String type = headers.get("Content-Type");
    if (type == null) {
        type = "text/plain";
    }

    contentReceiver.setContentType(type);

    String filename = headers.get("Content-Disposition");
    if (filename == null || !filename.matches(".*filename=\".*\"")) {
        filename = uri.substring(uri.lastIndexOf('/'));
    } else {
        filename = filename.substring(filename.indexOf("filename=\"") + 10, filename.length() - 1);
    }
    contentReceiver.setFilename(filename);
}

From source file:Main.java

static String generateURLForm(HashMap<String, String> data) throws UnsupportedEncodingException {
    Set<String> keys = data.keySet();
    Iterator<String> keyIterator = keys.iterator();
    String content = "";
    for (int i = 0; keyIterator.hasNext(); i++) {
        String key = keyIterator.next();
        if (i != 0) {
            content += "&";
        }//from   w w  w .  j a  va2 s.co  m
        content += key + "=" + URLEncoder.encode(data.get(key), "UTF-8");
    }
    return content;
}

From source file:net.triptech.metahive.model.Submission.java

/**
 * Find submission entries./*from  w  w  w . j a v a  2 s  . co  m*/
 *
 * @param filter the submission filter
 * @param firstResult the first result
 * @param maxResults the max results
 * @return the list
 */
public static List<Submission> findSubmissionEntries(final SubmissionFilter filter, final int firstResult,
        final int maxResults) {

    StringBuilder sql = new StringBuilder("SELECT s FROM Submission s");
    sql.append(buildWhere(filter));
    sql.append(" ORDER BY s.created ASC");

    TypedQuery<Submission> q = entityManager().createQuery(sql.toString(), Submission.class)
            .setFirstResult(firstResult).setMaxResults(maxResults);

    HashMap<String, Long> variables = buildVariables(filter);
    for (String variable : variables.keySet()) {
        q.setParameter(variable, variables.get(variable));
    }

    return q.getResultList();
}

From source file:cd.go.contrib.elasticagents.dockerswarm.elasticagent.DockerSecrets.java

private static Map<String, String> lineToMap(String content) {
    final String[] properties = content.split(",");
    final HashMap<String, String> map = new HashMap<>();
    for (String property : properties) {
        if (property.contains("=")) {
            final String[] parts = property.split("=", 2);
            map.put(stripToEmpty(parts[0]).toLowerCase(), stripToEmpty(parts[1]));
        }/*from  w  w  w .  ja  v  a2s  . c  om*/
    }

    if (isBlank(map.get("src"))) {
        throw new RuntimeException(
                format("Invalid secret specification `{0}`. Must specify property `src` with value.", content));
    }

    return map;
}