List of usage examples for java.util TreeMap keySet
public Set<K> keySet()
From source file:com.npower.dm.model.TestGenerateModelXMLByWurfl.java
public void testOutputXML() throws Exception { WurflSource source = new FileWurflSource( new File("D:\\zhao\\MyWorkspace\\nWave-DM-Common\\metadata\\wurfl\\wurfl.xml")); ObjectsManager om = ObjectsManager.newInstance(source); ListManager lm = om.getListManagerInstance(); TreeMap<String, WurflDevice> load = lm.getActualDeviceElementsList(); Set<String> sortedBrands = new TreeSet<String>(); sortedBrands.addAll(load.keySet()); Map<String, Set<String>> maps = new TreeMap<String, Set<String>>(); Map<String, String> brandNames = new TreeMap<String, String>(); for (String brand : sortedBrands) { // System.out.print("'"+key+"',"); WurflDevice wd = (WurflDevice) load.get(brand); System.out.print("'" + brand + "',"); System.out.print("'" + wd.getBrandName() + "',"); System.out.println("'" + wd.getModelName() + "'"); if (maps.get(wd.getBrandName().toLowerCase()) == null) { maps.put(wd.getBrandName().toLowerCase(), new TreeSet<String>()); }//from w ww. ja v a2 s . c o m maps.get(wd.getBrandName().toLowerCase()).add(wd.getModelName()); if (brandNames.get(wd.getBrandName().toLowerCase()) == null) { brandNames.put(wd.getBrandName().toLowerCase(), wd.getBrandName()); } } System.out.println(maps); //String outputBaseDir = "D:/Zhao/MyWorkspace/nWave-DM-Common/metadata/setup"; String outputBaseDir = "C:/temp/setup"; outputManufacturersXML(maps, brandNames, outputBaseDir); outputModelsXML(maps, brandNames, outputBaseDir); File setupFile = new File(outputBaseDir, "dmsetup.2nd.xml"); BufferedWriter out = new BufferedWriter(new FileWriter(setupFile)); out.write("<Setup>\n"); out.write(" <Name>OTAS DM Setup</Name>\n"); out.write(" <Description>OTAS DM Setup</Description>\n"); out.write(" <Properties>\n"); out.write(" <!-- Please customize the following properties -->\n"); out.write(" <Property key=\"jdbc.driver.class\"\n"); out.write(" value=\"oracle.jdbc.driver.OracleDriver\" />\n"); out.write(" <Property key=\"jdbc.url\"\n"); out.write(" value=\"jdbc:oracle:thin:@192.168.0.4:1521:orcl\" />\n"); out.write(" <Property key=\"jdbc.autoCommit\"\n"); out.write(" value=\"false\" />\n"); out.write(" <Property key=\"jdbc.super.user\"\n"); out.write(" value=\"system\" />\n"); out.write(" <Property key=\"jdbc.super.password\"\n"); out.write(" value=\"admin123\" />\n"); out.write(" <Property key=\"jdbc.dmuser.user\"\n"); out.write(" value=\"otasdm\" />\n"); out.write(" <Property key=\"jdbc.dmuser.password\"\n"); out.write(" value=\"otasdm\" />\n"); out.write(" \n"); out.write(" <!-- Do not modified the following properties -->\n"); out.write(" <!-- Database connection parameters -->\n"); out.write(" <Property key=\"hibernate.dialect\" value=\"org.hibernate.dialect.Oracle9Dialect\"/>\n"); out.write(" <Property key=\"hibernate.connection.driver_class\" value=\"${jdbc.driver.class}\"/>\n"); out.write(" <Property key=\"hibernate.connection.url\" value=\"${jdbc.url}\"/>\n"); out.write(" <Property key=\"hibernate.connection.username\" value=\"${jdbc.dmuser.user}\"/>\n"); out.write(" <Property key=\"hibernate.connection.password\" value=\"${jdbc.dmuser.password}\"/>\n"); out.write(" \n"); out.write(" <!-- Model library parameters -->\n"); out.write(" <Property key=\"model.default.icon.file\" value=\"./models/default_model.jpg\"/>\n"); out.write(" \n"); out.write(" </Properties>\n"); out.write(" \n"); out.write(" <Console class=\"com.npower.setup.console.ConsoleImpl\"></Console>\n"); out.write(" \n"); out.write(" <Tasks>\n"); out.write(" <!-- Step#9: Import Manufacturers and Models -->\n"); out.write(" <Task disable=\"false\">\n"); out.write(" <Name>Setup DM Manufacturers and Models (2nd stage)</Name>\n"); out.write(" <Description>Setup DM Manufacturers and Models (2nd stage)</Description>\n"); out.write("\n"); out.write(" <!-- Import Manufacturers -->\n"); out.write(" <Task class=\"com.npower.dm.setup.task.ManufacturerTask\">\n"); out.write(" <Name>Import Manufacturers</Name>\n"); out.write(" <Description>Import Manufacturers</Description>\n"); out.write(" <Properties>\n"); String files = ""; for (int i = 0; i < this.manufacturerFiles.size(); i++) { if (i < this.manufacturerFiles.size() - 1) { files += "./manufacturers/" + this.manufacturerFiles.get(i) + ",\n"; } else { files += "./manufacturers/" + this.manufacturerFiles.get(i) + "\n"; } } out.write(" <Property key=\"import.files\" value=\"" + files + "\" />\n"); out.write(" </Properties>\n"); out.write(" </Task>\n"); out.write(" \n"); for (int i = 0; i < this.modelFiles.size(); i++) { out.write(" <!-- Import " + this.modelNames.get(i) + " Models -->\n"); out.write(" <Task class=\"com.npower.dm.setup.task.ModelTask\">\n"); out.write(" <Name>Import " + this.modelNames.get(i) + " Models</Name>\n"); out.write(" <Description>Import " + this.modelNames.get(i) + " Models</Description>\n"); out.write(" <Properties>\n"); out.write(" <Property key=\"import.files\" value=\"" + this.modelFiles.get(i) + "\" />\n"); out.write(" </Properties>\n"); out.write(" </Task>\n"); out.write("\n"); } out.write(" </Task>\n"); out.write(" </Tasks>\n"); out.write("</Setup>\n"); out.close(); }
From source file:pl.otros.logview.api.gui.LogDataTableModel.java
public void restoreFromMemento(Memento memento) { logDataStore.clear();/*from w w w . j a va 2 s. c o m*/ logDataStore.setLimit(memento.dataLimit); logDataStore.add(memento.list.toArray(new LogData[memento.list.size()])); TreeMap<Integer, MarkerColors> marksColor = memento.getMarksColor(); for (Integer row : marksColor.keySet()) { logDataStore.markRows(marksColor.get(row), row); } logDataStore.clearNotes(); for (Integer row : memento.notes.keySet()) { logDataStore.addNoteToRow(row, memento.notes.get(row)); } fireTableDataChanged(); }
From source file:com.sfs.whichdoctor.importer.Importer.java
/** * Process data./*from w w w . j a va2 s . c om*/ * * @param type the type * @param data the data * @param columns the columns * @param applicationContext the application context * * @throws IOException Signals that an I/O exception has occurred. */ public final void processData(final String type, final TreeMap<Integer, TreeMap<Integer, String>> data, final TreeMap<Integer, String> columns, final ApplicationContext applicationContext) throws IOException { HashMap<String, List<String>> dataMap = new HashMap<String, List<String>>(); if (data != null && columns != null) { // Iterate through the columns assigning values to the dataMap for (Integer columnNumber : columns.keySet()) { String columnField = columns.get(columnNumber); if (StringUtils.isNotBlank(columnField)) { // The column has been associated to some data ArrayList<String> dataValues = new ArrayList<String>(); for (Integer rowNumber : data.keySet()) { TreeMap<Integer, String> rowData = data.get(rowNumber); if (rowData.containsKey(columnNumber)) { // Get the value of the column and add it array String dataField = rowData.get(columnNumber); dataValues.add(dataField); } } // Add the data name and array to the dataMap dataMap.put(columnField, dataValues); } } // Store the completed dataMap setDataMap(dataMap); } // Take the dataMap and load the relevant objects into the bean map if (StringUtils.equalsIgnoreCase(type, "exam")) { importLogger.debug("Processing exam import"); try { ExamImporter examImporter = new ExamImporter(); examImporter.setDataMap(getDataMap()); /* Process the data map and turn it into a bean map */ final PersonDAO personDAO = (PersonDAO) applicationContext.getBean("personDAO"); setBeanMap(examImporter.assignData(personDAO)); setDescriptionMap(examImporter.getDescriptionMap()); setImportMessage(examImporter.getImportMessage()); } catch (Exception e) { importLogger.error("Error processing exam import: " + e.getMessage()); throw new IOException("Error processing exam import: " + e.getMessage()); } } }
From source file:edu.utexas.cs.tactex.subscriptionspredictors.LWRCustOldAppache.java
/** * @param candidateEval// ww w . j av a 2 s . c o m * @param e2n * @return */ @Override public Double predictNumSubs(double candidateEval, TreeMap<Double, Double> e2n, CustomerInfo customer, int timeslot) { // tree map guarantees that keys are unique // so we are suppose to be able to run LWR // if there are at least 3 entries (even 2) // LWR, run n-fold cross validation with different bandwidth double min = e2n.firstKey(); double max = e2n.lastKey(); ArrayRealVector xVec = createNormalizedXVector(e2n.keySet(), min, max); ArrayRealVector yVec = createYVector(e2n.values()); double bestTau = Double.MAX_VALUE; double bestMSE = Double.MAX_VALUE; ArrayList<Double> candidateTaus = new ArrayList<Double>(); //candidateTaus.add(0.025 * SQUEEZE); candidateTaus.add(0.05);// * SQUEEZE); candidateTaus.add(0.1);// * SQUEEZE); candidateTaus.add(0.2);// * SQUEEZE); candidateTaus.add(0.3);// * SQUEEZE); candidateTaus.add(0.4);// * SQUEEZE); candidateTaus.add(0.5);// * SQUEEZE); candidateTaus.add(0.6);// * SQUEEZE); candidateTaus.add(0.7);// * SQUEEZE); candidateTaus.add(0.8);// * SQUEEZE); candidateTaus.add(0.9);// * SQUEEZE); candidateTaus.add(1.0);// * SQUEEZE); for (Double tau : candidateTaus) { Double mse = CrossValidationError(tau, xVec, yVec); if (null == mse) { log.error(" cp cross-validation failed, return null"); return null; } if (mse < bestMSE) { bestMSE = mse; bestTau = tau; } } log.info(" cp LWR bestTau " + bestTau); double x0 = candidateEval; Double prediction = LWRPredict(xVec, yVec, normalizeX(x0, min, max), bestTau); if (null == prediction) { log.error("LWR passed CV but cannot predict on new point. falling back to interpolateOrNN()"); log.error("e2n: " + e2n.toString()); log.error("candidateEval " + candidateEval); return null; } // cast to int, and cannot be negative return Math.max(0, (double) (int) (double) prediction); }
From source file:com.sfs.whichdoctor.analysis.GroupAnalysisDAOImpl.java
/** * Analyse a set of groups./*from www . ja v a2 s. co m*/ * * @param groups the groups * @param loadDetails the load details * @param user the user * * @return the group analysis bean * * @throws WhichDoctorAnalysisDaoException the which doctor analysis dao * exception */ public final GroupAnalysisBean analyse(final Collection<Integer> groups, final BuilderBean loadDetails, final UserBean user) throws WhichDoctorAnalysisDaoException { GroupAnalysisBean groupAnalysis = new GroupAnalysisBean(); Collection<Object> variables = new ArrayList<Object>(); for (Integer groupGUID : groups) { dataLogger.debug("Analyising Group GUID: " + groupGUID); variables.add(groupGUID); } dataLogger.debug("Group variables size: " + variables.size()); if (variables.size() == 0) { dataLogger.error("Cannot perform group analysis with no groups"); throw new WhichDoctorAnalysisDaoException("Cannot perform group analysis with no groups"); } SearchBean search = this.searchDAO.initiate("group", user); search.setSearchArray(variables, "Group GUIDs"); search.setLimit(0); try { BuilderBean groupDetails = new BuilderBean(); groupDetails.setParameter("ITEMS", true); SearchResultsBean results = this.searchDAO.search(search, groupDetails); Collection<Object> searchResults = results.getSearchResults(); if (searchResults != null) { for (Object group : searchResults) { groupAnalysis.addGroup((GroupBean) group); } } } catch (Exception e) { dataLogger.error("Error performing Group Analysis search: " + e.getMessage()); } /* Iterate through each group's itembeans, adding them to the item map */ for (Integer groupGUID : groupAnalysis.getGroups().keySet()) { GroupBean group = groupAnalysis.getGroups().get(groupGUID); TreeMap<String, ItemBean> items = group.getItems(); if (items != null) { for (String key : items.keySet()) { ItemBean item = items.get(key); groupAnalysis.addReferenceGUID(item.getObject2GUID(), group.getGUID()); } } } /* * Build the CombinedGroup map using the groupGUID and referenceGUID * maps */ for (Integer referenceGUID : groupAnalysis.getReferenceGUIDs().keySet()) { ArrayList<Integer> groupGUIDs = groupAnalysis.getReferenceGUIDs().get(referenceGUID); groupAnalysis.addCombinedGroup(referenceGUID, groupGUIDs); } /* * With the referenceGUIDs/groupGUIDs organised load the referenceGUID * objects */ try { groupAnalysis.setReferenceObjects(loadReferenceObjects(groupAnalysis.getReferenceGUIDs(), loadDetails, user, groupAnalysis.getGroupClass())); } catch (Exception e) { dataLogger.error("Error loading reference objects: " + e.getMessage()); } /* With the objects loaded build the order map */ groupAnalysis .setReferenceOrder(buildOrder(groupAnalysis.getReferenceObjects(), groupAnalysis.getGroupClass())); return groupAnalysis; }
From source file:org.pentaho.di.baserver.utils.inspector.InspectorTest.java
@Test public void testGetModuleNames() throws Exception { TreeMap<String, TreeMap<String, LinkedList<Endpoint>>> endpoints = null; doReturn(endpoints).when(inspectorSpy).getEndpointsTree(); assertEquals(inspectorSpy.getModuleNames(), Collections.emptyList()); endpoints = new TreeMap<String, TreeMap<String, LinkedList<Endpoint>>>(); doReturn(endpoints).when(inspectorSpy).getEndpointsTree(); assertEquals(inspectorSpy.getModuleNames(), endpoints.keySet()); }
From source file:eu.sisob.uma.crawler.AirResearchersWebPagesExtractor.java
/** * In this block the crawler will try to extract the departments web adresses. * The block works with a org.dom4j.Element * Notes:// ww w . j a va2 s .com * The function iterate the institution elemento taking all the UNIT_OF_ASSESSMENT to search all of them in same crawler call. * The UNIT_OF_ASSESSMENT will be stores in subjects array, next, it will be given to the crawler. * * @param elementInstitution * @param path * @param sInstitutionName * @param sWebAddress * @return */ @Override protected boolean actionsInInstitutionNode(org.dom4j.Element elementInstitution, String path, String sInstitutionName, String sWebAddress) { if (refuseExecution) return false; String crawler_data_folder = this.work_dir.getAbsolutePath() + File.separator + CRAWLER_DATA_FOLDERNAME; List<String> subjects = new ArrayList<String>(); String sSeed = sWebAddress; String sContainPattern = sSeed.replace("http://www.", ""); int index = sContainPattern.indexOf("/"); if (index == -1) index = sContainPattern.length() - 1; sContainPattern = sContainPattern.substring(0, index); ProjectLogger.LOGGER.info("Department phase - " + sInstitutionName); /* * Taking subjects to search its web adresses */ String sUnitOfAssessment_Description = ""; for (Iterator<org.dom4j.Element> i2 = elementInstitution.elementIterator(XMLTags.UNIT_OF_ASSESSMENT); i2 .hasNext();) { sUnitOfAssessment_Description = i2.next().element(XMLTags.UNIT_OF_ASSESSMENT_DESCRIPTION).getText(); subjects.add(sUnitOfAssessment_Description); ProjectLogger.LOGGER.info( "\tAdding subject '" + sUnitOfAssessment_Description + "' to search its section webpages"); } /* * Crawling to search the departments */ CrawlerDepartamentsV3Controller controllerDepts = null; try { String university_crawler_data_folder = crawler_data_folder + File.separator + sInstitutionName.replaceAll("\\W+", "").toLowerCase() + "-crawler-data"; File university_crawler_data_dir = new File(university_crawler_data_folder); if (university_crawler_data_dir.exists()) FileFootils.deleteDir(university_crawler_data_dir); controllerDepts = new CrawlerDepartamentsV3Controller(university_crawler_data_folder, this.keywords_data_dir, subjects); controllerDepts.addSeed(sSeed); controllerDepts.setPolitenessDelay(200); controllerDepts.setMaximumCrawlDepth(3); controllerDepts.setMaximumPagesToFetch(-1); controllerDepts.setContainPattern(sContainPattern); controllerDepts.clearPossibleResults(); ProjectLogger.LOGGER .info("Begin crawling: " + sInstitutionName + " (" + sWebAddress + ") - [" + sSeed + "]"); long lTimerAux = java.lang.System.currentTimeMillis(); controllerDepts.start(CrawlerDepartamentsV3.class, 1); lTimerAux = java.lang.System.currentTimeMillis() - lTimerAux; ProjectLogger.LOGGER .info("End crawling: " + sInstitutionName + " - Time: " + lTimerAux + " ms - [" + sSeed + "]"); } catch (Exception ex) { ProjectLogger.LOGGER.error(ex.getMessage(), ex); } finally { if (CrawlerTrace.isTraceUrlsActive() && controllerDepts != null) controllerDepts.closeCrawlerTrace(); controllerDepts.releaseResources(); } /* * Update results */ if (controllerDepts != null) { if (CrawlerTrace.isTraceSearchActive()) { CandidateTypeURL.printResults("Results of: " + sInstitutionName + " (" + sWebAddress + ") by TYPE", controllerDepts.getPossibleResultsTYPE()); } /* * Adding departments web addresses to xml document */ for (Iterator<org.dom4j.Element> i2 = elementInstitution.elementIterator(XMLTags.UNIT_OF_ASSESSMENT); i2 .hasNext();) { org.dom4j.Element e2 = i2.next(); sUnitOfAssessment_Description = e2.element(XMLTags.UNIT_OF_ASSESSMENT_DESCRIPTION).getText(); TreeMap<String, List<CandidateTypeURL>> t = controllerDepts.getPossibleResultsTYPE(); Iterator<String> it = t.keySet().iterator(); // String department_of = CrawlerDepartamentsV3Controller.DEPARTMENT_OF_RESULT_TAG + sUnitOfAssessment_Description; //FIXME, TEST THIS //while(it.hasNext()) //{ // String department_of = it.next(); // if(department_of.toLowerCase().equals(CrawlerDepartamentsV3Controller.DEPARTMENT_OF_RESULT_TAG + sUnitOfAssessment_Description.toLowerCase())) // { List<CandidateTypeURL> lst = t.get(department_of); if (lst != null) { for (CandidateTypeURL ss : lst) { ProjectLogger.LOGGER .info("Add department '" + department_of + "' the url '" + ss.sURL + "'"); e2.addElement(XMLTags.DEPARTMENT_WEB_ADDRESS).addText(ss.sURL); } } // break; // } //} } } return true; }
From source file:mrmc.chart.ROCCurvePlot.java
/** * Creates an ROC curve that averages together the scores for all readers in * the diagonal direction/*from w w w .ja va 2 s .c o m*/ * * @param treeMap Mapping of readers to points defining a curve * @return Series containing the ROC curve points */ private XYSeries generateDiagonalROC(TreeMap<String, TreeSet<XYPair>> treeMap) { XYSeries diagAvg = new XYSeries("Diagonal Average", false); TreeMap<String, TreeSet<XYPair>> rotatedData = new TreeMap<String, TreeSet<XYPair>>(); // rotate all points in data 45 degrees clockwise about origin for (String r : treeMap.keySet()) { rotatedData.put(r, new TreeSet<XYPair>()); for (XYPair point : treeMap.get(r)) { double x2 = (point.x + point.y) / Math.sqrt(2.0); double y2 = (point.y - point.x) / Math.sqrt(2.0); rotatedData.get(r).add(new XYPair(x2, y2)); } } // generate linear interpolation with new points ArrayList<InterpolatedLine> rotatedLines = new ArrayList<InterpolatedLine>(); for (String r : rotatedData.keySet()) { rotatedLines.add(new InterpolatedLine(rotatedData.get(r))); } // take vertical sample averages from x = 0 to x = 1 for (double i = 0; i <= Math.sqrt(2); i += 0.01) { double avg = 0; int counter = 0; for (InterpolatedLine line : rotatedLines) { avg += line.getYatDiag(i); counter++; } // rotate points back 45 degrees counterclockwise double x1 = i; double y1 = (avg / (double) counter); double x2 = (x1 * Math.cos(Math.toRadians(45))) - (y1 * Math.sin(Math.toRadians(45))); double y2 = (x1 * Math.sin(Math.toRadians(45))) + (y1 * Math.cos(Math.toRadians(45))); diagAvg.add(x2, y2); } diagAvg.add(1, 1); return diagAvg; }
From source file:uk.ac.leeds.ccg.andyt.projects.moses.process.RegressionReport_UK1.java
protected static Object[] loadDataHSARHP_ISARCEP(File a_SARFile, File a_CASFile) throws IOException { Object[] result = new Object[3]; TreeMap<String, double[]> a_SAROptimistaionConstraints = loadCASOptimistaionConstraints(a_SARFile); TreeMap<String, double[]> a_CASOptimistaionConstraints = loadCASOptimistaionConstraints(a_CASFile); Vector<String> variables = GeneticAlgorithm_HSARHP_ISARCEP.getVariableList(); variables.add(0, "Zone_Code"); String[] variableNames = new String[0]; variableNames = variables.toArray(variableNames); result[0] = variableNames;/* ww w . jav a2 s .c om*/ // Format (Flip) data double[][] a_SARExpectedData = new double[variables.size() - 1][a_SAROptimistaionConstraints.size()]; double[][] a_CASObservedData = new double[variables.size() - 1][a_SAROptimistaionConstraints.size()]; String oa; double[] a_SARExpectedRow; double[] a_CASObservedRow; int j = 0; Iterator<String> iterator_String = a_SAROptimistaionConstraints.keySet().iterator(); while (iterator_String.hasNext()) { oa = iterator_String.next(); a_SARExpectedRow = a_SAROptimistaionConstraints.get(oa); a_CASObservedRow = a_CASOptimistaionConstraints.get(oa); // if (oa.equalsIgnoreCase("00AAFQ0013")){ // System.out.println(oa); // } if (a_SARExpectedRow == null) { System.out.println( "Warning a_SARExpectedRow == null in loadDataHSARHP_ISARCEP(File,File) for OA " + oa); } else { if (a_CASObservedRow == null) { System.out.println( "Warning a_SARExpectedRow == null in loadDataHSARHP_ISARCEP(File,File) for OA " + oa); } else { for (int i = 0; i < variables.size() - 1; i++) { a_SARExpectedData[i][j] = a_SARExpectedRow[i]; a_CASObservedData[i][j] = a_CASObservedRow[i]; } } } j++; } result[1] = a_SARExpectedData; result[2] = a_CASObservedData; return result; }
From source file:org.motechproject.mobile.omi.manager.SMSMessageFormatter.java
private String formatDefaulterMessage(TreeMap<String, List<String>> defaulters) { String message = ""; if (defaulters == null || defaulters.isEmpty()) { return "\nNo defaulters found for this clinic"; }/*www .ja va 2s. com*/ TreeSet<String> keys = new TreeSet<String>(defaulters.keySet()); for (String p : keys) { List<String> defaultedCareList = defaulters.get(p); if (defaultedCareList == null || defaultedCareList.isEmpty()) { continue; } String defaultedCare = StringUtils.join(defaultedCareList.toArray(), ","); message += String.format("\n%s (%s)", p, defaultedCare); } return message; }