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

public static void save(HashMap<String, String> map) {
    SharedPreferences preferences = getPrivateSharedPreference();
    SharedPreferences.Editor editor = preferences.edit();
    for (String key : map.keySet()) {
        editor.putString(key, map.get(key));
    }/*from ww w .  ja v  a 2 s . c  om*/
    editor.commit();
}

From source file:it.acubelab.smaph.entityfilters.LibSvmEntityFilter.java

/**
 * Turns a frature_name-feature_value mapping to an array of features.
 * /* www .java  2  s.c  o m*/
 * @param features
 *            the mapping from feature names to feature values.
 * @return an array of feature values.
 */
public static double[] featuresToFtrVectStatic(HashMap<String, Double> features) {

    if (!checkFeatures(features)) {
        for (String ftrName : features.keySet())
            System.err.printf("%s -> %f%n", ftrName, features.get(ftrName));
        throw new RuntimeException("Implementation error -- check the features");
    }

    Vector<Double> ftrValues = new Vector<>();
    for (String ftrName : ftrNames)
        ftrValues.add(getOrDefault(features, ftrName, 0.0));

    return ArrayUtils.toPrimitive(ftrValues.toArray(new Double[] {}));
}

From source file:eu.scape_project.hawarp.utils.StringUtils.java

public static String normaliseMimetype(String mime) {
    String normalised = getStrUntilChar(mime, ";");
    HashMap<String, String> replMap = new HashMap<String, String>();
    replMap.put("no-type", "application/octet-stream");
    for (String key : replMap.keySet()) {
        if (normalised.contains(key)) {
            normalised = normalised.replace(key, replMap.get(key));
        }//from w w w  .  j  a v a 2  s . c om
    }
    return normalised.toLowerCase();
}

From source file:cooccurrence.emf.java

/**
 * Method to populate the apache matrix from cooccur hashmap
 *
 * @param matrixR//from  ww w . jav  a  2 s . c  o  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:com.morphoss.jumble.models.ModelParser.java

public static Collection<Category> readJsonData(String json) throws IOException, JSONException {

    JSONObject file = new JSONObject(json);
    JSONObject cats = file.getJSONObject("categories");
    JSONObject Words = file.getJSONObject("words");
    HashMap<Integer, Category> catMap = Category.getCategoriesFromJson(cats);

    HashMap<String, Word> words = Word.getWordFromJson(Words, catMap);

    HashMap<String, ArrayList<Localisation>> localisations = Localisation
            .getLocalisationFromJson(file.getJSONObject("localisations"));

    for (String cc : localisations.keySet()) {
        ArrayList<Localisation> locs = localisations.get(cc);
        for (Localisation loc : locs) {
            Word word = words.get(loc.getNameKey());
            if (word != null) {
                word.addLocalisation(cc, loc);
            } else {
                Log.e(TAG, "Unable to find original word with name key: " + loc.getNameKey());
            }//from   www. j a va 2 s. com
        }
    }

    return catMap.values();
}

From source file:com.glluch.ecf2xmlmaven.Writer.java

protected static String terms2xml(String field_name, HashMap<String, Integer> terms) {
    String text = "";
    Set pterms = terms.keySet();
    for (Object t : pterms) {
        text += "<field name=\"" + field_name + "\" " + " boost=\"" + terms.get(t) + "\"" + ">" + t + "</field>"
                + System.lineSeparator();
    }//  w w w . jav a 2s  .c o m
    return text;
}

From source file:nl.coralic.beta.sms.utils.http.HttpHandler.java

private static List<NameValuePair> createPostData(HashMap<String, String> arguments) throws Exception {
    List<NameValuePair> postdata = new ArrayList<NameValuePair>();
    if (arguments != null) {
        for (String key : arguments.keySet()) {
            postdata.add(new BasicNameValuePair(key, arguments.get(key)));
        }/*from w w  w.  j av a  2 s . com*/
        return postdata;
    }
    throw new Exception("No arguments");
}

From source file:Main.java

public static String addAttributes(HashMap<String, String> p_attributes) {
    StringBuffer l_buf = null;/*from  w  ww  .  j  av  a 2  s. c  o  m*/
    Iterator<String> l_iter = null;
    String l_name = null;

    if (p_attributes != null) {
        l_buf = new StringBuffer();
        l_iter = p_attributes.keySet().iterator();
        while (l_iter.hasNext()) {
            l_name = l_iter.next();
            l_buf.append(" ").append(l_name).append("=\"");
            l_buf.append(p_attributes.get(l_name)).append("\"");
        }

        return l_buf.toString();
    }

    return "";
}

From source file:com.austin.base.commons.util.StringUtil.java

/**
 * @param map ?HashMap//from   ww  w  .ja v a  2s  .com
 * @return ??
 */
public static String makeParamter(HashMap map) {
    StringBuilder sb = new StringBuilder();
    String result = null;
    java.util.Iterator iterator = map.keySet().iterator();
    String key = null;
    Object obj = null;
    boolean flag = iterator.hasNext();
    while (iterator.hasNext()) {
        key = iterator.next().toString();
        log.info("?Mapkey" + key);
        obj = map.get(key);
        log.info("?MapValue" + obj);
        if (obj == null) {
            obj = "";
        }
        sb.append(key);
        sb.append("=");
        sb.append(obj.toString());
        sb.append("&");
    }
    result = sb.toString();
    if (flag) {
        result = result.substring(0, result.length() - 1);
    }
    log.info("HashMap??" + result);
    return result;
}

From source file:com.proctorcam.proctorserv.HashedAuthenticator.java

protected static String hashQuery(String key, HashMap<String, Object> valueHash) {
    StringBuilder query = new StringBuilder();
    for (String k : valueHash.keySet()) {
        String v = String.valueOf(valueHash.get(k));
        query.append(String.format("%s[%s]=%s&", key, k, v));
    }//  ww  w.jav  a 2  s  .co m
    return query.toString();
}