List of usage examples for java.util HashMap keySet
public Set<K> keySet()
From source file:edu.utexas.cs.tactex.tariffoptimization.TariffOptimizierTOUFixedMargin.java
private TotalEnergyRecords sumTotalEnergy(HashMap<CustomerInfo, ArrayRealVector> customer2estimatedEnergy, HashMap<TariffSpecification, HashMap<CustomerInfo, Integer>> tariffSubscriptions, int currentTimeslot) { List<TariffSpecification> allSpecs = new ArrayList<TariffSpecification>(); allSpecs.addAll(tariffSubscriptions.keySet()); HashMap<CustomerInfo, HashMap<TariffSpecification, ShiftedEnergyData>> customer2ShiftedEnergy = estimateShiftedPredictions( customer2estimatedEnergy, allSpecs, currentTimeslot); int predictionRecordLength = customer2estimatedEnergy.values().iterator().next().getDimension(); ArrayRealVector predictedMyCustomersEnergy = new ArrayRealVector(predictionRecordLength); // we currently predict cost by total amount of energy //// www . j av a 2s . c o m for (Entry<TariffSpecification, HashMap<CustomerInfo, Integer>> entry : tariffSubscriptions.entrySet()) { TariffSpecification spec = entry.getKey(); for (Entry<CustomerInfo, Integer> e : entry.getValue().entrySet()) { CustomerInfo customer = e.getKey(); int subs = e.getValue(); RealVector customerEnergy = customer2ShiftedEnergy.get(customer).get(spec).getShiftedEnergy() .mapMultiply(subs); predictedMyCustomersEnergy = predictedMyCustomersEnergy.add(customerEnergy); } } // competitor energy prediction ArrayRealVector predictedCompetitorsEnergyRecord = new ArrayRealVector(predictionRecordLength); HashMap<CustomerInfo, HashMap<TariffSpecification, Integer>> predictedCustomerSubscriptions = BrokerUtils .revertKeyMapping(tariffSubscriptions); for (CustomerInfo cust : predictedCustomerSubscriptions.keySet()) { double subsToOthers = cust.getPopulation() - BrokerUtils.sumMapValues(predictedCustomerSubscriptions.get(cust)); RealVector customerNonShiftedEnergy = customer2estimatedEnergy.get(cust).mapMultiply(subsToOthers); predictedCompetitorsEnergyRecord = predictedCompetitorsEnergyRecord.add(customerNonShiftedEnergy); } log.debug("predictedMyCustomersEnergy =" + predictedMyCustomersEnergy.toString()); log.debug("predictedCompetitorsEnergyRecord =" + predictedCompetitorsEnergyRecord.toString()); return new TotalEnergyRecords(predictedMyCustomersEnergy, predictedCompetitorsEnergyRecord); }
From source file:com.yangcong345.android.phone.manager.OkHttpStack.java
@Override public synchronized HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { String url = request.getUrl(); if (mUrlRewriter != null) { String rewritten = mUrlRewriter.rewriteUrl(url); if (rewritten == null) { throw new IOException("URL blocked by rewriter: " + url); }/*from ww w .ja v a 2 s .c o m*/ url = rewritten; } /*init request builder*/ okhttp3.Request.Builder okRequestBuilder = new okhttp3.Request.Builder().url(url) .cacheControl(new CacheControl.Builder().maxAge(0, TimeUnit.SECONDS).build()); /*set request headers*/ HashMap<String, String> map = new HashMap<String, String>(); map.putAll(request.getHeaders()); map.putAll(additionalHeaders); for (String headerName : map.keySet()) { okRequestBuilder.addHeader(headerName, map.get(headerName)); } /*set request method*/ setRequestMethod(okRequestBuilder, request); okhttp3.Request okRequest = okRequestBuilder.build(); /*init request client*/ int timeoutMs = request.getTimeoutMs(); OkHttpClient.Builder okClientBuilder = new OkHttpClient.Builder(); okClientBuilder.followRedirects(HttpURLConnection.getFollowRedirects()) .followSslRedirects(HttpURLConnection.getFollowRedirects()) .connectTimeout(timeoutMs, TimeUnit.MILLISECONDS).readTimeout(timeoutMs, TimeUnit.MILLISECONDS); if (okRequest.isHttps() && mSslSocketFactory != null) { okClientBuilder.sslSocketFactory(mSslSocketFactory); } // Initialize HttpResponse with data from the HttpURLConnection. ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1); OkHttpClient okClient = okClientBuilder.build(); Response okResponse = okClient.newCall(okRequest).execute(); int responseCode = okResponse.code(); if (responseCode == -1) { // -1 is returned by getResponseCode() if the response code could not be retrieved. // Signal to the caller that something was wrong with the connection. throw new IOException("Could not retrieve response code from HttpUrlConnection."); } StatusLine responseStatus = new BasicStatusLine(protocolVersion, responseCode, okResponse.message()); BasicHttpResponse response = new BasicHttpResponse(responseStatus); if (hasResponseBody(request.getMethod(), responseStatus.getStatusCode())) { response.setEntity(entityFromOkHttp(okResponse)); } for (int i = 0; i < okResponse.headers().size(); i++) { String name = okResponse.headers().name(i); String value = okResponse.headers().value(i); Header h = new BasicHeader(name, value); response.addHeader(h); } return response; }
From source file:com.odoo.support.provider.OContentProvider.java
private void handleManyToMany(HashMap<String, List<Integer>> record_ids, int _id) { if (record_ids.size() > 0) { for (String key : record_ids.keySet()) { List<Integer> ids = record_ids.get(key); OColumn column = model.getColumn(key); OModel rel_model = model.createInstance(column.getType()); model.manageManyToManyRecords(model.getWritableDatabase(), rel_model, ids, _id, Command.Replace); }/*from www. ja va 2 s. c o m*/ } }
From source file:dk.defxws.fedoragsearch.server.GTransformer.java
public StringBuffer transform(String xsltName, Source sourceStream, URIResolver uriResolver, HashMap<String, String> params, boolean checkInHome) throws Exception { logger.fine("xsltName=" + xsltName); Transformer transformer = getTransformer(xsltName, uriResolver, checkInHome); //logger.info(params); Iterator it = params.keySet().iterator(); String key = ""; String value = ""; while (it.hasNext()) { key = (String) it.next(); value = params.get(key);/* w w w . j av a2s . c om*/ if (value == null) { value = ""; } transformer.setParameter(key, value); } transformer.setParameter("DATETIME", new Date()); StreamResult destStream = new StreamResult(new StringWriter()); try { transformer.transform(sourceStream, destStream); } catch (TransformerException e) { logger.log(Level.SEVERE, "transform " + xsltName + ":\n", e); throw new Exception("transform " + xsltName + ":\n", e); } StringWriter sw = (StringWriter) destStream.getWriter(); // if (logger.isDebugEnabled()) // logger.debug("sw="+sw.getBuffer().toString()); return sw.getBuffer(); }
From source file:com.magnet.android.mms.controller.RequestSchema.java
public void bindMethodNameMap(HashMap<String, String> encNameMap) { for (String key : encNameMap.keySet()) { bindMethodName(key, encNameMap.get(key)); }//from www . ja va 2 s . c om }
From source file:de.uniwue.info6.webapp.misc.InitVariables.java
/** * @param event/*from w ww . ja v a 2 s. c o m*/ */ @Override public void contextDestroyed(final ServletContextEvent event) { // ------------------------------------------------ // ConnectionTools.inst().cleanUp(); // ------------------------------------------------ // C3P0Registry.getNumPooledDataSources(); PooledDataSource dataSource = null; @SuppressWarnings({ "unchecked", "rawtypes" }) Iterator<Set> it = C3P0Registry.getPooledDataSources().iterator(); while (it.hasNext()) { try { dataSource = (PooledDataSource) it.next(); dataSource.close(); } catch (Exception e) { LOGGER.error("Error deregistering driver %s", dataSource, e); } } // ------------------------------------------------ // final HashMap<Scenario, ComboPooledDataSource> pools = ConnectionManager.instance().getPools(); for (Scenario scenario : pools.keySet()) { final String dbHost = scenario.getDbHost(); final String dbPort = scenario.getDbPort(); final String url = ConnectionManager.URL_PREFIX + dbHost + ":" + dbPort + "/"; Driver mariaDBDriver = null; try { final ComboPooledDataSource cpds = pools.get(scenario); mariaDBDriver = DriverManager.getDriver(url); if (mariaDBDriver != null) { DriverManager.deregisterDriver(mariaDBDriver); } DataSources.destroy(cpds); } catch (SQLException e) { } catch (Exception e) { LOGGER.error(String.format("Error deregistering driver %s", mariaDBDriver), e); } } // ------------------------------------------------ // Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { Driver driver = drivers.nextElement(); try { DriverManager.deregisterDriver(driver); LOGGER.info(String.format("deregistering jdbc driver: %s", driver)); } catch (SQLException e) { LOGGER.error(String.format("Error deregistering driver %s", driver), e); } } // ------------------------------------------------ // // for (Thread thread : Thread.getAllStackTraces().keySet()) { // } // ------------------------------------------------ // }
From source file:ca.mcgill.cs.creco.logic.AttributeExtractor.java
/** Constructor that takes a category. * @param pDataStore the whole space of interesting products *///ww w . j ava 2 s.co m @Autowired public AttributeExtractor(IDataStore pDataStore) { aDataStore = pDataStore; aAllAttributes = new HashMap<String, ArrayList<ScoredAttribute>>(); for (Category cat : aDataStore.getCategories()) { ArrayList<ScoredAttribute> scoredAttributeList = new ArrayList<ScoredAttribute>(); HashMap<String, Attribute> attributes = new HashMap<String, Attribute>(); for (Product prod : cat.getProducts()) { for (Attribute att : prod.getAttributes()) { attributes.put(att.getId(), att); } } for (String key : attributes.keySet()) { ScoredAttribute sa = null; try { sa = new ScoredAttribute(attributes.get(key), cat); sa.getAttributeID(); } catch (IllegalArgumentException iae) { LOG.error(iae.toString()); } scoredAttributeList.add(sa); } sort(DEFAULT_SORT, scoredAttributeList); aAllAttributes.put(cat.getId(), scoredAttributeList); } }
From source file:com.tedx.activities.LazyActivity.java
protected void startActivityForPosition(Class<?> targetCls, int position) { HashMap<String, String> info = mAdapterData.get(position); Intent i = new Intent(this, targetCls); for (String key : info.keySet()) { i.putExtra(key, info.get(key));/*from ww w.ja v a2s. c o m*/ } startActivity(i); }
From source file:de.rrze.idmone.utils.jidgen.cli.IdGenHelpFormatter.java
/** * Compile the fully formatted help message that should be * reachable via the --help option and returns it as a string. * //www . j a v a 2 s .c o m * @param options * options that should be included in the help message * @return the formatted help message as a string */ public String getHelpString(IdGenOptions options, boolean longHelp) { StringBuffer sb = new StringBuffer(); // usage string sb.append(Messages.getString("IdGenerator.HELP_USAGE")); if (!longHelp) { sb.append(Globals.NEWLINE); sb.append(Messages.getString("IdGenerator.HELP_SHORT_EXAMPLE")); sb.append(Globals.NEWLINE); } if (longHelp) { sb.append(Globals.NEWLINE); sb.append(Messages.getString("IdGenerator.HELP_INTRO")); } if (longHelp) { // predefined data sb.append(Globals.NEWLINE); HashMap<String, String> presets = Template.getPredefinedData(); if (!presets.isEmpty()) { sb.append(format(Messages.getString("IdGenereator.HELP_PREDEFINED_STRINGS"))); for (Iterator<String> iter = presets.keySet().iterator(); iter.hasNext();) { String key = iter.next(); sb.append( format(key + "\t" + Messages.getString("Template.HELP_DATA_PRESET_" + key.toUpperCase()) + " (" + presets.get(key) + ")" + Messages.getString("IdGenerator.NEW_LINE"))); } sb.append(Globals.NEWLINE); } } if (longHelp) { // template syntax sb.append(Globals.NEWLINE); sb.append(format(Messages.getString("IdGenerator.HELP_TEMPLATE_SYNTAX"))); } // command line options sb.append(Globals.NEWLINE); sb.append(format(Messages.getString("IdGenerator.HELP_CLI_OPTIONS"))); sb.append(this.renderOptions(options)); if (longHelp) { // example string sb.append(Globals.NEWLINE); sb.append(Messages.getString("IdGenerator.HELP_LONG_EXAMPLE")); } return sb.toString(); }
From source file:org.openmidaas.library.common.network.AndroidNetworkTransport.java
@Override public void doPostRequest(boolean withSSL, String url, HashMap<String, String> headers, JSONObject data, AsyncHttpResponseHandler responseHandler) { try {/*ww w. j ava 2s. c o m*/ AsyncHttpClient client = new AsyncHttpClient(); if (headers != null) { if (headers.size() > 0) { MIDaaS.logDebug(TAG, "Headers: "); MIDaaS.logDebug(TAG, "Key: Value"); for (String key : headers.keySet()) { client.addHeader(key, headers.get(key)); MIDaaS.logDebug(TAG, "" + key + " : " + headers.get(key)); } } } MIDaaS.logDebug(TAG, "Data: " + data.toString()); client.post(null, mHostUrl + url, new StringEntity(data.toString()), "application/json", responseHandler); } catch (UnsupportedEncodingException e) { MIDaaS.logError(TAG, e.getMessage()); responseHandler.onFailure(e, e.getMessage()); } }