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:net.opentsdb.tsd.HttpJsonSerializer.java
/** * Parses a single Tree object// w w w. ja v a 2 s.co m * <b>Note:</b> Incoming data is a hash map of strings instead of directly * deserializing to a tree. We do it this way because we don't want users * messing with the timestamp fields. * @return A parsed Tree * @throws JSONException if parsing failed * @throws BadRequestException if the content was missing or parsing failed */ public Tree parseTreeV1() { final String json = query.getContent(); if (json == null || json.isEmpty()) { throw new BadRequestException(HttpResponseStatus.BAD_REQUEST, "Missing message content", "Supply valid JSON formatted data in the body of your request"); } try { final HashMap<String, String> properties = JSON.parseToObject(json, TR_HASH_MAP); final Tree tree = new Tree(); for (Map.Entry<String, String> entry : properties.entrySet()) { // skip nulls, empty is fine, but nulls are not welcome here if (entry.getValue() == null) { continue; } if (entry.getKey().toLowerCase().equals("treeid")) { tree.setTreeId(Integer.parseInt(entry.getValue())); } else if (entry.getKey().toLowerCase().equals("name")) { tree.setName(entry.getValue()); } else if (entry.getKey().toLowerCase().equals("description")) { tree.setDescription(entry.getValue()); } else if (entry.getKey().toLowerCase().equals("notes")) { tree.setNotes(entry.getValue()); } else if (entry.getKey().toLowerCase().equals("enabled")) { if (entry.getValue().toLowerCase().equals("true")) { tree.setEnabled(true); } else { tree.setEnabled(false); } } else if (entry.getKey().toLowerCase().equals("strictmatch")) { if (entry.getValue().toLowerCase().equals("true")) { tree.setStrictMatch(true); } else { tree.setStrictMatch(false); } } else if (entry.getKey().toLowerCase().equals("storefailures")) { if (entry.getValue().toLowerCase().equals("true")) { tree.setStoreFailures(true); } else { tree.setStoreFailures(false); } } } return tree; } catch (NumberFormatException nfe) { throw new BadRequestException("Unable to parse 'tree' value"); } catch (IllegalArgumentException iae) { throw new BadRequestException("Unable to parse the given JSON", iae); } }
From source file:com.fujitsu.dc.client.http.RestAdapter.java
/** * This is the PUT method that receives the response body and uses Etag value and header map. * @param url Target Request URL/*from ww w .j a va2 s . com*/ * @param data Data to be sent * @param etag ETag value * @param map HashMap of Request Header * @param contentType CONTENT-TYPE value * @return DcResponse object * @throws DaoException Exception thrown */ public DcResponse put(String url, String data, String etag, HashMap<String, String> map, String contentType) throws DaoException { HttpUriRequest req = new DcRequestBuilder().url(url).method(HttpMethods.PUT).contentType(contentType) .ifMatch(etag).body(data).token(getToken()).defaultHeaders(this.accessor.getDefaultHeaders()) .build(); for (Map.Entry<String, String> entry : map.entrySet()) { req.setHeader((String) entry.getKey(), (String) entry.getValue()); } return this.request(req); }
From source file:android.syncml.pim.vcard.VCardComposer.java
/** Loop append TEL property. */ private void appendPhoneStr(List<ContactStruct.PhoneData> phoneList, int version) { HashMap<String, String> numMap = new HashMap<String, String>(); String joinMark = version == VERSION_VCARD21_INT ? ";" : ","; for (ContactStruct.PhoneData phone : phoneList) { String type;//from www . j a v a2 s . 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:ch.fixme.status.Main.java
private void populateDataHs() { try {// w w w .ja va 2s.c om HashMap<String, Object> data = new ParseGeneric(mResultHs).getData(); // Initialize views LayoutInflater inflater = getLayoutInflater(); LinearLayout vg = (LinearLayout) inflater.inflate(R.layout.base, null); ScrollView scroll = (ScrollView) findViewById(R.id.scroll); scroll.removeAllViews(); scroll.addView(vg); // Mandatory fields ((TextView) findViewById(R.id.space_name)).setText((String) data.get(ParseGeneric.API_NAME)); ((TextView) findViewById(R.id.space_url)).setText((String) data.get(ParseGeneric.API_URL)); getImageTask = new GetImage(R.id.space_image); getImageTask.execute((String) data.get(ParseGeneric.API_LOGO)); // Status text String status_txt = ""; if ((Boolean) data.get(ParseGeneric.API_STATUS)) { status_txt = OPEN; ((TextView) findViewById(R.id.status_txt)) .setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.presence_online, 0, 0, 0); } else { status_txt = CLOSED; ((TextView) findViewById(R.id.status_txt)) .setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.presence_busy, 0, 0, 0); } if (data.containsKey(ParseGeneric.API_STATUS_TXT)) { status_txt += ": " + (String) data.get(ParseGeneric.API_STATUS_TXT); } ((TextView) findViewById(R.id.status_txt)).setText(status_txt); // Status last change if (data.containsKey(ParseGeneric.API_LASTCHANGE)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setAutoLinkMask(0); tv.setText( getString(R.string.api_lastchange) + " " + (String) data.get(ParseGeneric.API_LASTCHANGE)); vg.addView(tv); } // Status duration if (data.containsKey(ParseGeneric.API_EXT_DURATION) && (Boolean) data.get(ParseGeneric.API_STATUS)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText(getString(R.string.api_duration) + " " + (String) data.get(ParseGeneric.API_EXT_DURATION) + getString(R.string.api_duration_hours)); vg.addView(tv); } // Location Pattern ptn = Pattern.compile("^.*$", Pattern.DOTALL); if (data.containsKey(ParseGeneric.API_ADDRESS) || data.containsKey(ParseGeneric.API_LON)) { TextView title = (TextView) inflater.inflate(R.layout.title, null); title.setText(getString(R.string.api_location)); vg.addView(title); inflater.inflate(R.layout.separator, vg); // Address if (data.containsKey(ParseGeneric.API_ADDRESS)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setAutoLinkMask(0); tv.setText((String) data.get(ParseGeneric.API_ADDRESS)); Linkify.addLinks(tv, ptn, MAP_SEARCH); vg.addView(tv); } // Lon/Lat if (data.containsKey(ParseGeneric.API_LON) && data.containsKey(ParseGeneric.API_LAT)) { String addr = (data.containsKey(ParseGeneric.API_ADDRESS)) ? (String) data.get(ParseGeneric.API_ADDRESS) : getString(R.string.empty); TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setAutoLinkMask(0); tv.setText((String) data.get(ParseGeneric.API_LON) + ", " + (String) data.get(ParseGeneric.API_LAT)); Linkify.addLinks(tv, ptn, String.format(MAP_COORD, (String) data.get(ParseGeneric.API_LAT), (String) data.get(ParseGeneric.API_LON), addr)); vg.addView(tv); } } // Contact if (data.containsKey(ParseGeneric.API_PHONE) || data.containsKey(ParseGeneric.API_TWITTER) || data.containsKey(ParseGeneric.API_IRC) || data.containsKey(ParseGeneric.API_EMAIL) || data.containsKey(ParseGeneric.API_ML)) { TextView title = (TextView) inflater.inflate(R.layout.title, null); title.setText(R.string.api_contact); vg.addView(title); inflater.inflate(R.layout.separator, vg); // Phone if (data.containsKey(ParseGeneric.API_PHONE)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText((String) data.get(ParseGeneric.API_PHONE)); vg.addView(tv); } // SIP if (data.containsKey(ParseGeneric.API_SIP)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText((String) data.get(ParseGeneric.API_SIP)); vg.addView(tv); } // Twitter if (data.containsKey(ParseGeneric.API_TWITTER)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText(TWITTER + (String) data.get(ParseGeneric.API_TWITTER)); vg.addView(tv); } // Identica if (data.containsKey(ParseGeneric.API_IDENTICA)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText((String) data.get(ParseGeneric.API_IDENTICA)); vg.addView(tv); } // Foursquare if (data.containsKey(ParseGeneric.API_FOURSQUARE)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText(FOURSQUARE + (String) data.get(ParseGeneric.API_FOURSQUARE)); vg.addView(tv); } // IRC if (data.containsKey(ParseGeneric.API_IRC)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setAutoLinkMask(0); tv.setText((String) data.get(ParseGeneric.API_IRC)); vg.addView(tv); } // Email if (data.containsKey(ParseGeneric.API_EMAIL)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText((String) data.get(ParseGeneric.API_EMAIL)); vg.addView(tv); } // Jabber if (data.containsKey(ParseGeneric.API_JABBER)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText((String) data.get(ParseGeneric.API_JABBER)); vg.addView(tv); } // Mailing-List if (data.containsKey(ParseGeneric.API_ML)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText((String) data.get(ParseGeneric.API_ML)); vg.addView(tv); } } // Sensors if (data.containsKey(ParseGeneric.API_SENSORS)) { // Title TextView title = (TextView) inflater.inflate(R.layout.title, null); title.setText(getString(R.string.api_sensors)); vg.addView(title); inflater.inflate(R.layout.separator, vg); HashMap<String, ArrayList<HashMap<String, String>>> sensors = (HashMap<String, ArrayList<HashMap<String, String>>>) data .get(ParseGeneric.API_SENSORS); Set<String> names = sensors.keySet(); Iterator<String> it = names.iterator(); while (it.hasNext()) { String name = it.next(); // Subtitle String name_title = name.toLowerCase().replace("_", " "); name_title = name_title.substring(0, 1).toUpperCase() + name_title.substring(1, name_title.length()); TextView subtitle = (TextView) inflater.inflate(R.layout.subtitle, null); subtitle.setText(name_title); vg.addView(subtitle); // Sensors data ArrayList<HashMap<String, String>> sensorsData = sensors.get(name); for (HashMap<String, String> elem : sensorsData) { RelativeLayout rl = (RelativeLayout) inflater.inflate(R.layout.entry_sensor, null); if (elem.containsKey(ParseGeneric.API_VALUE)) { ((TextView) rl.findViewById(R.id.entry_value)) .setText(elem.get(ParseGeneric.API_VALUE)); } else { rl.findViewById(R.id.entry_value).setVisibility(View.GONE); } if (elem.containsKey(ParseGeneric.API_UNIT)) { ((TextView) rl.findViewById(R.id.entry_unit)).setText(elem.get(ParseGeneric.API_UNIT)); } else { rl.findViewById(R.id.entry_unit).setVisibility(View.GONE); } if (elem.containsKey(ParseGeneric.API_NAME2)) { ((TextView) rl.findViewById(R.id.entry_name)).setText(elem.get(ParseGeneric.API_NAME2)); } else { rl.findViewById(R.id.entry_name).setVisibility(View.GONE); } if (elem.containsKey(ParseGeneric.API_LOCATION2)) { ((TextView) rl.findViewById(R.id.entry_location)) .setText(elem.get(ParseGeneric.API_LOCATION2)); } else { rl.findViewById(R.id.entry_location).setVisibility(View.GONE); } if (elem.containsKey(ParseGeneric.API_DESCRIPTION)) { ((TextView) rl.findViewById(R.id.entry_description)) .setText(elem.get(ParseGeneric.API_DESCRIPTION)); } else { rl.findViewById(R.id.entry_description).setVisibility(View.GONE); } if (elem.containsKey(ParseGeneric.API_PROPERTIES)) { ((TextView) rl.findViewById(R.id.entry_properties)) .setText(elem.get(ParseGeneric.API_PROPERTIES)); } else { rl.findViewById(R.id.entry_properties).setVisibility(View.GONE); } if (elem.containsKey(ParseGeneric.API_MACHINES)) { ((TextView) rl.findViewById(R.id.entry_other)) .setText(elem.get(ParseGeneric.API_MACHINES)); } else if (elem.containsKey(ParseGeneric.API_NAMES)) { ((TextView) rl.findViewById(R.id.entry_other)) .setText(elem.get(ParseGeneric.API_NAMES)); } else { rl.findViewById(R.id.entry_other).setVisibility(View.GONE); } vg.addView(rl); } } } // Stream and cam if (data.containsKey(ParseGeneric.API_STREAM) || data.containsKey(ParseGeneric.API_CAM)) { TextView title = (TextView) inflater.inflate(R.layout.title, null); title.setText(getString(R.string.api_stream)); vg.addView(title); inflater.inflate(R.layout.separator, vg); // Stream if (data.containsKey(ParseGeneric.API_STREAM)) { HashMap<String, String> stream = (HashMap<String, String>) data.get(ParseGeneric.API_STREAM); for (Entry<String, String> entry : stream.entrySet()) { final String type = entry.getKey(); final String url = entry.getValue(); TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText(url); tv.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(Uri.parse(url), type); startActivity(i); } }); vg.addView(tv); } } // Cam if (data.containsKey(ParseGeneric.API_CAM)) { HashMap<String, String> cam = (HashMap<String, String>) data.get(ParseGeneric.API_CAM); for (String value : cam.values()) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText(value); vg.addView(tv); } } } } catch (Exception e) { e.printStackTrace(); showError(e.getClass().getCanonicalName(), e.getLocalizedMessage() + getString(R.string.error_generic)); } }
From source file:com.tealeaf.util.HTTP.java
public File getFile(URI uri, String fileName, HashMap<String, String> requestHeaders) { InputStream in = null;/*ww w . j a v a 2 s .co m*/ File file = new File(fileName); new File(file.getParent()).mkdirs(); FileOutputStream fo = null; try { file.createNewFile(); fo = new FileOutputStream(file); } catch (IOException e1) { logger.log(e1); return null; } AndroidHttpClient client = null; try { client = AndroidHttpClient.newInstance(userAgent); HttpGet request = new HttpGet(); if (requestHeaders != null) { for (Map.Entry<String, String> entry : requestHeaders.entrySet()) { request.addHeader(new BasicHeader(entry.getKey(), entry.getValue())); } } request.setURI(uri); HttpResponse response = client.execute(request, localContext); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != 200) { client.close(); return null; } in = response.getEntity().getContent(); byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = in.read(buffer)) != -1) { fo.write(buffer, 0, bytesRead); } fo.close(); in.close(); client.close(); } catch (SocketTimeoutException e) { // forget it--we don't care that the user failed to connect } catch (IllegalArgumentException e) { // forget it--we don't care that the user failed to connect logger.log("{http} WARNING: Illegal argument" + uri); } catch (IOException e) { if (!caughtIOException) { caughtIOException = true; logger.log(e); } file = null; } finally { if (client != null) { client.close(); } if (in != null) { try { in.close(); } catch (IOException e) { // ignore it } } } return file; }
From source file:io.personium.client.http.RestAdapter.java
/** * This is the PUT method that receives the response body and uses Etag value and header map. * @param url Target Request URL// www .j av a2 s . c om * @param data Data to be sent * @param etag ETag value * @param map HashMap of Request Header * @param contentType CONTENT-TYPE value * @return DcResponse object * @throws DaoException Exception thrown */ public PersoniumResponse put(String url, String data, String etag, HashMap<String, String> map, String contentType) throws DaoException { HttpUriRequest req = new PersoniumRequestBuilder().url(url).method(HttpMethods.PUT).contentType(contentType) .ifMatch(etag).body(data).token(getToken()).defaultHeaders(this.accessor.getDefaultHeaders()) .build(); for (Map.Entry<String, String> entry : map.entrySet()) { req.setHeader((String) entry.getKey(), (String) entry.getValue()); } return this.request(req); }
From source file:io.personium.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 . java 2 s . c o 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 PersoniumResponse post(String url, HashMap<String, String> map, String data, String contentType) throws DaoException { HttpUriRequest req = new PersoniumRequestBuilder().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.mdlive.sav.MDLiveSearchProvider.java
/** * Instantiating array adapter to populate the listView * The layout android.R.layout.simple_list_item_single_choice creates radio button for each listview item * * @param list : Dependent users array list *///w w w .j a v a2s.com private void showListViewDialog(final ArrayList<String> list, final TextView selectedText, final String key, final ArrayList<HashMap<String, String>> typeList) { /*We need to get the instance of the LayoutInflater*/ final AlertDialog.Builder alertDialog = new AlertDialog.Builder(MDLiveSearchProvider.this); LayoutInflater inflater = getLayoutInflater(); View convertView = inflater.inflate(R.layout.mdlive_screen_popup, null); alertDialog.setView(convertView); ListView lv = (ListView) convertView.findViewById(R.id.popupListview); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list); lv.setAdapter(adapter); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); final AlertDialog dialog = alertDialog.create(); dialog.show(); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String SelectedText = list.get(position); HashMap<String, String> localMap = typeList.get(position); for (Map.Entry entry : localMap.entrySet()) { if (SelectedText.equals(entry.getValue().toString())) { postParams.put(key, entry.getKey().toString()); break; //breaking because its one to one map } } specialityBasedOnProvider(SelectedText, key); String oldChoice = selectedText.getText().toString(); selectedText.setText(SelectedText); dialog.dismiss(); // if user selects a different Provider type, then reload this screen if (!oldChoice.equals(SelectedText)) { SharedPreferences sharedpreferences = getSharedPreferences( PreferenceConstants.MDLIVE_USER_PREFERENCES, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PreferenceConstants.PROVIDER_MODE, SelectedText); int providerType = MDLiveConfig.PROVIDERTYPE_MAP.get(SelectedText) == null ? MDLiveConfig.UNMAPPED : MDLiveConfig.PROVIDERTYPE_MAP.get(SelectedText); if (providerType == MDLiveConfig.UNMAPPED) editor.putString(PreferenceConstants.PROVIDERTYPE_ID, ""); else editor.putString(PreferenceConstants.PROVIDERTYPE_ID, String.valueOf(providerType)); editor.commit(); // now reload the screen //recreate(); } } }); }
From source file:dao.EventCommentDao.java
public List<Object[]> getUserIdFailedCount(Campaign campaign, Date dateFrom, Date dateTo, Long pkId) { HashMap<String, Object> paramMap = new HashMap(); String sql = "select user_id,count(distinct event_id) from event_comment where type=:failed and campaign_id=:campaignId and personal_cabinet_id=:pkId"; if (dateFrom != null) { sql += " and insert_date>=:dateFrom"; paramMap.put("dateFrom", DateAdapter.getDateFromString(DateAdapter.getDateInMysql(dateFrom))); }/*from w w w . j a v a 2 s . c o m*/ if (dateTo != null) { sql += " and insert_date<=:dateTo"; paramMap.put("dateTo", DateAdapter.getDateFromString(DateAdapter.getDateInMysql(dateTo))); } sql += " group by user_id"; Query query = getCurrentSession().createSQLQuery(sql); query.setParameter("campaignId", campaign.getCampaignId()); query.setParameter("pkId", pkId); query.setParameter("failed", EventComment.FAILED); for (Map.Entry<String, Object> entry : paramMap.entrySet()) { query.setParameter(entry.getKey(), entry.getValue()); } return query.list(); }
From source file:edu.indiana.lib.twinpeaks.search.singlesearch.web2.Web2Query.java
public Iterator getStatusMapEntrySetIterator() { HashMap statusMap = (HashMap) getSessionContext().get("searchStatus"); Set entrySet = statusMap.entrySet(); return entrySet.iterator(); }