List of usage examples for java.util LinkedHashMap entrySet
public Set<Map.Entry<K, V>> entrySet()
From source file:gov.nih.nci.cabig.caaers.domain.report.Report.java
public void removeFromMetaData(String k) { LinkedHashMap<String, String> map = getMetaDataAsMap(); StringBuilder sb = new StringBuilder(); map.remove(k);//w w w . java 2 s . com for (Map.Entry<String, String> e : map.entrySet()) { if (sb.length() > 0) sb.append("|~"); sb.append(e.getKey()).append(":~").append(e.getValue()); } setMetaData(sb.toString()); }
From source file:gov.nih.nci.cabig.caaers.domain.report.Report.java
public void addToMetaData(String k, String v) { if (StringUtils.isEmpty(k) || StringUtils.isEmpty(v)) return;//from w ww . j a v a 2 s . c om LinkedHashMap<String, String> map = getMetaDataAsMap(); StringBuilder sb = new StringBuilder(); map.put(k, v); for (Map.Entry<String, String> e : map.entrySet()) { if (sb.length() > 0) sb.append("|$"); sb.append(e.getKey()).append(":~").append(e.getValue()); } setMetaData(sb.toString()); }
From source file:org.onebusaway.android.report.ui.Open311ProblemFragment.java
/** * Dynamically creates checkboxes/*from w ww . j a v a 2s .c om*/ * * @param open311Attribute contains the open311 attributes */ private void createMultiValueList(Open311Attribute open311Attribute) { ArrayList<Object> values = (ArrayList<Object>) open311Attribute.getValues(); if (values != null && values.size() > 0) { LayoutInflater inflater = LayoutInflater.from(getActivity()); RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.report_issue_multi_value_list_item, null, false); ((ImageView) layout.findViewById(R.id.ri_ic_checkbox)) .setColorFilter(getResources().getColor(R.color.material_gray)); Spannable word = new SpannableString(open311Attribute.getDescription()); ((TextView) layout.findViewById(R.id.rimvli_textView)).setText(word); if (open311Attribute.getRequired()) { Spannable wordTwo = new SpannableString(" *Required"); wordTwo.setSpan(new ForegroundColorSpan(Color.RED), 0, wordTwo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ((TextView) layout.findViewById(R.id.rimvli_textView)).append(wordTwo); } // Restore view state from attribute result hash map AttributeValue av = mAttributeValueHashMap.get(open311Attribute.getCode()); LinearLayout cg = (LinearLayout) layout.findViewById(R.id.rimvli_checkBoxGroup); for (int i = 0; i < values.size(); i++) { LinkedHashMap<String, String> value = (LinkedHashMap<String, String>) values.get(i); CheckBox cb = new CheckBox(getActivity()); cg.addView(cb); String attributeKey = ""; String attributeValue = ""; for (LinkedHashMap.Entry<String, String> entry : value.entrySet()) { if (Open311Attribute.NAME.equals(entry.getKey())) { cb.setText(entry.getValue()); if (av != null && av.getValues().contains(entry.getValue())) { cb.setChecked(true); } attributeKey = open311Attribute.getCode() + entry.getValue(); } else if (Open311Attribute.KEY.equals(entry.getKey())) { attributeValue = entry.getValue(); } } mOpen311AttributeKeyNameMap.put(attributeKey, attributeValue); } mInfoLayout.addView(layout); mDynamicAttributeUIMap.put(open311Attribute.getCode(), cg); } }
From source file:com.android.mtkex.chips.BaseRecipientAdapter.java
/** * Constructs an actual list for this Adapter using {@link #mEntryMap}. Also tries to * fetch a cached photo for each contact entry (other than separators), or request another * thread to get one from directories.//from ww w . j a v a 2 s . c o m */ private List<RecipientEntry> constructEntryList(LinkedHashMap<Long, List<RecipientEntry>> entryMap, List<RecipientEntry> nonAggregatedEntries) { final List<RecipientEntry> entries = new ArrayList<RecipientEntry>(); int validEntryCount = 0; for (Map.Entry<Long, List<RecipientEntry>> mapEntry : entryMap.entrySet()) { final List<RecipientEntry> entryList = mapEntry.getValue(); final int size = entryList.size(); for (int i = 0; i < size; i++) { RecipientEntry entry = entryList.get(i); entries.add(entry); tryFetchPhoto(entry); validEntryCount++; } /// M: Fix the condition of reaching maximum result count if (validEntryCount >= mPreferredMaxResultCount) { break; } } if (validEntryCount < mPreferredMaxResultCount) { for (RecipientEntry entry : nonAggregatedEntries) { if (validEntryCount >= mPreferredMaxResultCount) { break; } entries.add(entry); tryFetchPhoto(entry); validEntryCount++; } } return entries; }
From source file:com.streamsets.pipeline.stage.origin.jdbc.JdbcSource.java
private Record processRow(ResultSet resultSet, long rowCount) throws SQLException, StageException { Source.Context context = getContext(); ResultSetMetaData md = resultSet.getMetaData(); int numColumns = md.getColumnCount(); LinkedHashMap<String, Field> fields = jdbcUtil.resultSetToFields(resultSet, commonSourceConfigBean, errorRecordHandler, unknownTypeAction, null); if (fields.size() != numColumns) { errorRecordHandler.onError(JdbcErrors.JDBC_35, fields.size(), numColumns); return null; // Don't output this record. }//w w w . j a v a2s .c om final String recordContext = StringUtils.substring(query.replaceAll("[\n\r]", ""), 0, 100) + "::rowCount:" + rowCount + (StringUtils.isEmpty(offsetColumn) ? "" : ":" + resultSet.getString(offsetColumn)); Record record = context.createRecord(recordContext); if (jdbcRecordType == JdbcRecordType.LIST_MAP) { record.set(Field.createListMap(fields)); } else if (jdbcRecordType == JdbcRecordType.MAP) { record.set(Field.create(fields)); } else { // type is LIST List<Field> row = new ArrayList<>(); for (Map.Entry<String, Field> fieldInfo : fields.entrySet()) { Map<String, Field> cell = new HashMap<>(); cell.put("header", Field.create(fieldInfo.getKey())); cell.put("value", fieldInfo.getValue()); row.add(Field.create(cell)); } record.set(Field.create(row)); } if (createJDBCNsHeaders) { jdbcUtil.setColumnSpecificHeaders(record, Collections.<String>emptySet(), md, jdbcNsHeaderPrefix); } // We will add cdc operation type to record header even if createJDBCNsHeaders is false // we currently support CDC on only MS SQL. if (hikariConfigBean.getConnectionString().startsWith("jdbc:sqlserver")) { MSOperationCode.addOperationCodeToRecordHeader(record); } return record; }
From source file:com.smartitengineering.dao.impl.hbase.CommonDao.java
protected void deleteOptimistically(Template[] states) throws IllegalStateException { final byte[] family = infoProvider.getVersionColumnFamily(); final byte[] qualifier = infoProvider.getVersionColumnQualifier(); Collection<Future<String>> deletes = new ArrayList<Future<String>>(); for (final Template state : states) { if (!state.isValid()) { throw new IllegalStateException("Entity not in valid state!"); }/*from w w w .j a v a 2s . co m*/ LinkedHashMap<String, Delete> dels = getConverter().objectToDeleteableRows(state, executorService, false); final byte[] version = state.getVersion() != null ? Bytes.toBytes(state.getVersion()) : null; if (logger.isInfoEnabled() && version != null) { logger.info("Version to check on delete optimistically is " + Bytes.toLong(version)); } else if (logger.isInfoEnabled()) { logger.info("Version is null"); } for (final Map.Entry<String, Delete> del : dels.entrySet()) { deletes.add(executorService.executeAsynchronously(del.getKey(), new Callback<String>() { @Override public String call(HTableInterface tableInterface) throws Exception { final Delete delVal = del.getValue(); boolean deleted = tableInterface.checkAndDelete(delVal.getRow(), family, qualifier, version, delVal); if (logger.isInfoEnabled()) { logger.info("Deleted row? " + deleted); } if (!deleted) { return String.format(errorMessageFormat, infoProvider.getIdFromRowId(delVal.getRow()).toString(), Bytes.toString(tableInterface.getTableName())); } return null; } })); } } throwIfErrors(deletes); }
From source file:org.mitre.dsmiley.httpproxy.URITemplateProxyServlet.java
@Override protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { //First collect params /*//from w w w. j av a 2 s.c om * Do not use servletRequest.getParameter(arg) because that will * typically read and consume the servlet InputStream (where our * form data is stored for POST). We need the InputStream later on. * So we'll parse the query string ourselves. A side benefit is * we can keep the proxy parameters in the query string and not * have to add them to a URL encoded form attachment. */ String queryString = "?" + servletRequest.getQueryString();//no "?" but might have "#" int hash = queryString.indexOf('#'); if (hash >= 0) { queryString = queryString.substring(0, hash); } List<NameValuePair> pairs; try { //note: HttpClient 4.2 lets you parse the string without building the URI pairs = URLEncodedUtils.parse(new URI(queryString), "UTF-8"); } catch (URISyntaxException e) { throw new ServletException("Unexpected URI parsing error on " + queryString, e); } LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); for (NameValuePair pair : pairs) { params.put(pair.getName(), pair.getValue()); } //Now rewrite the URL StringBuffer urlBuf = new StringBuffer();//note: StringBuilder isn't supported by Matcher Matcher matcher = TEMPLATE_PATTERN.matcher(targetUriTemplate); while (matcher.find()) { String arg = matcher.group(1); String replacement = params.remove(arg);//note we remove if (replacement == null) { throw new ServletException("Missing HTTP parameter " + arg + " to fill the template"); } matcher.appendReplacement(urlBuf, replacement); } matcher.appendTail(urlBuf); String newTargetUri = urlBuf.toString(); servletRequest.setAttribute(ATTR_TARGET_URI, newTargetUri); URI targetUriObj; try { targetUriObj = new URI(newTargetUri); } catch (Exception e) { throw new ServletException("Rewritten targetUri is invalid: " + newTargetUri, e); } servletRequest.setAttribute(ATTR_TARGET_HOST, URIUtils.extractHost(targetUriObj)); //Determine the new query string based on removing the used names StringBuilder newQueryBuf = new StringBuilder(queryString.length()); for (Map.Entry<String, String> nameVal : params.entrySet()) { if (newQueryBuf.length() > 0) newQueryBuf.append('&'); newQueryBuf.append(nameVal.getKey()).append('='); if (nameVal.getValue() != null) newQueryBuf.append(nameVal.getValue()); } servletRequest.setAttribute(ATTR_QUERY_STRING, newQueryBuf.toString()); super.service(servletRequest, servletResponse); }
From source file:convcao.com.agent.ConvcaoNeptusInteraction.java
public TransferData localState() { TransferData data = new TransferData(); data.timeStep = this.timestep; data.SessionID = sessionID;/*from w w w . ja v a 2s. com*/ data.Bathymeter = new double[auvs]; data.Location = new double[auvs][3]; for (int AUV = 0; AUV < auvs; AUV++) { String auvName = nameTable.get(AUV); double noptDepth = coords.convertWgsDepthToNoptilusDepth(positions.get(auvName).getDepth()); data.Bathymeter[AUV] = noptDepth - bathymetry.get(auvName); double[] nopCoords = coords.convert(positions.get(auvName)); if (nopCoords == null) { GuiUtils.errorMessage(getConsole(), "ConvCAO", auvName + " is outside operating region"); return null; } data.Location[AUV][0] = Math.round(nopCoords[0]); data.Location[AUV][1] = Math.round(nopCoords[1]); data.Location[AUV][2] = (int) noptDepth; } LinkedHashMap<EstimatedState, ArrayList<Distance>> samples = new LinkedHashMap<>(); synchronized (dvlMeasurements) { samples.putAll(dvlMeasurements); dvlMeasurements.clear(); } Vector<double[]> locations = new Vector<>(); Vector<Double> bathymetry = new Vector<>(); for (Entry<EstimatedState, ArrayList<Distance>> beams : samples.entrySet()) { for (Distance d : beams.getValue()) { double measurement[] = getBeamMeasurement(beams.getKey(), d); locations.add(new double[] { measurement[0], measurement[1], measurement[2] }); bathymetry.add(measurement[3]); } } data.MBSamples = new double[bathymetry.size()]; data.SampleLocations = new double[bathymetry.size()][3]; for (int i = 0; i < bathymetry.size(); i++) { data.MBSamples[i] = bathymetry.get(i); data.SampleLocations[i] = locations.get(i); } return data; }
From source file:org.onebusaway.android.report.ui.Open311ProblemFragment.java
/** * Dynamically creates radio buttons/*w w w. j a v a2 s . co m*/ * * @param open311Attribute contains the open311 attributes */ private void createSingleValueList(Open311Attribute open311Attribute) { ArrayList<Object> values = (ArrayList<Object>) open311Attribute.getValues(); if (values != null && values.size() > 0) { LayoutInflater inflater = LayoutInflater.from(getActivity()); RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.report_issue_single_value_list_item, null, false); layout.setSaveEnabled(true); ((ImageView) layout.findViewById(R.id.ri_ic_radio)) .setColorFilter(getResources().getColor(R.color.material_gray)); Spannable word = new SpannableString(open311Attribute.getDescription()); ((TextView) layout.findViewById(R.id.risvli_textView)).setText(word); if (open311Attribute.getRequired()) { Spannable wordTwo = new SpannableString(" *Required"); wordTwo.setSpan(new ForegroundColorSpan(Color.RED), 0, wordTwo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ((TextView) layout.findViewById(R.id.risvli_textView)).append(wordTwo); } RadioGroup rg = (RadioGroup) layout.findViewById(R.id.risvli_radioGroup); rg.setOrientation(RadioGroup.VERTICAL); // Restore view state from attribute result hash map AttributeValue av = mAttributeValueHashMap.get(open311Attribute.getCode()); String entryValue = null; if (av != null) { entryValue = av.getSingleValue(); } for (int i = 0; i < values.size(); i++) { LinkedHashMap<String, String> value = (LinkedHashMap<String, String>) values.get(i); RadioButton rb = new RadioButton(getActivity()); rg.addView(rb); //the RadioButtons are added to the radioGroup instead of the layout String attributeKey = ""; String attributeValue = ""; for (LinkedHashMap.Entry<String, String> entry : value.entrySet()) { if (Open311Attribute.NAME.equals(entry.getKey())) { rb.setText(entry.getValue()); if (entryValue != null && entryValue.equalsIgnoreCase(entry.getValue())) { rb.setChecked(true); } attributeKey = open311Attribute.getCode() + entry.getValue(); } else if (Open311Attribute.KEY.equals(entry.getKey())) { attributeValue = entry.getValue(); } } mOpen311AttributeKeyNameMap.put(attributeKey, attributeValue); } mInfoLayout.addView(layout); mDynamicAttributeUIMap.put(open311Attribute.getCode(), rg); } }
From source file:Simulator.PerformanceCalculation.java
public JPanel waitTime1() { LinkedHashSet no = new LinkedHashSet(); LinkedHashMap<Integer, ArrayList<Double>> wait1 = new LinkedHashMap<>(); for (Map.Entry<Integer, TraceObject> entry : l.getLocalTrace().entrySet()) { TraceObject traceObject = entry.getValue(); if (wait1.get(traceObject.getSurgeonId()) == null) { ArrayList details = new ArrayList(); details.add(traceObject.getWaitTime1()); wait1.put(traceObject.getSurgeonId(), details); } else {//from w w w . j a v a2 s .c om wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime1()); } no.add(traceObject.getSurgeonId()); } String[] column = new String[no.size()]; String series1 = "Wait Time 1"; for (int i = 0; i < no.size(); i++) { column[i] = "Surgeon " + (i + 1); } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); LinkedHashMap<Integer, Double> average = new LinkedHashMap<>(); for (Map.Entry<Integer, ArrayList<Double>> entry : wait1.entrySet()) { Integer integer = entry.getKey(); ArrayList<Double> arrayList = entry.getValue(); double total = 0; for (Double double1 : arrayList) { total += double1; } average.put(integer, total / arrayList.size()); } for (int i = 1; i <= average.size(); i++) { dataset.addValue(Math.round(average.get(i) / 600), series1, column[i - 1]); } JFreeChart chart = ChartFactory.createBarChart("Wait Time 1", // chart title "Surgeon ID", // domain axis label "Days", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); return new ChartPanel(chart); }