List of usage examples for java.util Hashtable keySet
Set keySet
To view the source code for java.util Hashtable keySet.
Click Source Link
From source file:com.hs.mail.mailet.RemoteDelivery.java
/** * For this message, we take the list of recipients, organize these into * distinct servers, and deliver the message for each of these servers. *///from w ww. ja va 2 s . c o m public void service(Set<Recipient> recipients, SmtpMessage message) throws MessagingException { // Organize the recipients into distinct servers (name made case insensitive) Hashtable<String, Collection<Recipient>> targets = new Hashtable<String, Collection<Recipient>>(); for (Recipient recipient : recipients) { String targetServer = recipient.getHost().toLowerCase(Locale.US); if (!Config.isLocal(targetServer)) { String key = (null == gateway) ? targetServer : gateway; Collection<Recipient> temp = targets.get(key); if (temp == null) { temp = new ArrayList<Recipient>(); targets.put(key, temp); } temp.add(recipient); } } if (targets.isEmpty()) { return; } // We have the recipients organized into distinct servers List<Recipient> undelivered = new ArrayList<Recipient>(); MimeMessage mimemsg = message.getMimeMessage(); boolean deleteMessage = true; for (String targetServer : targets.keySet()) { Collection<Recipient> temp = targets.get(targetServer); if (!deliver(targetServer, temp, message, mimemsg)) { // Retry this message later deleteMessage = false; if (!temp.isEmpty()) { undelivered.addAll(temp); } } } if (!deleteMessage) { try { message.setRetryCount(message.getRetryCount() + 1); message.setLastUpdate(new Date()); recipients.clear(); recipients.addAll(undelivered); message.store(); } catch (IOException e) { } } }
From source file:org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.rm.defaults.DefaultDescribe.java
/** * @param vms vms to sort/*from w w w .j a va 2s. c om*/ * @return Hashtable with key: reservationID (String) * and value: VMs in the reservation (List) * @throws CannotTranslateException problem */ protected Hashtable sort(VM[] vms) throws CannotTranslateException { if (vms == null) { throw new IllegalArgumentException("vms may not be null"); } final Set seenKeys = new HashSet(); final Hashtable dict = new Hashtable(); for (int i = 0; i < vms.length; i++) { final VM vm = vms[i]; if (vm == null) { logger.error("Manager implementation is invalid, received " + "null VM in query response"); continue; // *** GOTO NEXT VM *** } final String groupid = vm.getGroupID(); if (groupid == null) { this._newNoGroupID(vm, seenKeys, dict); } else { this._newGroupReservation(vm, groupid, seenKeys, dict); } } // look at all VMs to make sure they have elastic instance IDs, // they will not if they were created via other protocols and have // never shown up to this messaging layer before final Iterator iter = dict.keySet().iterator(); while (iter.hasNext()) { final String elasticReservationID = (String) iter.next(); final List group = (List) dict.get(elasticReservationID); final Iterator groupiter = group.iterator(); while (groupiter.hasNext()) { final VM vm = (VM) groupiter.next(); try { this.ids.checkInstanceAndReservation(vm.getID(), elasticReservationID); } catch (Exception e) { final String elasticSingleID = this.ids.managerInstanceToElasticReservation(vm.getID()); if (elasticSingleID == null) { throw new CannotTranslateException(e.getMessage(), e); } } } } return dict; }
From source file:edu.ku.brc.specify.utilapps.RegisterApp.java
/** * @return// w ww .j av a2 s .c o m */ private JPanel getStatsPane(final String chartPrefixTitle, final Collection<RegProcEntry> entries, final String tableName) { CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "f:p:g")); final Hashtable<String, String> keyDescPairsHash = rp.getAllDescPairsHash(); final Hashtable<String, String> desc2KeyPairsHash = new Hashtable<String, String>(); for (String key : keyDescPairsHash.keySet()) { desc2KeyPairsHash.put(keyDescPairsHash.get(key), key); } Vector<String> keywords = new Vector<String>(); for (String keyword : getKeyWordsList(entries)) { if (keyword.endsWith("_name") || keyword.endsWith("_type") || keyword.endsWith("ISA_Number") || keyword.endsWith("reg_isa")) { //keywords.add(keyword); } else { String desc = keyDescPairsHash.get(keyword); //System.out.println("["+keyword+"]->["+desc+"]"); if (desc != null) { keywords.add(desc); } else { System.out.println("Desc for keyword[" + keyword + "] is null."); } } } Vector<Object[]> rvList = BasicSQLUtils .query("SELECT DISTINCT(Name) FROM registeritem WHERE SUBSTRING(Name, 1, 4) = 'num_'"); for (Object[] array : rvList) { keywords.add((String) array[0]); } Collections.sort(keywords); final JList list = new JList(keywords); pb.add(UIHelper.createScrollPane(list), cc.xy(1, 1)); list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { String statName = (String) list.getSelectedValue(); if (desc2KeyPairsHash.get(statName) != null) { statName = desc2KeyPairsHash.get(statName); } DateType dateType = convertDateType(statName); if (dateType == DateType.None) { Vector<Pair<String, Integer>> values; if (statName.startsWith("num_")) { values = getCollNumValuesFromList(statName); Hashtable<String, Boolean> hash = new Hashtable<String, Boolean>(); for (Pair<String, Integer> p : values) { if (hash.get(p.first) == null) { hash.put(p.first, true); } else { int i = 0; String name = p.first; while (hash.get(p.first) != null) { p.first = name + " _" + i; i++; } hash.put(p.first, true); } //p.first += "(" + p.second.toString() + ")"; } } else { values = getCollValuesFromList(statName); } Collections.sort(values, countComparator); Vector<Pair<String, Integer>> top10Values = new Vector<Pair<String, Integer>>(); for (int i = 1; i < Math.min(11, values.size()); i++) { top10Values.insertElementAt(values.get(values.size() - i), 0); } createBarChart(chartPrefixTitle + " " + statName, statName, top10Values); } else { String desc = getByDateDesc(dateType); Vector<Pair<String, Integer>> values = tableName.equals("track") ? getDateValuesFromListByTable(dateType, tableName) : getDateValuesFromList(dateType); Collections.sort(values, titleComparator); createBarChart(chartPrefixTitle + " " + desc, desc, values); } } } }); return pb.getPanel(); }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerDlg.java
@Override public Vector<Locale> getLocalesInUse() { Hashtable<String, Boolean> localeHash = new Hashtable<String, Boolean>(); // Add any from the Database Vector<Locale> localeList = getLocalesInUseInDB(schemaType); for (Locale locale : localeList) { localeHash.put(SchemaLocalizerXMLHelper.makeLocaleKey(locale.getLanguage(), locale.getCountry(), locale.getVariant()), true); }/* w w w. j av a 2 s . c o m*/ for (SpLocaleContainer container : tables) { SchemaLocalizerXMLHelper.checkForLocales(container, localeHash); for (LocalizableItemIFace f : container.getContainerItems()) { SchemaLocalizerXMLHelper.checkForLocales(f, localeHash); } } localeList.clear(); for (String key : localeHash.keySet()) { String[] toks = StringUtils.split(key, "_"); localeList.add(new Locale(toks[0], "", "")); } return localeList; }
From source file:us.mn.state.health.lims.testanalyte.daoimpl.TestAnalyteTestResultDAOImpl.java
public void updateData(Test test, List allOldTestAnalytes, List allOldTestResults, List allNewTestAnalytes, List allNewTestResults) throws LIMSRuntimeException { Transaction tx = null;//from w w w . j a v a2 s . com Session session = null; try { session = HibernateUtil.getSession(); tx = session.beginTransaction(); // this stores all testResult Ids (test results can be shared // amongst components) Hashtable allOldTestResultsForTest = new Hashtable(); Hashtable allNewTestResultsForTest = new Hashtable(); // load hashtables if (allNewTestResults != null) { for (int j = 0; j < allNewTestResults.size(); j++) { TestResult tr = (TestResult) allNewTestResults.get(j); if (!StringUtil.isNullorNill(tr.getId())) { allNewTestResultsForTest.put(tr.getId(), tr); } } } if ((allOldTestResults != null) && (allOldTestResults.size() > 0)) { for (int j = 0; j < allOldTestResults.size(); j++) { TestResult tr = (TestResult) allOldTestResults.get(j); allOldTestResultsForTest.put(tr.getId(), tr); } } // Get a List of allNewTrIds (all new test result Ids) from // Hashtable allNewTestResultsForTest // Note : this does not include new ones that don't have an id yet!! Set allNewTrIdsSet = (Set) allNewTestResultsForTest.keySet(); Iterator allNewTrIdsIt = allNewTrIdsSet.iterator(); List allNewTrIds = new ArrayList(); while (allNewTrIdsIt.hasNext()) { allNewTrIds.add(allNewTrIdsIt.next()); } // Get a List of allOldTrIds (all old test result Ids) from // Hashtable allOldTestResultsForTest Set allOldTrIdsSet = (Set) allOldTestResultsForTest.keySet(); Iterator allOldTrIdsIt = allOldTrIdsSet.iterator(); List allOldTrIds = new ArrayList(); while (allOldTrIdsIt.hasNext()) { allOldTrIds.add(allOldTrIdsIt.next()); } // Loop through all new test analytes for (int i = 0; i < allNewTestAnalytes.size(); i++) { TestAnalyte testAnalyte = (TestAnalyte) allNewTestAnalytes.get(i); List testResults = new ArrayList(); List oldTestResults = new ArrayList(); TestAnalyte testAnalyteClone; //bug#1342 String analyteType; if (!StringUtil.isNullorNill(testAnalyte.getId())) { // UPDATE testAnalyteClone = readTestAnalyte(testAnalyte.getId()); oldTestResults = testAnalyteClone.getTestResults(); //bug#1342 recover old test analyte type (R/N) as this is not submitted //correctly when select is disabled and User re-sorts analyteType = testAnalyteClone.getTestAnalyteType(); PropertyUtils.copyProperties(testAnalyteClone, testAnalyte); //bug#1342 recover old test analyte type (R/N) as this is not submitted //correctly when select is disabled and User resorts if (testAnalyte.getTestAnalyteType() == null) { testAnalyteClone.setTestAnalyteType(analyteType); } // list of testResults testResults = testAnalyteClone.getTestResults(); session.merge(testAnalyteClone); session.flush(); session.clear(); } else { // INSERT testAnalyte.setId(null); // list of testResults testResults = testAnalyte.getTestResults(); session.save(testAnalyte); session.flush(); session.clear(); } List newIds = new ArrayList(); List oldIds = new ArrayList(); if (testResults != null) { for (int j = 0; j < testResults.size(); j++) { TestResult tr = (TestResult) testResults.get(j); newIds.add(tr.getId()); } } if ((oldTestResults != null) && (oldTestResults.size() > 0)) { List listOfOldOnesToRemove = new ArrayList(); for (int j = 0; j < oldTestResults.size(); j++) { TestResult tr = (TestResult) oldTestResults.get(j); oldIds.add(tr.getId()); if (!newIds.contains(tr.getId())) { // remove ones that are to be deleted listOfOldOnesToRemove.add(new Integer(j)); } } int decreaseOTRIndexBy = 0; int decreaseOIIndexBy = 0; for (int j = 0; j < listOfOldOnesToRemove.size(); j++) { oldTestResults .remove(((Integer) listOfOldOnesToRemove.get(j)).intValue() - decreaseOTRIndexBy++); oldIds.remove(((Integer) listOfOldOnesToRemove.get(j)).intValue() - decreaseOIIndexBy++); } } //Loop through new testResults for this particular testAnalyte if (testResults != null) { for (int j = 0; j < testResults.size(); j++) { TestResult teRe = (TestResult) testResults.get(j); int index = oldIds.indexOf(teRe.getId()); if (!StringUtil.isNullorNill(teRe.getId()) && allOldTestResultsForTest.containsKey(teRe.getId())) { //UPDATE TestResult testResultClone = readTestResult(teRe.getId()); PropertyUtils.copyProperties(testResultClone, teRe); if (index >= 0) { oldTestResults.set(index, testResultClone); } else { oldTestResults.add(testResultClone); } session.merge(teRe); session.flush(); session.clear(); } else { //INSERT oldTestResults.add(teRe); session.save(teRe); session.flush(); session.clear(); } } } // remove test analytes from total list which holds all test analytes to be deleted (this is not a // candidate for delete because it is amongst the new test // analytes list!) if (allOldTestAnalytes != null) { for (int x = 0; x < allOldTestAnalytes.size(); x++) { TestAnalyte ta = (TestAnalyte) allOldTestAnalytes.get(x); if (ta.getId().equals(testAnalyte.getId())) { allOldTestAnalytes.remove(x); break; } } } } // BEGIN OF DELETE // Delete any left-over old test analytes if ((allOldTestAnalytes != null) && (allOldTestAnalytes.size() > 0)) { for (int i = 0; i < allOldTestAnalytes.size(); i++) { TestAnalyte testAnalyte = (TestAnalyte) allOldTestAnalytes.get(i); session.delete(testAnalyte); session.flush(); session.clear(); } } // Delete any left-over old test results if ((allOldTrIds != null) && (allOldTrIds.size() > 0)) { for (int i = 0; i < allOldTrIds.size(); i++) { if (!allNewTrIds.contains(allOldTrIds.get(i))) { TestResult testResult = (TestResult) allOldTestResultsForTest.get(allOldTrIds.get(i)); session.delete(testResult); session.flush(); session.clear(); } } } // END OF DELETE tx.commit(); } catch (Exception e) { //bugzilla 2154 LogEvent.logError("TestAnalyteTestResultDAOImpl", "updateData()", e.toString()); if (tx != null) tx.rollback(); throw new LIMSRuntimeException("Error in TestAnalyteTestResult updateData()", e); } }
From source file:org.hdiv.filter.AbstractValidatorHelper.java
/** * Check if all required parameters are received in <code>request</code>. * //from w w w. j a va 2 s .c o m * @param request HttpServletRequest to validate * @param state IState The restored state for this url * @param target Part of the url that represents the target action * @return True if all required parameters are received. False in otherwise. */ private boolean allRequiredParametersReceived(HttpServletRequest request, IState state, String target) { Hashtable receivedParameters = new Hashtable(state.getRequiredParams()); String currentParameter = null; Enumeration requestParameters = request.getParameterNames(); while (requestParameters.hasMoreElements()) { currentParameter = (String) requestParameters.nextElement(); if (receivedParameters.containsKey(currentParameter)) { receivedParameters.remove(currentParameter); } // If multiple parameters are received, it is possible to pass this // verification without checking all the request parameters. if (receivedParameters.size() == 0) { return true; } } if (receivedParameters.size() > 0) { this.logger.log(HDIVErrorCodes.REQUIRED_PARAMETERS, target, receivedParameters.keySet().toString(), null); return false; } return true; }
From source file:edu.ku.brc.specify.utilapps.RegisterApp.java
/** * //from www .j a v a 2 s . c o m */ public void createStatsReport() { if (fullDescHash == null) { fullDescHash = rp.getAllDescPairsHash(); } String[] statsArray = { "num_co", "num_tx", "num_txu", "num_geo", "num_geou", "num_loc", "num_locgr", "num_preps", "num_prpcnt", "num_litho", "num_lithou", "num_gtp", "num_gtpu" }; StringBuilder sb = new StringBuilder(); sb.append("<html><head>\n<title>Statistics</title>\n"); sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + UIRegistry.getResourceString("CGI_BASE_URL") + "/css/report.css\">\n"); sb.append("</head><body>\n<div style=\"text-align: left;\"><img src=\"" + UIRegistry.getResourceString("CGI_BASE_URL") + "/images/logosmaller.png\" height=\"42\" width=\"117\"></div>\n"); sb.append("<center\n<table class=\"brd\" border=\"0\" cellspacing=\"0\">\n"); sb.append("<tr>"); sb.append("<th colspan=\"2\">"); sb.append("Statistics - All Collections"); sb.append("</th>"); sb.append("</tr>"); sb.append("<tr><th>Name</th><th>Total</th></tr>\n"); Collection<RegProcEntry> collEntries = rp.getCollectionsHash().values(); int[] values = new int[statsArray.length]; for (int i = 0; i < statsArray.length; i++) { values[i] = calcStat(sb, collEntries, statsArray[i], fullDescHash.get(statsArray[i]), null); } sb.append("</table>"); Hashtable<String, Boolean> dispHash = new Hashtable<String, Boolean>(); for (RegProcEntry entry : collEntries) { String disp = null; RegProcEntry parent = (RegProcEntry) entry.getParent(); if (parent != null) { disp = parent.getName(); if (disp != null) { dispHash.put(disp, true); } } } for (String disp : dispHash.keySet()) { DisciplineType discipline = DisciplineType.getDiscipline(disp); String dTitle = discipline != null ? discipline.getTitle() : disp; sb.append("<br><br><table class=\"brd\" border=\"0\" cellspacing=\"0\">\n"); sb.append("<tr>"); sb.append("<th colspan=\"2\">"); sb.append("Statistics for " + dTitle); sb.append("</th>"); sb.append("</tr>"); sb.append("<tr><th>Name</th><th>Total</th></tr>\n"); values = new int[statsArray.length]; for (int i = 0; i < statsArray.length; i++) { values[i] = calcStat(sb, collEntries, statsArray[i], fullDescHash.get(statsArray[i]), disp); } sb.append("</table>"); } //sb.append("<br><br>"); //createTable(sb, "No ISA Registrations", rp.getRoot(INCL_ANON).getKids(), false); sb.append("</center></body></html>"); try { File file = new File("stats.html"); FileUtils.writeStringToFile(file, sb.toString()); BrowserLauncher.openURL(file.toURI().toString()); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerXMLHelper.java
@Override public boolean createResourceFiles() { Hashtable<String, Boolean> localeHash = new Hashtable<String, Boolean>(); for (LocalizableContainerIFace table : tables) { checkForLocales(table, localeHash); for (LocalizableItemIFace f : table.getContainerItems()) { checkForLocales(f, localeHash); }// w w w. ja v a2 s . co m } for (String key : localeHash.keySet()) { String[] toks = StringUtils.split(key, '_'); String lang = toks[0]; String country = toks.length > 1 && StringUtils.isNotEmpty(toks[1]) ? toks[1] : ""; //System.out.println("["+key+"] "+lang+" "+country); File resFile = new File("db_resources" + (StringUtils.isNotEmpty(lang) ? ("_" + lang) : "") + (StringUtils.isNotEmpty(country) ? ("_" + country) : "") + ".properties"); try { PrintWriter pw = new PrintWriter(resFile); for (LocalizableContainerIFace table : tables) { printLocales(pw, null, table, lang, country); for (LocalizableItemIFace f : table.getContainerItems()) { printLocales(pw, table, f, lang, country); } } pw.close(); return true; } catch (IOException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SchemaLocalizerXMLHelper.class, ex); ex.printStackTrace(); } } return false; }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerXMLHelper.java
@Override public Vector<Locale> getLocalesInUse() { Hashtable<String, Boolean> localeHash = new Hashtable<String, Boolean>(); for (SpLocaleContainer container : tables) { checkForLocales(container, localeHash); for (LocalizableItemIFace f : container.getContainerItems()) { checkForLocales(f, localeHash); }//from w ww . j a v a2 s. com } Vector<Locale> inUseLocales = new Vector<Locale>(localeHash.keySet().size() + 10); for (String key : localeHash.keySet()) { String[] toks = StringUtils.split(key, "_"); inUseLocales.add(new Locale(toks[0], "", "")); } return inUseLocales; }
From source file:edu.stanford.epad.common.pixelmed.SegmentationObjectsFileWriter.java
/** * Moved common attributes from per-frame functional group to shared functional group. * //from ww w .j a v a 2s. c om * @param shared_group contains the attributes in SharedFunctionalGroup. * @param per_frame_sequence is the attribute sequence of PerFrameFunctionalGroup. * @throws DicomException */ private void combine_shared_attributes(AttributeList shared_group, SequenceAttribute per_frame_sequence) throws DicomException { // Check all the items in per_frame_sequence and move the common attributes to shared_group. //plane position sequence removed from check for slicer AttributeTag[] checked_attrs = new AttributeTag[] { TagFromName.SegmentIdentificationSequence/*, TagFromName.PlanePositionSequence*/ /* , TagFromName.StackID, TagFromName.PlaneOrientationSequence, TagFromName.SliceThickness, TagFromName.PixelSpacing */ }; Hashtable<AttributeTag, SequenceAttribute> common_attrs = get_common_attributes(checked_attrs, per_frame_sequence); add_attributes_to_shared_group(common_attrs, shared_group); remove_attributes_from_sequence(common_attrs.keySet(), per_frame_sequence); }