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:Main.java

public static HashMap<String, String> copyMap(Map<String, Object> map) {
    HashMap<String, String> result = new HashMap<String, String>();

    for (Map.Entry<String, Object> entry : map.entrySet()) {
        String value = null;/* w  ww  .  j  av a2s .  c om*/

        if (entry.getValue() != null) {
            value = entry.getValue().toString();
        }

        result.put(entry.getKey(), value);
    }

    return result;
}

From source file:fshp.FSHP.java

/**
 * Returns the hash of <tt>passwd</tt> 
 *
 * @param passwd Byte representation of clear text password.
 * @param salt Byte representation of salt to be used in hashing.
 * @param saltlen Length of the salt. Should be 0 if a salt is already
 *        provided. If salt is null, saltlen bytes of salt will be
 *        auto generated./*from   w  ww. j  av a 2 s.  c  o m*/
 * @param rounds Number of hashing rounds.
 * @param variant FSHP variant indicating the behaviour and/or
 * <ul>
 *        <li><tt>0: SHA-1</tt> <em>(not recommended)</em></li>
 *        <li><tt>1: SHA-256</tt></li>
 *        <li><tt>2: SHA-384</tt></li>
 *        <li><tt>3: SHA-512</tt></li>
 * </ul>
 *
 * @return       FSHP hash of <tt>passwd</tt>
 */
public static String crypt(byte[] passwd, byte[] salt, int saltlen, int rounds, int variant) throws Exception {
    // Ensure we have sane values for salt length and rounds.
    if (saltlen < 0)
        saltlen = 0;
    if (rounds < 1)
        rounds = 1;

    if (salt == null) {
        salt = new byte[saltlen];
        new SecureRandom().nextBytes(salt);
    } else
        saltlen = salt.length;

    HashMap<Integer, String> algoMap = new HashMap<Integer, String>();
    algoMap.put(0, "SHA-1");
    algoMap.put(1, "SHA-256");
    algoMap.put(2, "SHA-384");
    algoMap.put(3, "SHA-512");

    MessageDigest md;
    try {
        if (!algoMap.containsKey(variant))
            throw new NoSuchAlgorithmException();

        md = MessageDigest.getInstance(algoMap.get(variant));
    } catch (NoSuchAlgorithmException e) {
        throw new Exception("Unsupported FSHP variant " + variant);
    }

    md.update(salt);
    md.update(passwd);
    byte[] digest = md.digest();

    for (int i = 1; i < rounds; i++) {
        md.reset();
        md.update(digest);
        digest = md.digest();
    }

    String meta = "{FSHP" + variant + "|" + saltlen + "|" + rounds + "}";

    byte[] saltdigest = new byte[salt.length + digest.length];
    System.arraycopy(salt, 0, saltdigest, 0, salt.length);
    System.arraycopy(digest, 0, saltdigest, salt.length, digest.length);

    byte[] b64saltdigest = Base64.encodeBase64(saltdigest);

    return meta + new String(b64saltdigest, "US-ASCII");
}

From source file:com.aokyu.dev.pocket.util.JSONUtils.java

public static HashMap<String, String> toHashMap(JSONObject jsonObj) throws JSONException {
    HashMap<String, String> map = new HashMap<String, String>();
    String[] names = getKeys(jsonObj);
    int size = names.length;
    for (int i = 0; i < size; i++) {
        String key = names[i];/*from w  w w. j  a  va 2  s  . c om*/
        String value = jsonObj.getString(key);
        map.put(key, value);
    }
    return map;
}

From source file:com.hangum.tadpole.engine.query.sql.DBSystemSchema.java

/**
 * Return trigger information/*from   w  w  w .ja  v  a 2 s .  c  o  m*/
 * 
 * @param strObjectName 
 */
public static List<TriggerDAO> getTrigger(final UserDBDAO userDB, String strObjectName)
        throws TadpoleSQLManagerException, SQLException {
    if (userDB.getDBDefine() == DBDefine.TAJO_DEFAULT || userDB.getDBDefine() == DBDefine.HIVE_DEFAULT
            || userDB.getDBDefine() == DBDefine.HIVE2_DEFAULT)
        return new ArrayList<TriggerDAO>();

    SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB);

    HashMap<String, String> paramMap = new HashMap<String, String>();
    paramMap.put("table_schema", userDB.getDb()); //$NON-NLS-1$
    paramMap.put("table_name", strObjectName); //$NON-NLS-1$

    return sqlClient.queryForList("triggerList", paramMap); //$NON-NLS-1$
}

From source file:com.opengamma.analytics.util.surface.StringValue.java

/**
 * Create a new object containing the point of the initial object and the new point. If the point is not in the existing points of the object, it is put in the map.
 * If a point is already in the existing point of the object, the value is added to the existing value.
 * @param stringValue The surface value.
 * @param point The surface point./* www.  j a va  2  s. com*/
 * @param value The associated value.
 * @return The combined/sum surface value.
 */
public static StringValue plus(final StringValue stringValue, final String point, final Double value) {
    Validate.notNull(stringValue, "Surface value");
    Validate.notNull(point, "Point");
    final HashMap<String, Double> plus = new HashMap<String, Double>(stringValue._data);
    if (stringValue._data.containsKey(point)) {
        plus.put(point, value + stringValue._data.get(point));
    } else {
        plus.put(point, value);
    }
    return new StringValue(plus);
}

From source file:Main.java

public static HashMap<String, String> jsonObject2HashMap(JSONObject jsonObject) {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    Iterator<String> iterator = jsonObject.keys();

    try {//from   www  . j  ava2  s . c om
        while (iterator.hasNext()) {
            String key = iterator.next();
            String value = jsonObject.getString(key);
            hashMap.put(key, value);

        }
    } catch (Exception e) {
        Log.w("apputil", "jsonobject2hasmap");
    }
    return hashMap;
}

From source file:joshua.ui.alignment_visualizer.WordAlignmentLayout.java

private static Transformer<Word, Point2D> calculateInitializer(Graph<Word, Integer> g, double height,
        double spacing) {
    HashMap<Word, Point2D> map = new HashMap<Word, Point2D>();
    for (Word w : g.getVertices()) {
        double x, y;
        if (w.isSource())
            y = 0.0;/*from   w w  w.j a  v  a 2 s  .  c  o m*/
        else
            y = height;
        x = spacing * w.position();
        map.put(w, new Point2D.Double(x, y));
    }
    return TransformerUtils.mapTransformer(map);
}

From source file:Main.java

public static HashMap<String, Object> getDateFromLJString(String dateString) {
    final HashMap<String, Object> result = new HashMap<String, Object>();

    if (dateString == null || dateString.length() == 0) {
        return result;
    }//ww w. j a v  a  2 s.  c  o  m

    final String[] dateTime = dateString.split(" ");
    final String[] dateItems = dateTime[0].split("-");
    result.put(YEAR, dateItems[0]);
    result.put(MONTH, dateItems[1]);
    result.put(DAY, dateItems[2]);

    final String[] timeItems = dateTime[1].split(":");
    result.put(HOUR, timeItems[0]);
    result.put(MIN, timeItems[1]);

    return result;
}

From source file:ru.apertum.qsystem.reports.net.NetUtil.java

public static synchronized HashMap<String, String> getCookie(String data, String delimiter) {
    final HashMap<String, String> res = new HashMap<>();
    final String[] ss = data.split(delimiter);
    for (String s : ss) {
        final String[] ss0 = s.split("=");
        try {/* w ww .  j  ava  2 s.  c o m*/
            res.put(URLDecoder.decode(ss0[0], "utf-8"),
                    URLDecoder.decode(ss0.length == 1 ? "" : ss0[1], "utf-8"));
        } catch (UnsupportedEncodingException ex) {
            QLog.l().logRep().error(ss0[1], ex);
        }
    }
    return res;
}

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

public static Map<String, Object> getStudies() throws IOException, NoSuchAlgorithmException {
    HashMap<String, String> formvars = new HashMap<String, String>();
    formvars.put("deviceID", getDeviceId());
    formvars.put("validation", getValidation());
    HttpResponse response = postValues(formvars, baseApiUrl + "getStudies");
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String json = "";
    String s = "";
    while ((s = stdInput.readLine()) != null) {
        json += s;/*from   w w w .j a v  a2 s . c  o m*/
    }

    Gson gson = new Gson();
    Map<String, Object> subjectsData = gson.fromJson(json, new TypeToken<Map<String, Object>>() {
    }.getType());
    return subjectsData;
}