Example usage for java.util HashMap entrySet

List of usage examples for java.util HashMap entrySet

Introduction

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

Prototype

Set entrySet

To view the source code for java.util HashMap entrySet.

Click Source Link

Document

Holds cached entrySet().

Usage

From source file:com.fujitsu.dc.test.jersey.DcRestAdapter.java

/**
 * GET/POST/PUT/DELETE ?.// ww  w  . jav a  2s.  com
 * @param method Http
 * @param url URL
 * @param body 
 * @param headers ??
 * @return DcResponse
 * @throws DcException DAO
 */
public DcResponse request(final String method, String url, String body, HashMap<String, String> headers)
        throws DcException {
    HttpEntityEnclosingRequestBase req = new HttpEntityEnclosingRequestBase() {
        @Override
        public String getMethod() {
            return method;
        }
    };
    req.setURI(URI.create(url));
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        req.setHeader(entry.getKey(), entry.getValue());
    }
    req.addHeader("X-Dc-Version", DcCoreTestConfig.getCoreVersion());

    if (body != null) {
        HttpEntity httpEntity = null;
        try {
            String bodyStr = toUniversalCharacterNames(body);
            httpEntity = new StringEntity(bodyStr);
        } catch (UnsupportedEncodingException e) {
            throw DcException.create("error while request body encoding : " + e.getMessage(), 0);
        }
        req.setEntity(httpEntity);
    }
    debugHttpRequest(req, body);
    return this.request(req);
}

From source file:io.personium.test.jersey.PersoniumRestAdapter.java

/**
 * GET/POST/PUT/DELETE ?./*from  ww  w .ja v  a  2s .c  o m*/
 * @param method Http
 * @param url URL
 * @param body 
 * @param headers ??
 * @return DcResponse
 * @throws PersoniumException DAO
 */
public PersoniumResponse request(final String method, String url, String body, HashMap<String, String> headers)
        throws PersoniumException {
    HttpEntityEnclosingRequestBase req = new HttpEntityEnclosingRequestBase() {
        @Override
        public String getMethod() {
            return method;
        }
    };
    req.setURI(URI.create(url));
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        req.setHeader(entry.getKey(), entry.getValue());
    }
    req.addHeader("X-Personium-Version", PersoniumCoreTestConfig.getCoreVersion());

    if (body != null) {
        HttpEntity httpEntity = null;
        try {
            String bodyStr = toUniversalCharacterNames(body);
            httpEntity = new StringEntity(bodyStr);
        } catch (UnsupportedEncodingException e) {
            throw PersoniumException.create("error while request body encoding : " + e.getMessage(), 0);
        }
        req.setEntity(httpEntity);
    }
    debugHttpRequest(req, body);
    return this.request(req);
}

From source file:net.bhl.cdt.connector.avl.strategies.AVLProcessGeneratorStrategy.java

private void writeRunCase(AVLProcessGenerator avlProcessGenerator, HashMap<String, BigDecimal> dimensionValues,
        List<String> sweppedDimensions, FileWriter fileWriter) throws IOException {
    if (avlProcessGenerator.getRuncaseCounter() > 1) {
        FileGeneratorHelper.writeLine("", fileWriter);
        FileGeneratorHelper.writeLine("", fileWriter);
    }//from w  w w.j  av a2 s .  com

    FileGeneratorHelper.writeLine("---------------------------------------------", fileWriter);
    FileGeneratorHelper.write("Run case  " + avlProcessGenerator.getRuncaseCounter() + ":", fileWriter);
    for (Map.Entry<String, BigDecimal> entry : dimensionValues.entrySet()) {
        if (sweppedDimensions.contains(entry.getKey())) {
            String string = "  " + entry.getKey() + " " + entry.getValue().toString();
            FileGeneratorHelper.write(string, fileWriter);
        }

    }
    FileGeneratorHelper.writeLine("", fileWriter);
    FileGeneratorHelper.writeLine("", fileWriter);
    for (VariableSweep varirableSweep : avlProcessGenerator.getVariableSweeps()) {
        String entryName = varirableSweep.getName();
        BigDecimal entryValue = dimensionValues.get(entryName);
        FileGeneratorHelper.writeLine(" " + StringUtils.rightPad(entryName, 13) + "->  "
                + StringUtils.rightPad(entryName, 13) + "=   " + entryValue, fileWriter);

    }
    avlProcessGenerator.setRuncaseCounter(avlProcessGenerator.getRuncaseCounter() + 1);
    File avlProcessFile = new File(avlProcessGenerator.getCommandFileName());
    int fileSeperatorIndex = avlProcessFile.getName().indexOf(".");
    String processFileName = "avl" + avlProcessFile.getName().subSequence(0, fileSeperatorIndex);
    if (avlProcessGenerator.getRuncaseCounter() > 1) {

        String fullResultFileName = processFileName
                + String.valueOf(avlProcessGenerator.getRuncaseCounter() - 1) + ".out";
        AVLResultImporter avlResultImporter = AvlprocessFactory.eINSTANCE.createAVLResultImporter();
        avlResultImporter.setFileName(fullResultFileName);
        avlResultImporter.setName(fullResultFileName);
        avlProcessGenerator.getAvlResultImporters().add(avlResultImporter);
    }
}

From source file:com.intuit.tank.http.BaseRequest.java

@SuppressWarnings("rawtypes")
protected void logRequest(String url, String body, String method, HashMap<String, String> headerInformation,
        HttpClient httpclient, boolean force) {
    try {/*  w w w  .j a  v a  2 s  .  c om*/
        StringBuilder sb = new StringBuilder();

        sb.append("REQUEST URL: " + method + " " + url).append(NEWLINE);
        // Header Information
        for (Map.Entry mapEntry : headerInformation.entrySet()) {
            sb.append("REQUEST HEADER: " + (String) mapEntry.getKey() + " = " + (String) mapEntry.getValue())
                    .append(NEWLINE);
        }
        // Cookies Information
        if (httpclient != null && httpclient.getState() != null && httpclient.getState().getCookies() != null) {
            for (Cookie cookie : httpclient.getState().getCookies()) {
                sb.append("REQUEST COOKIE: " + cookie.toExternalForm() + " (domain=" + cookie.getDomain()
                        + " : path=" + cookie.getPath() + ")").append(NEWLINE);
            }
        }
        if (null != body) {
            sb.append("REQUEST SIZE: " + body.getBytes().length).append(NEWLINE);
            sb.append("REQUEST BODY: " + body).append(NEWLINE);
        }
        this.logMsg = sb.toString();
        if (APITestHarness.getInstance().isDebug()) {
            System.out.println("******** REQUEST *********");
            System.out.println(this.logMsg);
        }
        logger.debug("******** REQUEST *********");
        logger.debug(this.logMsg);

    } catch (Exception ex) {
        logger.error("Unable to log request", ex);
    }
}

From source file:gemlite.shell.admin.dao.AdminDao.java

public List<HashMap<String, Object>> sizeM(String regionName) {
    List<HashMap<String, Object>> rs = new ArrayList<HashMap<String, Object>>();
    Map param = new HashMap();
    param.put("moduleName", "Runtime");
    param.put("beanName", "SizemService");
    Map args = new HashMap();
    args.put("REGIONPATH", regionName);
    param.put("userArgs", args);
    Execution execution = FunctionService.onServers(clientPool).withArgs(param);
    FunctionUtil.onServer("REMOTE_ADMIN_FUNCTION", null);
    ResultCollector rc = execution.execute("REMOTE_ADMIN_FUNCTION");
    Object obj = rc.getResult();//w  w  w.  ja  va 2 s.  co m
    HashMap<String, Object> resultMap = new HashMap<String, Object>();
    if (obj != null) {
        ArrayList list = (ArrayList) obj;
        int total = 0;

        boolean isPR = false;
        for (int i = 0; i < list.size(); i++) {
            resultMap = (HashMap<String, Object>) list.get(i);
            if (resultMap.get("isPR") != null)
                isPR = (Boolean) resultMap.get("isPR");
            if (resultMap == null || resultMap.get("code") == null || resultMap.get("code").equals("-1")) {
                continue;
            }
            HashMap<DistributedMember, Integer> memberMap = (HashMap<DistributedMember, Integer>) resultMap
                    .get("memberMap");
            Iterator it = memberMap.entrySet().iterator();
            while (it.hasNext()) {
                Entry<DistributedMember, Integer> entry = (Entry<DistributedMember, Integer>) it.next();
                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put(entry.getKey().getId(), entry.getValue());
                rs.add(map);
                if (isPR)
                    total += entry.getValue();
            }
        }
        if (isPR) {
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("Total", total);
            rs.add(map);
        }
        return rs;
    }
    return null;
}

From source file:com.yahoo.ycsb.db.JdbcDBClient.java

@Override
public Status insert(String tableName, String key, HashMap<String, ByteIterator> values) {
    try {/*w ww  . j  a va 2  s . c  o m*/
        StringBuilder insert = new StringBuilder("INSERT INTO ");
        insert.append(tableName);
        insert.append(" VALUES(");
        insert.append("'");
        insert.append(StringEscapeUtils.escapeSql(key));
        insert.append("'");
        for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
            String field = entry.getValue().toString();
            insert.append(",");
            insert.append("'");
            insert.append(StringEscapeUtils.escapeSql(field));
            insert.append("'");
        }
        insert.append(")");
        Statement insertStatement = getShardConnectionByKey(key).createStatement();
        int result = insertStatement.executeUpdate(insert.toString());
        if (result == 1) {
            return Status.OK;
        }
        return Status.UNEXPECTED_STATE;
    } catch (SQLException e) {
        System.err.println("Error in processing insert to table: " + tableName + e);
        return Status.ERROR;
    }
}

From source file:feedme.controller.AddOrDeleteCategoryServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);/*from  w w w . ja  v a 2s .co m*/
    request.setCharacterEncoding("UTF-8");
    response.setStatus(HttpServletResponse.SC_OK);
    String CategoryName = request.getParameter("categoryName").trim();
    DbRestaurantsManagement ob = new DbRestaurantsManagement();

    boolean flag = false;

    HashMap<String, Integer> cat = new DbHPOnLoad().getCategories();

    for (String se : cat.keySet()) {
        if (se.contains(CategoryName))
            flag = true;
    }
    int result = 0;
    if (!flag)
        result = ob.addNewCategory(CategoryName);

    PrintWriter out = response.getWriter();
    if (result == 1) {
        if (isAjax(request) == true) { // Stay in the same page, and sand json message

            try {
                cat = new DbHPOnLoad().getCategories();
                JSONObject catObj = new JSONObject();
                JSONArray catArray = new JSONArray();
                for (Entry<String, Integer> entry : cat.entrySet()) {
                    catArray.put(
                            new JSONObject().put("cat_id", entry.getValue()).put("cat_name", entry.getKey()));
                }
                catObj.put("categories", catArray);
                catObj.put("status", true);
                response.setContentType("application/json");
                PrintWriter writer = response.getWriter();
                writer.print(catObj);
                response.getWriter().flush();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else { // redirect to othe page

        }
    }
}

From source file:it.polito.tellmefirst.web.rest.clients.ClientEpub.java

private void removeEmptyTOC(HashMap lhm) {

    LOG.debug("[removeEmptyTOC] - BEGIN");

    Set set = lhm.entrySet();
    Iterator i = set.iterator();//  w w w . j  ava 2s.co m

    while (i.hasNext()) {
        Map.Entry me = (Map.Entry) i.next();
        if (me.getValue().toString().equals("")) {
            LOG.info("Remove empty TOC: " + me.getKey().toString());
            i.remove();
        }
    }

    LOG.debug("[removeEmptyTOC] - END");
}

From source file:com.oDesk.api.OAuthClient.java

/**
 * Send signed GET OAuth request/*w  w w. ja  v a2s .  c o m*/
 * 
 * @param   url Relative URL
 * @param   type Type of HTTP request (HTTP method)
 * @param   params Hash of parameters
 * @throws   JSONException If JSON object is invalid or request was abnormal
 * @return   {@link JSONObject} JSON Object that contains data from response
 * */
private JSONObject sendGetRequest(String url, Integer type, HashMap<String, String> params)
        throws JSONException {
    String fullUrl = getFullUrl(url);
    HttpGet request = new HttpGet(fullUrl);

    if (params != null) {
        URI uri;
        String query = "";
        try {
            URIBuilder uriBuilder = new URIBuilder(request.getURI());

            // encode values and add them to the request
            for (Map.Entry<String, String> entry : params.entrySet()) {
                String key = entry.getKey();
                String value = entry.getValue();
                // to prevent double encoding, we need to create query string ourself
                // uriBuilder.addParameter(key, URLEncoder.encode(value).replace("%3B", ";"));
                query = query + key + "=" + value + "&";
            }
            uriBuilder.setCustomQuery(query);
            uri = uriBuilder.build();

            ((HttpRequestBase) request).setURI(uri);
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    try {
        mOAuthConsumer.sign(request);
    } catch (OAuthException e) {
        e.printStackTrace();
    }

    return oDeskRestClient.getJSONObject(request, type);
}

From source file:gov.utah.dts.sdc.dao.BaseDAO.java

private void almLog(String logEntry, String logTypeCode, HashMap formMap) throws Exception {
    StringBuffer userComment = new StringBuffer();
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");

    Set<Entry<String, Object>> entries = formMap.entrySet();
    Iterator<Entry<String, Object>> it = entries.iterator();
    while (it.hasNext()) {
        Entry<String, Object> e = it.next();
        String key = e.getKey();// w  w  w .  j a  v  a  2  s  . c o m
        Object val = e.getValue();
        userComment.append(key + " = ");
        if (val == null) {
            userComment.append("null | ");
        } else if (val instanceof Integer[]) {
            Integer[] vals = (Integer[]) val;
            for (int i = 0; i < vals.length; i++) {
                userComment.append(vals[i].intValue());
                if (i < vals.length - 1) {
                    userComment.append(", ");
                }
            }
            userComment.append(" | ");
        } else if (val instanceof Date) {
            userComment.append(sdf.format((Date) val) + " | ");
        } else {
            userComment.append(val.toString() + " | ");
        }
    }

    LoggingClient logClient = new LoggingClientImpl();
    WriteLogResponse writeLogResponse = logClient.writeLog(userId, logTypeCode, logEntry,
            userComment.toString());
    log.info("Write log response: " + writeLogResponse.getResponseMessage().getResponseDescription());
    ;
}