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:org.wikimedia.analytics.kraken.schemas.JsonToClassConverterTest.java

@Test
public void readAppleUserAgentJsonFile() throws JsonMappingException, JsonParseException, RuntimeException {
    JsonToClassConverter converter = new JsonToClassConverter();
    HashMap<String, Schema> map = converter.construct("org.wikimedia.analytics.kraken.schemas.AppleUserAgent",
            "ios.json", "getProduct");
    assertEquals(map.keySet().size(), 89);

}

From source file:org.wikimedia.analytics.kraken.schemas.JsonToClassConverterTest.java

@Test
public void readMccMncJsonFile() throws JsonMappingException, JsonParseException, RuntimeException {
    JsonToClassConverter converter = new JsonToClassConverter();
    HashMap<String, Schema> map = converter.construct("org.wikimedia.analytics.kraken.schemas.MccMnc",
            "mcc_mnc.json", "getCountryCode");
    assertEquals(map.keySet().size(), 211);

}

From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.ManagePublicationsForIndividualController.java

private List<String> getAllSubclasses(HashMap<String, List<Map<String, String>>> publications) {
    List<String> allSubclasses = new ArrayList<String>(publications.keySet());
    Collections.sort(allSubclasses);
    return allSubclasses;
}

From source file:eu.scape_project.archiventory.identifiers.UnixFileIdentificationTest.java

/**
 * Test of identifyFileList method, of class UnixFileIdentification.
 *//*from  w ww  . j av a 2s  . c  om*/
@Test
public void testIdentifyFileList() throws Exception {
    UnixFileIdentification id = new UnixFileIdentification();
    id.setTool("unixfile");
    id.setOutputKeyFormat("%1$s/%2$s");
    id.setOutputValueFormat("%1$s %2$s %3$s");
    id.setCommand("file --mime-type");
    HashMap<String, List<String>> result = id.identifyFileList(arcFilesMap);
    assertEquals(5, result.size());
    for (String res : result.keySet()) {
        List<String> valueList = result.get(res);
        for (String val : valueList) {
            System.out.println(val);
        }
    }
    String tmpTestFilePath = ArcFilesTestMap.getInstance().getTmpTestFile().getAbsolutePath();
    List<String> vals = result.get(tmpTestFilePath + "/20130522085321/http://fue.onb.ac.at/test/image.png");
    assertEquals(vals.get(0), "unixfile mime image/png");
}

From source file:br.com.bropenmaps.util.Util.java

/**
 * Valida um formulrio. Dois parmetros so passados. O primeiro  um estrutura que representa os campos do formulrio, esta estrutura  formada por
 * uma coleo de pares nome do campo/valor do campo. O segundo parmtetro  tambm uma coleo formada por pares nome do campo/tipo de validao.
 * @param params - parmetros do formulrio a serem validados
 * @param tipo - tipo de validao para cada parmetro
 * @return Estrutura contendo os erros encontrados, que uma coleo de pares nome do campo/erro encontrado.
 *///from w ww. ja  v  a2 s . c om
public static HashMap<String, String> validaForm(final HashMap<String, String> params,
        final HashMap<String, Integer[]> tipo) {

    Set<String> chaves = params.keySet();

    HashMap<String, String> erros = new HashMap<String, String>();

    Integer[] ts = null;

    String tk[] = null;

    for (String s : chaves) {

        ts = tipo.get(s);

        for (Integer t : ts) {

            if (t.equals(OBRIGATORIO)) {

                if (params.get(s) == null || params.get(s).equals("")) {

                    erros.put(s, "Campo obrigatrio.");

                }

            }

            else if (t.equals(EMAIL)) {

                if (params.get(s) != null) {

                    tk = StringUtils.split(params.get(s), ",");

                    for (int i = 0; i < tk.length; i++) {

                        if (!validaEmail(StringUtils.trim(tk[i]))) {

                            erros.put(s, "Informe email(s) vlido(s).");

                            break;

                        }

                    }

                }

            }

        }

    }

    return erros;

}

From source file:com.grarak.kerneladiutor.database.tools.customcontrols.Controls.java

public void putItem(HashMap<String, Object> items) {
    JSONObject object = new JSONObject();
    for (String key : items.keySet()) {
        try {//from   www.jav  a  2s  . c  om
            object.put(key, items.get(key));
        } catch (JSONException ignored) {
        }
    }
    putItem(object);
}

From source file:io.crate.module.sql.benchmark.BulkDeleteBenchmark.java

@BenchmarkOptions(benchmarkRounds = BENCHMARK_ROUNDS, warmupRounds = 1)
@Test/*from www . j a va 2  s  .com*/
public void testSQLSingleDelete() {
    HashMap<String, String> ids = createSampleData();
    for (String id : ids.keySet()) {
        getClient(false).execute(SQLAction.INSTANCE, new SQLRequest(DELETE_SQL_STMT, new Object[] { id }))
                .actionGet();
    }
}

From source file:eu.scape_project.archiventory.identifiers.DroidIdentificationTest.java

/**
 * Test of identify method, of class DroidIdentification.
 *//*  w w w  .j  av a 2 s  .c  o  m*/
@Test
public void testIdentify() throws Exception {
    id.setTool("droid");
    id.setOutputKeyFormat("%1$s/%2$s");
    id.setOutputValueFormat("%1$s %2$s %3$s");
    HashMap<String, List<String>> result = id.identifyFileList(arcFilesMap);
    assertEquals(5, result.size());
    for (String res : result.keySet()) {
        List<String> valueList = result.get(res);
        for (String val : valueList) {
            System.out.println(val);
        }
    }
    String tmpTestFilePath = ArcFilesTestMap.getInstance().getTmpTestFile().getAbsolutePath();
    List<String> vals = result.get(tmpTestFilePath + "/20130522085321/http://fue.onb.ac.at/test/image.png");
    assertEquals(vals.get(0), "droid mime image/png");
    assertEquals(vals.get(1), "droid puid fmt/11");
}

From source file:com.tealeaf.Downloader.java

public boolean moveAll(HashMap<String, File> files) {
    String[] uris = new String[files.size()];
    files.keySet().toArray(uris);
    for (int i = 0; i < uris.length; i++) {
        cache(uris[i], files.get(uris[i]));
    }/*from  w  w w.j  a  v  a 2  s.c o m*/
    return true;
}

From source file:net.sf.taverna.t2.activities.biomoby.ExecuteAsyncCgiService.java

private static boolean pollAsyncCgiService(String msName, String url, EndpointReference epr, String[] queryIds,
        String[] result) throws MobyException {
    // Needed to remap results
    HashMap<String, Integer> queryMap = new HashMap<String, Integer>();
    for (int qi = 0; qi < queryIds.length; qi++) {
        String queryId = queryIds[qi];
        if (queryId != null)
            queryMap.put(queryId, new Integer(qi));
    }//from   w  ww  .  j a  va 2s .  c o m

    if (queryMap.size() == 0)
        return false;

    // construct the GetMultipleResourceProperties XML
    StringBuffer xml = new StringBuffer();
    xml.append("<wsrf-rp:GetMultipleResourceProperties xmlns:wsrf-rp='" + RESOURCE_PROPERTIES_NS
            + "' xmlns:mobyws='http://biomoby.org/'>");
    for (String q : queryMap.keySet())
        xml.append("<wsrf-rp:ResourceProperty>mobyws:" + STATUS_PREFIX + q + "</wsrf-rp:ResourceProperty>");
    xml.append("</wsrf-rp:GetMultipleResourceProperties>");

    StringBuffer httpheader = new StringBuffer();
    httpheader.append("<moby-wsrf>");
    httpheader.append("<wsa:Action xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">"
            + GET_MULTIPLE_RESOURCE_PROPERTIES_ACTION + "</wsa:Action>");
    httpheader.append(
            "<wsa:To xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsu:Id=\"To\">"
                    + url + "</wsa:To>");
    httpheader.append(
            "<mobyws:ServiceInvocationId xmlns:mobyws=\"http://biomoby.org/\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsa:IsReferenceParameter=\"true\">"
                    + epr.getServiceInvocationId() + "</mobyws:ServiceInvocationId>");
    httpheader.append("</moby-wsrf>");

    AnalysisEvent[] l_ae = null;
    // First, status from queries
    String response = "";
    // construct the Httpclient
    HttpClient client = new HttpClient();
    client.getParams().setParameter("http.useragent", "jMoby/Taverna2");
    // create the post method
    PostMethod method = new PostMethod(url + "/status");
    // add the moby-wsrf header (with no newlines)
    method.addRequestHeader("moby-wsrf", httpheader.toString().replaceAll("\r\n", ""));

    // put our data in the request
    RequestEntity entity;
    try {
        entity = new StringRequestEntity(xml.toString(), "text/xml", null);
    } catch (UnsupportedEncodingException e) {
        throw new MobyException("Problem posting data to webservice", e);
    }
    method.setRequestEntity(entity);

    // retry up to 10 times
    client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(10, true));

    // call the method
    try {
        if (client.executeMethod(method) != HttpStatus.SC_OK)
            throw new MobyException("Async HTTP POST service returned code: " + method.getStatusCode() + "\n"
                    + method.getStatusLine() + "\nduring our polling request");
        response = stream2String(method.getResponseBodyAsStream());
    } catch (IOException e) {
        throw new MobyException("Problem reading response from webservice", e);
    } finally {
        // Release current connection to the connection pool once you
        // are
        // done
        method.releaseConnection();
    }

    if (response != null) {
        l_ae = AnalysisEvent.createFromXML(response);
    }

    if (l_ae == null || l_ae.length == 0) {
        new MobyException("Troubles while checking asynchronous MOBY job status from service " + msName);
    }

    ArrayList<String> finishedQueries = new ArrayList<String>();
    // Second, gather those finished queries
    for (int iae = 0; iae < l_ae.length; iae++) {
        AnalysisEvent ae = l_ae[iae];
        if (ae.isCompleted()) {
            String queryId = ae.getQueryId();
            if (!queryMap.containsKey(queryId)) {
                throw new MobyException(
                        "Invalid result queryId on asynchronous MOBY job status fetched from " + msName);
            }
            finishedQueries.add(queryId);
        }
    }

    // Third, let's fetch the results from the finished queries
    if (finishedQueries.size() > 0) {
        String[] resQueryIds = finishedQueries.toArray(new String[0]);
        for (int x = 0; x < resQueryIds.length; x++) {
            // construct the GetMultipleResourceProperties XML
            xml = new StringBuffer();
            xml.append("<wsrf-rp:GetMultipleResourceProperties xmlns:wsrf-rp='" + RESOURCE_PROPERTIES_NS
                    + "' xmlns:mobyws='http://biomoby.org/'>");
            for (String q : resQueryIds)
                xml.append("<wsrf-rp:ResourceProperty>mobyws:" + RESULT_PREFIX + q
                        + "</wsrf-rp:ResourceProperty>");
            xml.append("</wsrf-rp:GetMultipleResourceProperties>");

            httpheader = new StringBuffer();
            httpheader.append("<moby-wsrf>");
            httpheader.append("<wsa:Action xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">"
                    + GET_MULTIPLE_RESOURCE_PROPERTIES_ACTION + "</wsa:Action>");
            httpheader.append(
                    "<wsa:To xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsu:Id=\"To\">"
                            + url + "</wsa:To>");
            httpheader.append(
                    "<mobyws:ServiceInvocationId xmlns:mobyws=\"http://biomoby.org/\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsa:IsReferenceParameter=\"true\">"
                            + epr.getServiceInvocationId() + "</mobyws:ServiceInvocationId>");
            httpheader.append("</moby-wsrf>");
            client = new HttpClient();
            client.getParams().setParameter("http.useragent", "jMoby/Taverna2");
            // create the post method
            method = new PostMethod(url + "/results");
            // add the moby-wsrf header (with no newlines)
            method.addRequestHeader("moby-wsrf", httpheader.toString().replaceAll("\r\n", ""));

            // put our data in the request
            entity = null;
            try {
                entity = new StringRequestEntity(xml.toString(), "text/xml", null);
            } catch (UnsupportedEncodingException e) {
                throw new MobyException("Problem posting data to webservice", e);
            }
            method.setRequestEntity(entity);

            // retry up to 10 times
            client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                    new DefaultHttpMethodRetryHandler(10, true));

            // call the method
            try {
                if (client.executeMethod(method) != HttpStatus.SC_OK)
                    throw new MobyException("Async HTTP POST service returned code: " + method.getStatusCode()
                            + "\n" + method.getStatusLine() + "\nduring our polling request");
                // place the result in the array
                result[x] = stream2String(method.getResponseBodyAsStream());
                // Marking as null
                queryIds[x] = null;
            } catch (IOException e) {
                logger.warn("Problem getting result from webservice\n" + e.getMessage());
            } finally {
                // Release current connection
                method.releaseConnection();
            }
        }

    }
    return finishedQueries.size() != queryMap.size();
}