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:edu.stevens.cpe.reservior.readout.CMAES.java

public void updateReadoutWeights(double[] newWeights) {
    //TODO remove neuron hardcoding type
    int index = 0;
    for (int i = 0; i < ((SpikingOutput) readout).getNeurons().length; i++) {
        HashMap<String, Double> weights = ((SpikingOutput) readout).getNeurons()[i].getWeights();
        Iterator<String> it = weights.keySet().iterator();
        while (it.hasNext()) {
            String id = it.next();
            weights.put(id, newWeights[index]);
            index++;/*w  ww .  j a v  a 2 s  .  c om*/
        }
    }
}

From source file:com.webbfontaine.valuewebb.utils.TTMailUtils.java

public String replaceTextVariables(String text, HashMap<String, String> textVariables) {
    for (String key : textVariables.keySet()) {
        String replace = "";
        if (textVariables.get(key) != null) {
            replace = textVariables.get(key);
        }//from  w ww  .ja va  2s . c  o  m
        text = text.replaceAll(Pattern.quote(key), replace);
    }
    return text;
}

From source file:it.marcoberri.mbmeteo.action.chart.Base.java

/**
 *
 * @param params/*from w  w w  . j  ava  2s.co  m*/
 * @return
 */
protected String getCacheKey(HashMap<String, String> params) {
    try {
        final StringBuilder s = new StringBuilder();
        for (String k : params.keySet()) {
            s.append(k);
            s.append(params.get(k));
        }

        return DigestUtils.shaHex(s.toString());
    } catch (final Exception e) {
        log.error(e);
        return null;
    }
}

From source file:com.soomla.store.domain.data.VirtualGood.java

/**
 * The same as the above {@link com.soomla.store.domain.data.VirtualGood#getCurrencyValues()}
 * only here the returned value is a representation of the HashMap as a JSONObject.
 * @return the current price of the virtual good according to its price model as a JSONObject.
 *//*from  ww  w. ja  v  a  2 s .  co m*/
public JSONObject getCurrencyValuesAsJSONObject() {

    HashMap<String, Integer> currencyValue = mPriceModel.getCurrentPrice(this);
    JSONObject jsonObject = new JSONObject();
    for (String key : currencyValue.keySet()) {
        try {
            jsonObject.put(key, currencyValue.get(key));
        } catch (JSONException e) {
            if (StoreConfig.debug) {
                Log.d(TAG, "An error occurred while generating JSON object.");
            }
        }
    }

    return jsonObject;
}

From source file:Evaluator.StatCalculator.java

public double rmsCalc(HashMap<String, Double> kderunQidMap, HashMap<String, Double> aprunQidMap) {
    double sum = 0;
    Iterator it = kderunQidMap.keySet().iterator();
    while (it.hasNext()) {
        String run = (String) it.next();
        sum = (kderunQidMap.get(run) - aprunQidMap.get(run)) * (kderunQidMap.get(run) - aprunQidMap.get(run));

    }//from  w  w w  . j av  a2s  .  c om

    sum /= kderunQidMap.size();
    sum = Math.sqrt(sum);
    return sum;
}

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

/**
 * Method for writing all modules to file.
 * /* w  w  w . j a v  a  2 s  .c o  m*/
 * @param bw
 *            BufferedWriter to xml-file.
 */
private void writeModules(final HashMap<String, HashMap<String, String>> modules, final OutputStream bw)
        throws IOException {

    final Iterator<String> modit = modules.keySet().iterator();
    String module;

    while (modit.hasNext()) {
        module = modit.next();
        if (modules.get(module) == null) {
            bw.write(("<module name=\"" + module + "\"/>\n").getBytes("UTF-8"));
        } else {
            bw.write(("<module name=\"" + module + "\">\n").getBytes("UTF-8"));
            writeProperty(modules.get(module), bw);
            bw.write("</module>\n".getBytes("UTF-8"));
        }
    }
}

From source file:com.mc.printer.model.panel.task.BuildGuideTask.java

public void deepCloneMap(HashMap<String, GuideCompBean> dest, HashMap<String, GuideCompBean> src) {
    for (String str : src.keySet()) {
        GuideCompBean newbean;//  w w  w . ja v a 2s  . c o m
        try {
            newbean = src.get(str).clone();
            dest.put(str, newbean);
        } catch (CloneNotSupportedException ex) {
            logger.error(ex.getMessage());
        }

    }
}

From source file:csiro.pidsvc.mappingstore.action.ActionProxy.java

@Override
public void run() {
    HttpClient httpClient = new DefaultHttpClient();
    try {/*from  w  w w.jav  a  2  s  .  co m*/
        HttpServletRequest originalHttpRequest = _controller.getRequest();
        HttpServletResponse originalHttpResponse = _controller.getResponse();
        HttpGet httpGet = new HttpGet(getExpandedActionValue());

        if (isTraceMode())
            trace(httpGet.getRequestLine().toString());

        // Pass-through HTTP headers.
        HashMap<String, String> hmHeaders = _controller.getHttpHeaders();
        for (String header : hmHeaders.keySet()) {
            httpGet.addHeader(header, hmHeaders.get(header));
            if (isTraceMode())
                trace("\t" + header + ": " + hmHeaders.get(header));
        }

        // Handle X-Original-URI HTTP header.
        if (!hmHeaders.containsKey("X-Original-URI")) {
            String originalUri = originalHttpRequest.getScheme() + "://" + originalHttpRequest.getServerName();
            if (originalHttpRequest.getServerPort() != 80)
                originalUri += ":" + originalHttpRequest.getServerPort();
            originalUri += _controller.getUri().getOriginalUriAsString();

            httpGet.addHeader("X-Original-URI", originalUri);
            if (isTraceMode())
                trace("\tX-Original-URI: " + originalUri);
        }

        // Get the data.
        HttpResponse response = httpClient.execute(httpGet);
        HttpEntity entity = response.getEntity();
        if (isTraceMode())
            trace(response.getStatusLine().toString());

        // Pass HTTP headers through.
        if (!isTraceMode())
            originalHttpResponse.setStatus(response.getStatusLine().getStatusCode());
        if (entity.getContentType() != null) {
            if (isTraceMode()) {
                trace("\tContent-Type: " + entity.getContentType().getValue());
                trace("\tContent-Length: " + EntityUtils.toString(entity).getBytes().length);
            } else
                originalHttpResponse.setContentType(entity.getContentType().getValue());
        }

        String headerName;
        for (Header header : response.getAllHeaders()) {
            headerName = header.getName();
            if (headerName.equalsIgnoreCase("Expires") || headerName.equalsIgnoreCase("Cache-Control")
                    || headerName.equalsIgnoreCase("Content-Type") || headerName.equalsIgnoreCase("Set-Cookie")
                    || headerName.equalsIgnoreCase("Transfer-Encoding"))
                continue;
            if (isTraceMode())
                trace("\t" + header.getName() + ": " + header.getValue());
            else
                originalHttpResponse.addHeader(header.getName(), header.getValue());
        }

        // Pass content through.
        if (!isTraceMode())
            originalHttpResponse.getWriter().write(EntityUtils.toString(entity));
    } catch (Exception e) {
        _logger.trace("Exception occurred while proxying HTTP request.", e);
        if (isTraceMode()) {
            Throwable cause = e.getCause();
            trace("Set response status: 500; exception: "
                    + (cause == null ? e.getMessage() : cause.getMessage()));
        } else
            Http.returnErrorCode(_controller.getResponse(), 500, e);
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}

From source file:info.unyttig.helladroid.newzbin.NewzBinController.java

/**
 * Sends HTTP POST requests to Newzbin with given parameters. 
 * //from  w  ww.ja  v  a2 s . co  m
 * @param url Type:String - The url to connect to
 * @param kvPairs Type:Map - The map of parameters to post
 * @return Returns a HttpResponse with results 
 * @throws ClientProtocolException
 * @throws IOException
 */
public static HttpResponse doPost(String url, HashMap<String, String> kvPairs)
        throws ClientProtocolException, IOException {

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);
    httppost.addHeader("Content-type", "application/x-www-form-urlencoded");

    if (kvPairs != null && kvPairs.isEmpty() == false) {
        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(kvPairs.size() + 4);
        nameValuePairs
                .add(new BasicNameValuePair("limit", preferences.getString("newzbin_search_limit", "10")));
        nameValuePairs
                .add(new BasicNameValuePair("retention", preferences.getString("newzbin_retention", "7")));
        nameValuePairs.add(new BasicNameValuePair("username", preferences.getString("newzbin_username", "")));
        nameValuePairs.add(new BasicNameValuePair("password", preferences.getString("newzbin_password", "")));
        String k, v;
        Iterator<String> itKeys = kvPairs.keySet().iterator();
        while (itKeys.hasNext()) {
            k = itKeys.next();
            v = kvPairs.get(k);
            nameValuePairs.add(new BasicNameValuePair(k, v));
        }
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    }
    return httpclient.execute(httppost);
}

From source file:com.soomla.store.domain.data.BalanceDrivenPriceModel.java

/**
 * docs in {@link AbstractPriceModel#toJSONObject()}
 *//*from   ww  w  . jav  a2 s .  c  om*/
@Override
public JSONObject toJSONObject() throws JSONException {
    JSONObject parentJsonObject = super.toJSONObject();
    JSONObject jsonObject = new JSONObject();

    Iterator<?> keys = parentJsonObject.keys();
    while (keys.hasNext()) {
        String key = (String) keys.next();
        jsonObject.put(key, parentJsonObject.get(key));
    }

    JSONArray valuesPerBalance = new JSONArray();
    for (HashMap<String, Integer> currencyValue : mCurrencyValuePerBalance) {
        JSONObject currencyValues = new JSONObject();
        for (String key : currencyValue.keySet()) {
            currencyValues.put(key, currencyValue.get(key));
        }
        valuesPerBalance.put(currencyValues);
    }
    jsonObject.put(JSONConsts.GOOD_PRICE_MODEL_VALUES, valuesPerBalance);

    return jsonObject;
}