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.eclipse.lyo.testsuite.server.oslcv1tests.QueryTests.java

@SuppressWarnings("unchecked")
@Test/*from w  w w. j a va 2s  .  c o m*/
public void fulltextSearchReturnsScoreValueInResultsJson() throws IOException, SAXException,
        ParserConfigurationException, XPathExpressionException, JSONException {
    String query = getQueryBase();
    query = query + "oslc_cm.query=oslc_cm:searchTerms="
            + URLEncoder.encode("\"" + fullTextSearchTerm + "\"", "UTF-8");

    //Get response in json
    Iterator<HashMap<String, Object>> iter = processJSONQuery(query).iterator();
    while (iter.hasNext()) {
        HashMap<String, Object> lhm = iter.next();
        assertTrue(lhm.keySet().contains("oslc_cm:score"));
        assertTrue((Integer) lhm.get("oslc_cm:score") >= 0);
    }
}

From source file:org.eclipse.lyo.testsuite.server.oslcv1tests.QueryTests.java

@SuppressWarnings("unchecked")
@Test//from w ww . j av a  2  s .  c  o m
public void validGreaterThanQueriesContainExpectedDefectsJson() throws IOException, SAXException,
        ParserConfigurationException, XPathExpressionException, ParseException, JSONException {
    String query = getQueryBase();
    query = query + "oslc_cm.query=" + queryComparisonProperty
            + URLEncoder.encode(">=\"" + queryComparisonValue + "\"", "UTF-8") + "&"
            + URLEncoder.encode("oslc_cm.properties", "UTF-8") + "=" + queryComparisonProperty;

    //Get response in json
    Iterator<HashMap<String, String>> iter = processJSONQuery(query).iterator();
    while (iter.hasNext()) {
        HashMap<String, String> lhm = iter.next();
        assertTrue(lhm.keySet().contains(queryComparisonProperty));
        assertTrue(lhm.get(queryComparisonProperty).compareTo(queryComparisonValue) >= 0);
    }
}

From source file:com.gottibujiku.httpjsonexchange.main.HttpJSONExchange.java

/**
 * Adds additional headers to the HTTP Request
 * /*from  w w w .  ja v  a2  s. co  m*/
 * @param headers A Hashmap of name and value headers
 * @param connection A connection object used to connect to the server
 * @return Modified connection object with additional headers(if there were any)
 */
private HttpURLConnection addHeadersToRequest(HashMap<String, String> headers, HttpURLConnection connection) {
    Set<String> keys;
    if (headers != null) {//check if there were any additional headers
        keys = headers.keySet();//get headers' keys
        //set the headers as request properties
        for (String key : keys) {
            connection.setRequestProperty(key, headers.get(key));
        }
    }
    return connection;
}

From source file:net.sf.mpaxs.spi.server.HostRegister.java

/**
 *
 * @return//w w  w  .ja  v  a  2  s. c om
 */
public String[] getHostIps() {
    HashMap<UUID, Host> allHosts = hosts.getAll();
    String[] ret = new String[allHosts.size()];
    int j = 0;
    for (UUID key : allHosts.keySet()) {
        ret[j] = allHosts.get(key).getIP();
        j++;
    }
    return ret;
}

From source file:org.eclipse.lyo.testsuite.server.oslcv1tests.QueryTests.java

@SuppressWarnings("unchecked")
@Test//from   www  .j  a  v  a2s.c  om
public void validCompoundQueryContainsExpectedDefectJson() throws IOException, SAXException,
        ParserConfigurationException, XPathExpressionException, JSONException {
    String query = getQueryBase();
    query = query + "oslc_cm.query="
            + URLEncoder.encode(queryProperty + "=\"" + queryPropertyValue + "\" and " + queryComparisonProperty
                    + ">=\"" + queryComparisonValue + "\"", "UTF-8")
            + "&" + URLEncoder.encode("oslc_cm.properties", "UTF-8") + "=" + queryProperty + ","
            + queryComparisonProperty;

    Iterator<HashMap<String, String>> iter = processJSONQuery(query).iterator();
    while (iter.hasNext()) {
        HashMap<String, String> lhm = iter.next();
        assertTrue(lhm.keySet().contains(queryProperty));
        assertTrue(lhm.get(queryProperty).equals(queryPropertyValue));
        assertTrue(lhm.keySet().contains(queryComparisonProperty));
        assertTrue(lhm.get(queryComparisonProperty).compareTo(queryComparisonValue) >= 0);
    }
}

From source file:ru.apertum.qsystem.reports.model.QReportsList.java

public synchronized byte[] generate(QUser user, String uri, HashMap<String, String> params) {
    final HttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", uri);
    r.addHeader("Cookie", "username=" + user.getName() + "; password=" + user.getPassword());
    final StringBuilder sb = new StringBuilder();
    params.keySet().stream().forEach((st) -> {
        sb.append("&").append(st).append("=").append(params.get(st));
    });//from w  w w  .  j  a  v a2 s  . c  o m
    final InputStream is = new ByteArrayInputStream(sb.substring(1).getBytes());
    final BasicHttpEntity b = new BasicHttpEntity();
    b.setContent(is);
    r.setEntity(b);
    sb.setLength(0);
    return generate(r).getData();
}

From source file:NaraePreference.java

@SuppressWarnings("unchecked")
public HashMap<String, String> getValue(String key, HashMap<String, String> defaultvalue) {
    try {//from  ww  w . j  a  va 2  s .  co m
        HashMap<String, String> map = (HashMap<String, String>) pref.getAll();
        for (String s : map.keySet()) {
            String value = map.get(s);
            map.put(s, value);
        }
        return map;
    } catch (Exception e) {
        return defaultvalue;
    }
}

From source file:fi.elfcloud.sci.DataItem.java

/**
 * Updates meta header of {@link DataItem}.
 * @param newMetaValues//  w w w .jav a 2 s  .co  m
 * @throws ECException
 * @throws IOException
 */
public synchronized void updateMeta(HashMap<String, String> newMetaValues) throws ECException, IOException {
    Map<String, Object> params = new HashMap<String, Object>();
    HashMap<String, String> existingMeta = Utils.metaToMap(this.meta);

    for (String key : newMetaValues.keySet()) {
        if (newMetaValues.get(key) != null) {
            existingMeta.put(key, newMetaValues.get(key));
        }
    }
    this.meta = Utils.metaToString(existingMeta);
    params.put("parent_id", this.parentId);
    params.put("name", this.name);
    params.put("meta", this.meta);
    this.client.getConnection().sendRequest("update_dataitem", params);
}

From source file:com.aliyun.odps.flume.sink.OdpsSink.java

private void buildStreamWriters() throws IOException, TunnelException {
    final StreamClient.ShardState finish = StreamClient.ShardState.LOADED;
    long now = System.currentTimeMillis();
    long endTime = now + maxLoadShardTime * 1000;
    List<Long> shardIDList = null;
    while (now < endTime) {
        HashMap<Long, StreamClient.ShardState> shardStatus = streamClient.getShardStatus();
        shardIDList = new ArrayList<Long>();
        Set<Long> keys = shardStatus.keySet();
        Iterator<Long> iter = keys.iterator();
        while (iter.hasNext()) {
            Long key = iter.next();
            StreamClient.ShardState value = shardStatus.get(key);
            if (value.equals(finish)) {
                shardIDList.add(key);/*  w w w  .j av a2s .  c o  m*/
            }
        }
        now = System.currentTimeMillis();
        if (shardIDList.size() == shardNumber) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // DO NOTHING...
        }
    }
    if (shardIDList != null && shardIDList.size() > 0) {
        this.streamWriters = new StreamWriter[shardIDList.size()];
        for (int i = 0; i < shardIDList.size(); i++) {
            this.streamWriters[i] = streamClient.openStreamWriter(shardIDList.get(i));
        }
    } else {
        throw new RuntimeException(
                "Odps Sink " + getName() + " buildStreamWriter() error, have not loaded shards" + ".");
    }
}

From source file:edu.utexas.cs.tactex.interfaces.TariffOptimizerBase.java

/**
 * compute a mapping customer=>(tariff=>charge) for all relevant tariffs
 * Used by derived classes./*from w w w .ja  v  a  2 s . co  m*/
 * 
 * @param suggestedSpecs
 * @param tariffSubscriptions
 * @param competingTariffs
 * @param customer2ShiftedEnergy
 * @return
 */
protected HashMap<CustomerInfo, HashMap<TariffSpecification, Double>> estimateRelevantTariffCharges(
        List<TariffSpecification> suggestedSpecs,
        HashMap<TariffSpecification, HashMap<CustomerInfo, Integer>> tariffSubscriptions,
        List<TariffSpecification> competingTariffs,
        HashMap<CustomerInfo, HashMap<TariffSpecification, ShiftedEnergyData>> customer2ShiftedEnergy) {
    addSuggestedSpecsToRepo(suggestedSpecs);

    List<TariffSpecification> relevantTariffs = new ArrayList<TariffSpecification>(
            tariffSubscriptions.keySet());
    relevantTariffs.addAll(competingTariffs);
    relevantTariffs.addAll(suggestedSpecs);
    HashMap<CustomerInfo, HashMap<TariffSpecification, Double>> customer2estimatedTariffCharges = chargeEstimator
            .estimateRelevantTariffCharges(relevantTariffs, customer2ShiftedEnergy);

    removeTmpSpecsFromRepo(suggestedSpecs);

    return customer2estimatedTariffCharges;
}