Example usage for java.util HashMap put

List of usage examples for java.util HashMap put

Introduction

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

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this map.

Usage

From source file:net.bioclipse.dbxp.business.DbxpManager.java

public static Map<String, Object> getSubjectsForStudy(String studyToken)
        throws NoSuchAlgorithmException, IOException {
    HashMap<String, String> formvars = new HashMap<String, String>();
    formvars.put("deviceID", getDeviceId());
    formvars.put("validation", getValidation());
    formvars.put("studyToken", studyToken);
    HttpResponse response = postValues(formvars, baseApiUrl + "getSubjectsForStudy");
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String json = "";
    String s = "";
    while ((s = stdInput.readLine()) != null) {
        json += s;// w  w w.java 2s  . co  m
    }
    Gson gson = new Gson();
    Map<String, Object> subjectsData = gson.fromJson(json, new TypeToken<Map<String, Object>>() {
    }.getType());
    return subjectsData;
}

From source file:net.bioclipse.dbxp.business.DbxpManager.java

public static Map<String, Object> getSamplesForAssay(String assayToken)
        throws NoSuchAlgorithmException, IOException {
    HashMap<String, String> formvars = new HashMap<String, String>();
    formvars.put("deviceID", getDeviceId());
    formvars.put("validation", getValidation());
    formvars.put("assayToken", assayToken);
    HttpResponse response = postValues(formvars, baseApiUrl + "getAssaysForStudy");
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String json = "";
    String s = "";
    while ((s = stdInput.readLine()) != null) {
        json += s;/*  ww w.j  a va  2 s.  co m*/
    }
    Gson gson = new Gson();
    Map<String, Object> subjectsData = gson.fromJson(json, new TypeToken<Map<String, Object>>() {
    }.getType());
    return subjectsData;
}

From source file:net.bioclipse.dbxp.business.DbxpManager.java

public static Map<String, Object> getMeasurementDataForAssay(String assayToken)
        throws NoSuchAlgorithmException, IOException {
    HashMap<String, String> formvars = new HashMap<String, String>();
    formvars.put("deviceID", getDeviceId());
    formvars.put("validation", getValidation());
    formvars.put("assayToken", assayToken);
    HttpResponse response = postValues(formvars, baseApiUrl + "getMeasurementDataForAssay");
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String json = "";
    String s = "";
    while ((s = stdInput.readLine()) != null) {
        json += s;//  ww  w  .java 2  s  .co  m
    }
    Gson gson = new Gson();
    Map<String, Object> subjectsData = gson.fromJson(json, new TypeToken<Map<String, Object>>() {
    }.getType());
    return subjectsData;
}

From source file:flpitu88.web.backend.psicoweb.config.Jwt.java

/**
 * Static method to generate a JSON Web Token
 *
 * @param payload JSON to attach//from  w  w w. j  av a 2s  . c  om
 * @param key Key used for the signature
 *
 * @return token
 *
 * @throws IllegalArgumentException
 * @throws NoSuchAlgorithmException
 * @throws UnsupportedEncodingException
 * @throws InvalidKeyException
 */
public static String encode(HashMap<String, Object> payload, String key) throws IllegalArgumentException,
        NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
    // Check key
    if (key == null || key.length() == 0) {
        throw new IllegalArgumentException("Key cannot be null or empty");
    }

    Algorithm algorithm = Algorithm.HS256;

    // Header, typ is fixed value
    HashMap<String, String> header = new HashMap<String, String>();
    header.put("typ", "JWT");
    header.put("alg", algorithm.name());

    // Create segments, all segment should be base64 String
    ArrayList<String> segments = new ArrayList<String>();
    Gson gson = new Gson();
    segments.add(base64Encode(gson.toJson(header).getBytes()));
    segments.add(base64Encode(gson.toJson(payload).getBytes()));
    segments.add(base64Encode(sign(StringUtils.join(segments, "."), key, algorithm.getValue())));

    return StringUtils.join(segments, ".");
}

From source file:net.bioclipse.dbxp.business.DbxpManager.java

public static Map<String, Object> getAssaysForStudy(String studyToken)
        throws NoSuchAlgorithmException, IOException {
    HashMap<String, String> formvars = new HashMap<String, String>();
    formvars.put("deviceID", getDeviceId());
    formvars.put("validation", getValidation());
    formvars.put("studyToken", studyToken);
    HttpResponse response = postValues(formvars, baseApiUrl + "getAssaysForStudy");
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String json = "";
    String s = "";
    while ((s = stdInput.readLine()) != null) {
        json += s;//  w w w .j  a va  2s . c  o  m
    }
    System.out.println(json);
    Gson gson = new Gson();
    Map<String, Object> subjectsData = gson.fromJson(json, new TypeToken<Map<String, Object>>() {
    }.getType());
    return subjectsData;
}

From source file:com.core.ServerConnector.java

public static QTResponse getQtResponse(String txRef) {
    QTResponse qtResponse = new QTResponse();
    String resCode = null, amount = null, resDesc = null, pmtRef = null, tdate = null, message = null;
    JSONObject jo = null;/* www.j a v  a  2  s.  com*/
    boolean gotres = false;

    try {
        String secretKey = Log.SECRETKEY;
        String endpoint = "https://paywith.quickteller.com/api/v2/transaction.json";
        HashMap params = new HashMap<String, String>();
        HashMap headers = new HashMap<String, String>();
        params.put("transRef", URLEncoder.encode(txRef));
        headers.put("clientid", Log.clientId);
        headers.put("Hash", Util.hash(txRef + secretKey));

        String response = GET(endpoint, params, headers);
        System.out.println("Raw Respone:" + response);

        jo = new JSONObject(response);
        resCode = jo.getString("ResponseCode");
        amount = jo.getString("Amount");
        resDesc = jo.getString("ResponseDescription");
        pmtRef = jo.getString("PaymentReference");
        tdate = jo.getString("TransactionDate");
        gotres = true;

    } catch (JSONException ex) {
        Logger.getLogger(TestService.class.getName()).log(Level.FINE, null, ex);
        try {
            message = jo.getString("Message");
        } catch (JSONException ex1) {
            Logger.getLogger(TestService.class.getName()).log(Level.SEVERE, null, ex1);
        }
    } catch (Exception ex) {
        Logger.getLogger(TestService.class.getName()).log(Level.SEVERE, null, ex);
    }

    if (gotres) {
        System.out.println("*********Successful Response**********");
        System.out.println("ResponseCode:" + resCode);
        System.out.println("Amount:" + amount);
        System.out.println("ResDesc:" + resDesc);
        System.out.println("pmtRef:" + pmtRef);
        System.out.println("tdate:" + tdate);

        qtResponse.setAmount(amount);
        qtResponse.setResponseCode(resCode);
        qtResponse.setDescription(resDesc);
        qtResponse.setHonour(true);
        if (resCode.equals("00")) {
            qtResponse.setSuccess(true);
        }
    } else {
        System.out.println("*********Failed**********");
        System.out.println("Message:" + message);
        qtResponse.setSuccess(false);
        qtResponse.setDescription(message);
    }

    return qtResponse;
}

From source file:com.github.koraktor.steamcondenser.community.AppNews.java

/**
 * Loads the news for the given game with the given restrictions
 *
 * @param appId The unique Steam Application ID of the game (e.g.
 *        <code>440</code> for Team Fortress 2). See
 *        http://developer.valvesoftware.com/wiki/Steam_Application_IDs for
 *        all application IDs//from w  w w .  j  av  a  2s .  c o  m
 * @param count The maximum number of news to load (default: 5). There's no
 *        reliable way to load all news. Use really a really great number
 *        instead
 * @param maxLength The maximum content length of the news (default: nil).
 *        If a maximum length is defined, the content of the news will only
 *        be at most <code>maxLength</code> characters long plus an
 *        ellipsis
 * @return A list of news for the specified game with the given options
 * @throws WebApiException if a request to Steam's Web API fails
 */
public static List<AppNews> getNewsForApp(int appId, int count, Integer maxLength) throws WebApiException {
    try {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("appid", appId);
        params.put("count", count);
        params.put("maxlength", maxLength);
        JSONObject data = new JSONObject(WebApi.getJSON("ISteamNews", "GetNewsForApp", 2, params));

        List<AppNews> newsItems = new ArrayList<AppNews>();
        JSONArray newsData = data.getJSONObject("appnews").getJSONArray("newsitems");
        for (int i = 0; i < newsData.length(); i++) {
            newsItems.add(new AppNews(appId, newsData.getJSONObject(i)));
        }

        return newsItems;
    } catch (JSONException e) {
        throw new WebApiException("Could not parse JSON data.", e);
    }
}

From source file:com.dtolabs.rundeck.core.common.NodeEntryFactory.java

public static Map<String, String> toMap(final INodeEntry node) {
    HashMap<String, String> map = new HashMap<String, String>();
    if (null != node.getAttributes()) {
        map.putAll(node.getAttributes());
    }//from w  ww.j a va2  s.c  o m

    if (null == map.get("tags")) {
        map.put("tags", "");
    }
    return map;
}

From source file:flpitu88.web.backend.psicoweb.config.Jwt.java

/**
 * Static method to generate a JSON Web Token
 *
 * @param payload JSON to attach//  w w w  .  j  a  va 2s  . c o m
 * @param key Key used for the signature
 * @param algorithm Encryption algorithm to apply
 *
 * @return token
 *
 * @throws IllegalArgumentException
 * @throws NoSuchAlgorithmException
 * @throws UnsupportedEncodingException
 * @throws InvalidKeyException
 */
public static String encode(HashMap<String, Object> payload, String key, Algorithm algorithm)
        throws IllegalArgumentException, NoSuchAlgorithmException, UnsupportedEncodingException,
        InvalidKeyException {
    // Check key
    if (key == null || key.length() == 0) {
        throw new IllegalArgumentException("Key cannot be null or empty");
    }

    if (algorithm == null) {
        algorithm = algorithm.HS256;
    }

    // Header, typ is fixed value
    HashMap<String, String> header = new HashMap<String, String>();
    header.put("typ", "JWT");
    header.put("alg", algorithm.name());

    // Create segments, all segment should be base64 String
    ArrayList<String> segments = new ArrayList<String>();

    Gson gson = new Gson();
    segments.add(base64Encode(gson.toJson(header).getBytes()));
    segments.add(base64Encode(gson.toJson(payload).getBytes()));
    segments.add(base64Encode(sign(StringUtils.join(segments, "."), key, algorithm.getValue())));

    return StringUtils.join(segments, ".");
}

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 ww  w .ja v a2s .  co m
    }

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

    return map;
}