List of usage examples for java.util HashMap entrySet
Set entrySet
To view the source code for java.util HashMap entrySet.
Click Source Link
From source file:eu.planets_project.tb.impl.model.ExperimentExecutableImpl.java
public Map.Entry<URI, String> getCharacterisationHttpDataEntry(String localFileInputRef) { if (this.hmInputOutputData.containsKey(localFileInputRef)) { String outputFileRef = this.hmInputOutputData.get(localFileInputRef); HashMap<URI, String> hmRet = new HashMap<URI, String>(); //get the URI return values for the local file ref URI inputFile = this.getOutputHttpFileRef(outputFileRef); if (inputFile != null) { hmRet.put(inputFile, outputFileRef); Iterator<Entry<URI, String>> itRet = hmRet.entrySet().iterator(); while (itRet.hasNext()) { //return the Entry return itRet.next(); }//from w w w . j av a 2 s.com } } return null; }
From source file:au.org.ala.layers.dao.LayerIntersectDAOImpl.java
@Override public HashMap[] sampling(String pointsString, int gridcacheToUse) { init();/*from w ww . ja v a 2 s. c o m*/ //parse points String[] pointsArray = pointsString.split(","); double[][] points = new double[pointsArray.length / 2][2]; for (int i = 0; i < pointsArray.length; i += 2) { try { points[i / 2][1] = Double.parseDouble(pointsArray[i]); points[i / 2][0] = Double.parseDouble(pointsArray[i + 1]); } catch (Exception e) { points[i / 2][1] = Double.NaN; points[i / 2][0] = Double.NaN; } } //output structure HashMap[] output = new HashMap[points.length]; for (int i = 0; i < points.length; i++) { output[i] = new HashMap(); } if (0 == gridcacheToUse) { String fids = ""; for (Field f : fieldDao.getFields()) { if (f.isEnabled() && f.isIndb()) { if (!fids.isEmpty()) { fids += ","; } fids += f.getId(); } } String[] fidsSplit = fids.split(","); ArrayList<String> sample = sampling(fidsSplit, points); for (int i = 0; i < sample.size(); i++) { String[] column = sample.get(i).split("\n"); for (int j = 0; j < column.length; j++) { output[j].put(fidsSplit[i], column[j]); } } } else if (1 == gridcacheToUse) { //contextual intersections if (getConfig().getShapeFileCache() != null) { HashMap<String, SimpleShapeFile> ssfs = getConfig().getShapeFileCache().getAll(); for (Entry<String, SimpleShapeFile> entry : ssfs.entrySet()) { for (int i = 0; i < points.length; i++) { output[i].put(entry.getKey(), entry.getValue().intersect(points[i][0], points[i][1])); } } } //environmental intersections if (gridReaders != null) { GridCacheReader gcr = null; try { gcr = gridReaders.take(); for (int i = 0; i < points.length; i++) { output[i].putAll(gcr.sample(points[i][0], points[i][1])); } } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (gcr != null) { try { gridReaders.put(gcr); } catch (Exception e) { logger.error(e.getMessage(), e); } } } } } return output; }
From source file:com.maass.android.imgur_uploader.ImgurUpload.java
private void handleResponse() { Log.i(this.getClass().getName(), "in handleResponse()"); // close progress notification mNotificationManager.cancel(NOTIFICATION_ID); String notificationMessage = getString(R.string.upload_success); // notification intent with result final Intent notificationIntent = new Intent(getBaseContext(), ImageDetails.class); if (mImgurResponse == null) { notificationMessage = getString(R.string.connection_failed); } else if (mImgurResponse.get("error") != null) { notificationMessage = getString(R.string.unknown_error) + mImgurResponse.get("error"); } else {/*from ww w . j a v a 2s . c om*/ // create thumbnail if (mImgurResponse.get("image_hash").length() > 0) { createThumbnail(imageLocation); } // store result in database final HistoryDatabase histData = new HistoryDatabase(getBaseContext()); final SQLiteDatabase data = histData.getWritableDatabase(); final HashMap<String, String> dataToSave = new HashMap<String, String>(); dataToSave.put("delete_hash", mImgurResponse.get("delete_hash")); dataToSave.put("image_url", mImgurResponse.get("original")); final Uri imageUri = Uri .parse(getFilesDir() + "/" + mImgurResponse.get("image_hash") + THUMBNAIL_POSTFIX); dataToSave.put("local_thumbnail", imageUri.toString()); dataToSave.put("upload_time", "" + System.currentTimeMillis()); for (final Map.Entry<String, String> entry : dataToSave.entrySet()) { final ContentValues content = new ContentValues(); content.put("hash", mImgurResponse.get("image_hash")); content.put("key", entry.getKey()); content.put("value", entry.getValue()); data.insert("imgur_history", null, content); } //set intent to go to image details notificationIntent.putExtra("hash", mImgurResponse.get("image_hash")); notificationIntent.putExtra("image_url", mImgurResponse.get("original")); notificationIntent.putExtra("delete_hash", mImgurResponse.get("delete_hash")); notificationIntent.putExtra("local_thumbnail", imageUri.toString()); data.close(); histData.close(); // if the main activity is already open then refresh the gridview sendBroadcast(new Intent(BROADCAST_ACTION)); } //assemble notification final Notification notification = new Notification(R.drawable.icon, notificationMessage, System.currentTimeMillis()); notification.setLatestEventInfo(this, getString(R.string.app_name), notificationMessage, PendingIntent .getActivity(getBaseContext(), 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT)); notification.flags |= Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:com.google.gwt.emultest.java.util.HashMapTest.java
public void testEntrySet() { HashMap<String, String> hashMap = new HashMap<String, String>(); checkEmptyHashMapAssumptions(hashMap); Set<Map.Entry<String, String>> entrySet = hashMap.entrySet(); assertNotNull(entrySet);/*from w ww . j a va 2 s . c o m*/ // Check that the entry set looks right hashMap.put(KEY_TEST_ENTRY_SET, VALUE_TEST_ENTRY_SET_1); entrySet = hashMap.entrySet(); assertEquals(entrySet.size(), SIZE_ONE); Iterator<Map.Entry<String, String>> itSet = entrySet.iterator(); Map.Entry<String, String> entry = itSet.next(); assertEquals(entry.getKey(), KEY_TEST_ENTRY_SET); assertEquals(entry.getValue(), VALUE_TEST_ENTRY_SET_1); assertEmptyIterator(itSet); // Check that entries in the entrySet are update correctly on overwrites hashMap.put(KEY_TEST_ENTRY_SET, VALUE_TEST_ENTRY_SET_2); entrySet = hashMap.entrySet(); assertEquals(entrySet.size(), SIZE_ONE); itSet = entrySet.iterator(); entry = itSet.next(); assertEquals(entry.getKey(), KEY_TEST_ENTRY_SET); assertEquals(entry.getValue(), VALUE_TEST_ENTRY_SET_2); assertEmptyIterator(itSet); // Check that entries are updated on removes hashMap.remove(KEY_TEST_ENTRY_SET); checkEmptyHashMapAssumptions(hashMap); }
From source file:com.fujitsu.dc.client.http.RestAdapter.java
/** * This is the POST method that receives the request body that does not need authorization and uses header map. * @param url Target URL/* w w w.ja v a 2 s .co m*/ * @param map HashMap of Request Header * @param data Data to be written * @param contentType CONTENT-TYPE value * @return DcResponse object * @throws DaoException Exception thrown */ public DcResponse post(String url, HashMap<String, String> map, String data, String contentType) throws DaoException { HttpUriRequest req = new DcRequestBuilder().url(url).method(HttpMethods.POST).contentType(contentType) .body(data).token(getToken()).defaultHeaders(this.accessor.getDefaultHeaders()).build(); for (Map.Entry<String, String> entry : map.entrySet()) { req.setHeader(entry.getKey(), entry.getValue()); } return this.request(req); }
From source file:com.esri.geoportal.harvester.beans.BrokerDefinitionManagerBean.java
@Override public Collection<Map.Entry<UUID, EntityDefinition>> list() throws CrudlException { HashMap<UUID, EntityDefinition> map = new HashMap<>(); try (Connection connection = dataSource.getConnection(); PreparedStatement st = connection.prepareStatement("SELECT * FROM BROKERS");) { ResultSet rs = st.executeQuery(); while (rs.next()) { try { UUID id = UUID.fromString(rs.getString("id")); EntityDefinition td = deserialize(rs.getString("brokerDefinition"), EntityDefinition.class); td.setRef(id.toString()); map.put(id, td);/*from w w w . j av a 2 s . c o m*/ } catch (IOException | SQLException ex) { LOG.warn("Error reading broker definition", ex); } } } catch (SQLException ex) { throw new CrudlException("Error selecting broker definition", ex); } return map.entrySet(); }
From source file:com.transage.privatespace.vcard.pim.vcard.VCardComposer.java
/** Loop append TEL property. */ private void appendPhoneStr(List<PhoneData> phoneList, int version) { HashMap<String, String> numMap = new HashMap<String, String>(); String joinMark = version == VERSION_VCARD21_INT ? ";" : ","; for (PhoneData phone : phoneList) { String type;//from w w w . j a va2s . co m if (!isNull(phone.data)) { type = getPhoneTypeStr(phone); if (version == VERSION_VCARD30_INT && type.indexOf(";") != -1) { type = type.replace(";", ","); } if (numMap.containsKey(phone.data)) { type = numMap.get(phone.data) + joinMark + type; } numMap.put(phone.data, type); } } for (Map.Entry<String, String> num : numMap.entrySet()) { if (version == VERSION_VCARD21_INT) { mResult.append("TEL;"); } else { // vcard3.0 mResult.append("TEL;TYPE="); } mResult.append(num.getValue()).append(":").append(num.getKey()).append(mNewline); } }
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 //// w w w. j av a2 s. com 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.esri.geoportal.harvester.beans.TriggerManagerBean.java
@Override public Collection<Map.Entry<UUID, TaskUuidTriggerDefinitionPair>> list() throws CrudlException { HashMap<UUID, TaskUuidTriggerDefinitionPair> map = new HashMap<>(); try (Connection connection = dataSource.getConnection(); PreparedStatement st = connection.prepareStatement("SELECT * FROM TRIGGERS");) { ResultSet rs = st.executeQuery(); while (rs.next()) { try { UUID id = UUID.fromString(rs.getString("id")); TaskUuidTriggerDefinitionPair td = deserialize(rs.getString("definition"), TaskUuidTriggerDefinitionPair.class); map.put(id, td);//from ww w . j a v a 2 s. c o m } catch (IOException | SQLException ex) { LOG.warn("Error reading broker definition", ex); } } } catch (SQLException ex) { throw new CrudlException("Error selecting broker definition", ex); } return map.entrySet(); }