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:com.proctorcam.proctorserv.RestRequestClient.java

/**
 *  Creates a URL using url (String) and appending to it the key-value pairs
 *  found in params (HashMap). The resulting String is used to make GET requests
 *  in makeGetRequest, /*from   w w  w  .j ava  2  s .  c  om*/
 */

protected String buildURL(String url, HashMap<String, Object> params) {
    StringBuilder query = new StringBuilder(url).append("?");
    for (String key : params.keySet()) {
        String data = String.valueOf(params.get(key));
        query.append(key).append("=").append(data).append("&");
    }

    query.deleteCharAt(query.length() - 1);
    String queryURL = query.toString();

    return queryURL;
}

From source file:com.walmartlabs.mupd8.application.ConfigTest.java

@SuppressWarnings("unchecked")
public void testConfigDirLoad() throws Exception {
    String dir = this.getClass().getClassLoader().getResource("testapp").getPath();
    Config config = new Config(new File(dir));
    String[] paths = { "mupd8", "application", "TestApp", "performers", "K1Updater", "class" };
    String k1Updater = (String) config.getScopedValue(paths);
    assertEquals("check performer class value", "com.walmartlabs.mupd8.examples.KnUpdaterJson", k1Updater);
    String[] cassPath = { "mupd8", "slate_store", "keyspace" };
    assertEquals("check slate_store", "Mupd8", (String) config.getScopedValue(cassPath));

    JSONObject performerConfig = config.workerJSONs.get("K1Updater");
    assertEquals("workerJSONs defined in directory configuration", k1Updater,
            (String) performerConfig.get("class"));

    String sys = this.getClass().getClassLoader().getResource("testapp/sys_old").getPath();
    String app = this.getClass().getClassLoader().getResource("testapp/app_old").getPath();

    Config newConfig = new Config(sys, app);
    String[] clPath = { "mupd8", "application" };
    java.util.HashMap<String, Object> testApp = (java.util.HashMap<String, Object>) newConfig
            .getScopedValue(clPath);/*from www .j  a  v a 2  s  .  c o m*/
    String firstKey = (String) testApp.keySet().toArray()[0];
    assertEquals("contains TestApp", "TestApp", firstKey);

    performerConfig = newConfig.workerJSONs.get("K1Updater");
    assertEquals("workerJSONs defined in sys/app configuration", "com.walmartlabs.mupd8.examples.KnUpdater",
            (String) performerConfig.get("class"));
}

From source file:net.sf.eclipsecs.core.transformer.CheckstyleFileWriter.java

/**
 * Method for writing a propterty to file.
 * /*from   w w  w  . j av  a2 s.  com*/
 * @param properties
 *            A HashMap containing all properties.
 */
private void writeProperty(final HashMap<String, String> properties, final OutputStream bw) throws IOException {
    final Iterator<String> propit = properties.keySet().iterator();
    String prop;

    while (propit.hasNext()) {
        prop = propit.next();
        bw.write(("<property name=\"" + prop + "\" value=\"" + properties.get(prop) + "\"/>\n")
                .getBytes("UTF-8"));
    }
}

From source file:eionet.rpcserver.servlets.XmlRpcRouter.java

/**
 * gets the service defs from the roster.
 */// w  w  w.  j av  a  2s.  c  o  m
public void init(ServletConfig config) throws ServletException {

    super.init(config);
    xmlrpc = new XmlRpcServer();

    try {
        HashMap services = UITServiceRoster.getServices();

        Iterator iter = services.keySet().iterator();
        while (iter.hasNext()) {
            String srvName = (String) iter.next();

            xmlrpc.addHandler(srvName, new XmlRpcServiceHandler(srvName));
            //Logger.log("** srv = " + srvName);
        }

    } catch (ServiceException se) {
        throw new ServletException(se);
    } catch (Exception e) {
        throw new ServletException(e);
    }

}

From source file:com.github.ignition.support.http.IgnitedHttpPost.java

public IgnitedHttpPost(IgnitedHttpClient ignitedHttp, String url, HashMap<String, String> defaultHeaders) {
    super(ignitedHttp);
    this.request = new org.apache.http.client.methods.HttpPost(url);

    for (String header : defaultHeaders.keySet()) {
        request.setHeader(header, defaultHeaders.get(header));
    }//from   w  w  w  .  j av a2 s.  c o m
}

From source file:net.exclaimindustries.geohashdroid.wiki.WikiUtils.java

/** Replaces an entire wiki page
   @param  httpclient an active HTTP session 
   @param  pagename   the name of the wiki page
   @param  content    the new content of the wiki page to be submitted
   @param  formfields a hashmap with the fields needed (besides pagename and content; those will be filled in this method)
   @throws WikiException problem with the wiki, translate the ID
   @throws Exception     anything else happened, use getMessage
*///w  w w  .  jav a 2s  .  co  m
public static void putWikiPage(HttpClient httpclient, String pagename, String content,
        HashMap<String, String> formfields) throws Exception {
    // If there's no edit token in the hash map, we can't do anything.
    if (!formfields.containsKey("token")) {
        throw new WikiException(R.string.wiki_error_protected);
    }

    HttpPost httppost = new HttpPost(WIKI_API_URL);

    ArrayList<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("action", "edit"));
    nvps.add(new BasicNameValuePair("title", pagename));
    nvps.add(new BasicNameValuePair("text", content));
    nvps.add(new BasicNameValuePair("format", "xml"));
    for (String s : formfields.keySet()) {
        nvps.add(new BasicNameValuePair(s, formfields.get(s)));
    }

    httppost.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));

    Document response = getHttpDocument(httpclient, httppost);

    Element root = response.getDocumentElement();

    // First, check for errors.
    if (doesResponseHaveError(root)) {
        throw new WikiException(getErrorTextId(findErrorCode(root)));
    }

    // And really, that's it.  We're done!
}

From source file:bigdataproject.ReadDataSet.java

List<DoublePoint> getCollection(HashMap<Integer, double[]> map) {
    List<DoublePoint> list = new ArrayList<>();
    map.keySet().stream().map((key) -> new DoublePoint(map.get(key))).forEach((p) -> {
        list.add(p);//from  ww  w  .j a v a  2  s. c o  m
    });
    return list;
}

From source file:android.databinding.tool.store.SetterStore.java

private static <K, V> void merge(HashMap<K, HashMap<V, MethodDescription>> first,
        HashMap<K, HashMap<V, MethodDescription>> second) {
    for (K key : second.keySet()) {
        HashMap<V, MethodDescription> firstVals = first.get(key);
        HashMap<V, MethodDescription> secondVals = second.get(key);
        if (firstVals == null) {
            first.put(key, secondVals);//from w  w  w . j  a  va 2s  .  co m
        } else {
            for (V key2 : secondVals.keySet()) {
                if (!firstVals.containsKey(key2)) {
                    firstVals.put(key2, secondVals.get(key2));
                }
            }
        }
    }
}

From source file:Gen.java

static void jar(String src_arg, String jar_arg, HashMap<String, String> manifestAttributes) {

    Jar jarTask = new Jar();
    jarTask.setProject(_project);//from w ww  .  j  a va 2  s  . co m
    jarTask.setTaskName("jar");

    jarTask.setBasedir(new File(src_arg));
    jarTask.setDestFile(new File(jar_arg));

    if (manifestAttributes != null) {
        try {

            Manifest manifest = new Manifest();

            for (Iterator<String> iter = manifestAttributes.keySet().iterator(); iter.hasNext();) {
                String item = iter.next();
                Attribute attribute = new Attribute(item, manifestAttributes.get(item));
                manifest.addConfiguredAttribute(attribute);
            }

            jarTask.addConfiguredManifest(manifest);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    jarTask.setIncludes("**/*.java,**/*.class, **/*.R, **/*.xml, **/*.properties, **/*.wsdl");
    jarTask.setExcludes("org/bioconductor/rserviceJms/**/*");

    jarTask.init();
    jarTask.execute();
}

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

@Override
public boolean filterEntity(HashMap<String, Double> features) {
    boolean result = predict(features);
    String ftrDesc = "";
    for (String key : features.keySet())
        ftrDesc += String.format("%s:%.3f ", key, features.get(key));
    SmaphAnnotatorDebugger.out.printf("EF: %s has been %s.%n", ftrDesc, result ? "accepted" : "discarded");
    return result;
}