List of usage examples for java.util TreeMap get
public V get(Object key)
From source file:au.org.ala.layers.web.TabulationService.java
private double[] speciesTotals(List<Tabulation> tabulations, boolean row) throws IOException { //determine x & y field names TreeMap<String, String> objects1 = new TreeMap<String, String>(); TreeMap<String, String> objects2 = new TreeMap<String, String>(); for (Tabulation t : tabulations) { objects1.put(t.getPid1(), t.getName1()); objects2.put(t.getPid2(), t.getName2()); }/* w ww.ja v a 2 s .co m*/ int rows = Math.max(objects1.size(), objects2.size()); int columns = Math.min(objects1.size(), objects2.size()); double[] grid = new double[row ? rows : columns]; //populate grid if (objects1.size() <= objects2.size()) { //row and column sort order and labels TreeMap<String, Integer> order1 = new TreeMap<String, Integer>(); TreeMap<String, Integer> order2 = new TreeMap<String, Integer>(); int pos = 0; for (String s : objects1.keySet()) { order1.put(s, pos++); } pos = 0; for (String s : objects2.keySet()) { order2.put(s, pos++); } //grid for (Tabulation t : tabulations) { //grid[order2.get(t.getPid2()) + 1][order1.get(t.getPid1()) + 1] = String.valueOf(t.getSpecies()); if (row) grid[order2.get(t.getPid2())] = t.getSpeciest2() == null ? 0 : t.getSpeciest2(); else grid[order1.get(t.getPid1())] = t.getSpeciest1() == null ? 0 : t.getSpeciest1(); } } else { //row and column sort order and labels TreeMap<String, Integer> order1 = new TreeMap<String, Integer>(); TreeMap<String, Integer> order2 = new TreeMap<String, Integer>(); int pos = 0; for (String s : objects1.keySet()) { order1.put(s, pos++); } pos = 0; for (String s : objects2.keySet()) { order2.put(s, pos++); } //grid for (Tabulation t : tabulations) { //grid[order1.get(t.getPid1()) + 1][order2.get(t.getPid2()) + 1] = String.valueOf(t.getSpecies()); if (!row) grid[order2.get(t.getPid2())] = t.getSpeciest2() == null ? 0 : t.getSpeciest2(); else grid[order1.get(t.getPid1())] = t.getSpeciest1() == null ? 0 : t.getSpeciest1(); } } return grid; }
From source file:IndexService.Indexer.java
private List<IRecord> getRecord(TreeMap<String, TreeSet<Integer>> indexresult, HashMap<String, Boolean> iscolumn, String indexids, int limit, int fieldnum) throws IOException { long time = System.currentTimeMillis(); List<IRecord> result = new ArrayList<IRecord>(); boolean returnallfields = false; String[] idxids;/* w w w .j a v a 2s . co m*/ ArrayList<Integer> idxs = new ArrayList<Integer>(); if (indexids == null) { returnallfields = true; idxids = new String[0]; } else { idxids = indexids.split(","); for (int i = 0; i < idxids.length; i++) { idxs.add(Integer.parseInt(idxids[i].trim())); } } int i = 0; label: for (String file : indexresult.keySet()) { if (!iscolumn.get(file)) { IFormatDataFile ifdf = new IFormatDataFile(conf); if (returnallfields) ifdf.open(file); else ifdf.open(file, idxs); for (Integer line : indexresult.get(file)) { if (limit >= 0 && i >= limit) { ifdf.close(); break label; } IRecord rec = ifdf.getByLine(line); result.add(rec); i++; } ifdf.close(); } else { IColumnDataFile icdf = new IColumnDataFile(conf); if (returnallfields) icdf.open(file); else icdf.open(file, idxs); for (Integer line : indexresult.get(file)) { if (limit >= 0 && i >= limit) { icdf.close(); break label; } IRecord rec = icdf.getByLine(line); result.add(rec); i++; } icdf.close(); } } System.out.println("getRecord time:\t" + (System.currentTimeMillis() - time) / 1000 + "s"); return result; }
From source file:com.sfs.whichdoctor.dao.RelationshipDAOImpl.java
/** * Returns a map of relationship names ordered by division -> type -> hierarchy. * * @param relationshipClass - the relationship class to search on * @param maximumHierarchy - the largest level of hierarchy to return * @return - A map of Division strings with a corresponding Map of supervisor * types and related hierarchies. * @throws WhichDoctorDaoException the which doctor dao exception *//*from w w w . j a v a2 s .c o m*/ public final TreeMap<String, TreeMap<String, Integer>> loadRelationships(final String relationshipClass, final int maximumHierarchy) throws WhichDoctorDaoException { dataLogger.info("Loading map of '" + relationshipClass + "' relationships types"); TreeMap<String, TreeMap<String, Integer>> supervisorMap = new TreeMap<String, TreeMap<String, Integer>>(); int max = maximumHierarchy + 1; Collection<RelationshipBean> relationships = loadSupervisors(relationshipClass); for (RelationshipBean rel : relationships) { if (rel.getHierarchy() > 0 && rel.getHierarchy() < max) { TreeMap<String, Integer> map = new TreeMap<String, Integer>(); if (supervisorMap.containsKey(rel.getDivision())) { map = supervisorMap.get(rel.getDivision()); } map.put(rel.getRelationshipType(), rel.getHierarchy()); supervisorMap.put(rel.getDivision(), map); } } return supervisorMap; }
From source file:org.squale.squaleweb.applicationlayer.action.export.ppt.AuditReportPPTData.java
/** * Create table of volumetry by profile/*from w w w . ja v a2 s. c o m*/ * * @param where place to add table * @param titles columns title * @param globalMap map getting informations to create table * @return table representing volumetry by profile */ private StringBuffer createVolByProfileTable(Rectangle where, List titles, TreeMap globalMap) { StringBuffer tableHtml = new StringBuffer("<html><body><table border='1'><tr>"); // first line: titles for (int i = 0; i < titles.size(); i++) { tableHtml.append("<td>" + (String) titles.get(i) + "</td>"); } tableHtml.append("</tr>"); // volumetry by profile for (Iterator profileIt = globalMap.keySet().iterator(); profileIt.hasNext();) { String curProfile = (String) profileIt.next(); // add cyan line for profile tableHtml.append("<tr bgcolor=\"#00FFFF\">"); tableHtml.append("<td colspan='" + titles.size() + "'>" + curProfile.toUpperCase() + "</td>"); tableHtml.append("</tr>"); // get tres TreeMap curTres = (TreeMap) globalMap.get(curProfile); for (Iterator tresIt = curTres.keySet().iterator(); tresIt.hasNext();) { tableHtml.append("<tr>"); String curTre = (String) tresIt.next(); tableHtml.append("<td>" + WebMessages.getString(request, curTre) + "</td>"); // get values for this tre ArrayList treLine = (ArrayList) curTres.get(curTre); int total = 0; for (int i = 0; i < treLine.size(); i++) { tableHtml.append("<td>" + (String) treLine.get(i) + "</td>"); try { total += Integer.parseInt((String) treLine.get(i)); } catch (NumberFormatException nfe) { // do nothing } } tableHtml.append("<td>" + total + "</td>"); tableHtml.append("</tr>"); } } tableHtml.append("</table></body></html>"); return tableHtml; }
From source file:com.clust4j.algo.HDBSCAN.java
protected static int[] getLabels(ArrayList<CompQuadTup<Integer, Integer, Double, Integer>> condensed, TreeMap<Integer, Double> stability) { double subTreeStability; ArrayList<Integer> clusters = new ArrayList<Integer>(); HSet<Integer> clusterSet; TreeMap<Integer, Integer> clusterMap = new TreeMap<>(), reverseClusterMap = new TreeMap<>(); // Get descending sorted key set ArrayList<Integer> nodeList = GetLabelUtils.descSortedKeySet(stability); // Get tuples where child size > 1 EntryPair<ArrayList<double[]>, Integer> entry = GetLabelUtils.childSizeGtOneAndMaxChild(condensed); ArrayList<double[]> clusterTree = entry.getKey(); // Map of nodes to whether it's a cluster TreeMap<Integer, Boolean> isCluster = GetLabelUtils.initNodeMap(nodeList); // Get num points //int numPoints = entry.getValue(); // Iter over nodes for (Integer node : nodeList) { subTreeStability = GetLabelUtils.subTreeStability(clusterTree, node, stability); if (subTreeStability > stability.get(node)) { isCluster.put(node, false);/*from ww w. j av a 2 s . c o m*/ stability.put(node, subTreeStability); } else { for (Integer subNode : GetLabelUtils.breadthFirstSearchFromClusterTree(clusterTree, node)) if (subNode.intValue() != node) isCluster.put(subNode, false); } } // Now add to clusters for (Map.Entry<Integer, Boolean> c : isCluster.entrySet()) if (c.getValue()) clusters.add(c.getKey()); clusterSet = new HSet<Integer>(clusters); // Build cluster map int n = 0; for (Integer clust : clusterSet) { clusterMap.put(clust, n); reverseClusterMap.put(n, clust); n++; } return doLabeling(condensed, clusters, clusterMap); }
From source file:com.sfs.whichdoctor.dao.WhichDoctorDAOImpl.java
/** * Load sibling beans./*from w w w .ja va 2 s . c o m*/ * * @param guid the guid * @param type the type * * @return the tree map< integer, collection< which doctor bean>> * * @throws WhichDoctorDaoException the whichdoctor dao exception */ @SuppressWarnings("unchecked") private TreeMap<Integer, Collection<WhichDoctorBean>> loadSiblingBeans(final int guid, final String type) throws WhichDoctorDaoException { dataLogger.info("Sibling history of GUID: " + guid + " requested"); String loadSQL = getSQL().getValue("whichdoctor/load/memo"); if (type.compareToIgnoreCase("membership") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/membership"); } if (type.compareToIgnoreCase("address") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/address"); } if (type.compareToIgnoreCase("phone") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/phone"); } if (type.compareToIgnoreCase("email") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/email"); } if (type.compareToIgnoreCase("specialty") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/specialty"); } if (type.compareToIgnoreCase("workshop") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/workshop"); } if (type.compareToIgnoreCase("rotation") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/rotationSibling"); } if (type.compareToIgnoreCase("project") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/project"); } if (type.compareToIgnoreCase("exam") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/exam"); } if (type.compareToIgnoreCase("qualification") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/qualification"); } if (type.compareToIgnoreCase("accreditation") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/accreditation"); } if (type.compareToIgnoreCase("assessment") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/assessment"); } if (type.compareToIgnoreCase("report") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/report"); } if (type.compareToIgnoreCase("expenseclaim") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/expenseClaim"); } if (type.compareToIgnoreCase("payment") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/payment"); } TreeMap<Integer, Collection<WhichDoctorBean>> siblings = new TreeMap<Integer, Collection<WhichDoctorBean>>(); try { Collection<WhichDoctorBean> siblingCollection = this.getJdbcTemplateReader().query(loadSQL, new Object[] { guid }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { WhichDoctorBean whichdoctorBean = loadHistory(rs); whichdoctorBean.setObjectType(type); return whichdoctorBean; } }); for (WhichDoctorBean whichdoctorBean : siblingCollection) { Collection<WhichDoctorBean> history = new ArrayList<WhichDoctorBean>(); if (siblings.containsKey(whichdoctorBean.getGUID())) { history = siblings.get(whichdoctorBean.getGUID()); } history.add(whichdoctorBean); siblings.put(whichdoctorBean.getGUID(), history); } } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } return siblings; }
From source file:com.clust4j.algo.HDBSCANTests.java
@Test public void testCondenseAndComputeStability() { double[][] slt = new double[][] { new double[] { 0.0, 2.0, 0.3, 2.0 }, new double[] { 3.0, 1.0, 0.6, 3.0 } }; ArrayList<CompQuadTup<Integer, Integer, Double, Integer>> h = HDBSCAN.LinkageTreeUtils.condenseTree(slt, 5); QuadTup<Integer, Integer, Double, Integer> q = h.get(0); assertTrue(q.getFirst() == 3);/*from w ww .j ava2 s . com*/ assertTrue(q.getSecond() == 0); // Three is a repeating decimal... assertTrue(q.getFourth() == 1); TreeMap<Integer, Double> computedStability = HDBSCAN.LinkageTreeUtils.computeStability(h); assertTrue(computedStability.size() == 1); assertTrue(computedStability.get(3) == 5); int[] labels = HDBSCAN.getLabels(h, computedStability); assertTrue(labels.length == 3); assertTrue(labels[0] == -1); assertTrue(labels[1] == -1); assertTrue(labels[2] == -1); }
From source file:hydrograph.ui.dataviewer.filter.FilterHelper.java
/** * Refresh group selections.// w ww.j a v a2 s .c om * * @param tableViewer * the table viewer * @param indexOfRow * the index of row * @param addOrDeleteRow * the add or delete row * @param groupSelectionMap * the group selection map * @return true, if successful */ public boolean refreshGroupSelections(TableViewer tableViewer, int indexOfRow, String addOrDeleteRow, TreeMap<Integer, List<List<Integer>>> groupSelectionMap) { boolean isRemoveColumn = false; for (int key : groupSelectionMap.keySet()) { List<List<Integer>> groups = groupSelectionMap.get(key); boolean isNewIndexAddedorRemoved = false; for (List<Integer> grp : groups) { List<Integer> tempGrp = new ArrayList<>(grp); if ("ADD".equalsIgnoreCase(addOrDeleteRow)) { for (int i = 0; i < grp.size(); i++) { if (grp.get(i) >= indexOfRow) { grp.set(i, grp.get(i) + 1); } } if (tempGrp.contains(indexOfRow)) { if (!isNewIndexAddedorRemoved && tempGrp.get(0) != indexOfRow) {//other than starting index then add row. grp.add(tempGrp.indexOf(indexOfRow), indexOfRow); isNewIndexAddedorRemoved = true; } } } else if ("DEL".equalsIgnoreCase(addOrDeleteRow)) { if (tempGrp.contains(indexOfRow)) { if (!isNewIndexAddedorRemoved) {//other than starting index then add row. grp.remove(grp.indexOf(indexOfRow)); if (grp.size() == 1) { grp.clear(); } if (rearrangeGroupsAfterDeleteRow(groupSelectionMap, grp) && groupSelectionMap.lastKey() != key) { grp.clear(); } List tempList = new ArrayList<>(); for (List lst : groupSelectionMap.get(key)) { tempList.addAll(lst); } if (tempList.isEmpty()) { isRemoveColumn = true; } } isNewIndexAddedorRemoved = true; } for (int i = 0; i < grp.size(); i++) { if (grp.get(i) >= indexOfRow) { grp.set(i, grp.get(i) - 1); } } } tempGrp.clear(); } } return isRemoveColumn; }
From source file:net.spfbl.core.Core.java
public static String getSequence(TreeMap<String, Boolean> map, String demiliter) { if (map == null) { return null; } else if (demiliter == null) { return null; } else if (map.isEmpty()) { return null; } else {/*from w w w .j a v a 2 s. c om*/ StringBuilder builder = new StringBuilder(); for (String key : map.keySet()) { boolean value = map.get(key); if (builder.length() > 0) { builder.append(demiliter); } builder.append(key); builder.append('='); builder.append(value); } return builder.toString(); } }
From source file:uk.ac.leeds.ccg.andyt.projects.moses.process.RegressionReport_UK1.java
public void writeOutResidualsISARHP_ISARCEP(File observed_File, File expected_File) throws Exception { File outputFile = new File(observed_File.getParentFile(), "residuals.csv"); FileOutputStream a_FileOutputStream = new FileOutputStream(outputFile); TreeMap<String, double[]> a_SAROptimistaionConstraints = loadCASOptimistaionConstraints(observed_File); TreeMap<String, double[]> a_CASOptimistaionConstraints = loadCASOptimistaionConstraints(expected_File); String line = OutputDataHandler_OptimisationConstraints.getISARHP_ISARCEPHeader(); String[] variableNames = line.split(","); a_FileOutputStream.write(line.getBytes()); a_FileOutputStream.write(StreamTokenizer.TT_EOL); a_FileOutputStream.flush();// w ww . j a v a2 s.co m String oa; double[] a_SARExpectedRow; double[] a_CASObservedRow; double[] a_Residual; Iterator<String> iterator_String = a_SAROptimistaionConstraints.keySet().iterator(); while (iterator_String.hasNext()) { oa = iterator_String.next(); line = oa + ","; a_SARExpectedRow = a_SAROptimistaionConstraints.get(oa); a_CASObservedRow = a_CASOptimistaionConstraints.get(oa); a_Residual = new double[a_SARExpectedRow.length]; for (int i = 0; i < a_SARExpectedRow.length; i++) { a_Residual[i] = a_SARExpectedRow[i] - a_CASObservedRow[i]; if (i == a_SARExpectedRow.length - 1) { line += a_Residual[i]; } else { line += a_Residual[i] + ","; } } a_FileOutputStream.write(line.getBytes()); a_FileOutputStream.write(StreamTokenizer.TT_EOL); a_FileOutputStream.flush(); } }