List of usage examples for java.util TreeMap entrySet
EntrySet entrySet
To view the source code for java.util TreeMap entrySet.
Click Source Link
From source file:org.apache.hadoop.hive.ql.exec.ExplainTask.java
@VisibleForTesting JSONObject outputMap(Map<?, ?> mp, boolean hasHeader, PrintStream out, boolean extended, boolean jsonOutput, int indent) throws Exception { TreeMap<Object, Object> tree = getBasictypeKeyedMap(mp); JSONObject json = jsonOutput ? new JSONObject(new LinkedHashMap<>()) : null; if (out != null && hasHeader && !mp.isEmpty()) { out.println();/*from w w w .j av a2 s .c om*/ } for (Entry<?, ?> ent : tree.entrySet()) { // Print the key if (out != null) { out.print(indentString(indent)); out.print(ent.getKey()); out.print(" "); } // Print the value if (isPrintable(ent.getValue())) { if (out != null) { out.print(ent.getValue()); out.println(); } if (jsonOutput) { json.put(ent.getKey().toString(), ent.getValue().toString()); } } else if (ent.getValue() instanceof List) { if (ent.getValue() != null && !((List<?>) ent.getValue()).isEmpty() && ((List<?>) ent.getValue()).get(0) != null && ((List<?>) ent.getValue()).get(0) instanceof TezWork.Dependency) { if (out != null) { boolean isFirst = true; for (TezWork.Dependency dep : (List<TezWork.Dependency>) ent.getValue()) { if (!isFirst) { out.print(", "); } else { out.print("<- "); isFirst = false; } out.print(dep.getName()); out.print(" ("); out.print(dep.getType()); out.print(")"); } out.println(); } if (jsonOutput) { for (TezWork.Dependency dep : (List<TezWork.Dependency>) ent.getValue()) { JSONObject jsonDep = new JSONObject(new LinkedHashMap<>()); jsonDep.put("parent", dep.getName()); jsonDep.put("type", dep.getType()); json.accumulate(ent.getKey().toString(), jsonDep); } } } else if (ent.getValue() != null && !((List<?>) ent.getValue()).isEmpty() && ((List<?>) ent.getValue()).get(0) != null && ((List<?>) ent.getValue()).get(0) instanceof SparkWork.Dependency) { if (out != null) { boolean isFirst = true; for (SparkWork.Dependency dep : (List<SparkWork.Dependency>) ent.getValue()) { if (!isFirst) { out.print(", "); } else { out.print("<- "); isFirst = false; } out.print(dep.getName()); out.print(" ("); out.print(dep.getShuffleType()); out.print(", "); out.print(dep.getNumPartitions()); out.print(")"); } out.println(); } if (jsonOutput) { for (SparkWork.Dependency dep : (List<SparkWork.Dependency>) ent.getValue()) { JSONObject jsonDep = new JSONObject(new LinkedHashMap<>()); jsonDep.put("parent", dep.getName()); jsonDep.put("type", dep.getShuffleType()); jsonDep.put("partitions", dep.getNumPartitions()); json.accumulate(ent.getKey().toString(), jsonDep); } } } else { if (out != null) { out.print(ent.getValue().toString()); out.println(); } if (jsonOutput) { json.put(ent.getKey().toString(), ent.getValue().toString()); } } } else if (ent.getValue() instanceof Map) { String stringValue = getBasictypeKeyedMap((Map) ent.getValue()).toString(); if (out != null) { out.print(stringValue); out.println(); } if (jsonOutput) { json.put(ent.getKey().toString(), stringValue); } } else if (ent.getValue() != null) { if (out != null) { out.println(); } JSONObject jsonOut = outputPlan(ent.getValue(), out, extended, jsonOutput, jsonOutput ? 0 : indent + 2); if (jsonOutput) { json.put(ent.getKey().toString(), jsonOut); } } else { if (out != null) { out.println(); } } } return jsonOutput ? json : null; }
From source file:com.l2jfree.sql.L2DatabaseInstaller.java
public static void check() throws SAXException, IOException, ParserConfigurationException { final TreeMap<String, String> tables = new TreeMap<String, String>(); final TreeMap<Double, String> updates = new TreeMap<Double, String>(); final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); // FIXME add validation factory.setIgnoringComments(true);//from ww w. ja v a 2s . c o m final List<Document> documents = new ArrayList<Document>(); InputStream is = null; try { // load default database schema from resources is = L2DatabaseInstaller.class.getResourceAsStream("database_schema.xml"); documents.add(factory.newDocumentBuilder().parse(is)); } finally { IOUtils.closeQuietly(is); } final File f = new File("./config/database_schema.xml"); // load optional project specific database tables/updates (fails on already existing) if (f.exists()) documents.add(factory.newDocumentBuilder().parse(f)); for (Document doc : documents) { for (Node n1 : L2XML.listNodesByNodeName(doc, "database")) { for (Node n2 : L2XML.listNodesByNodeName(n1, "table")) { final String name = L2XML.getAttribute(n2, "name"); final String definition = L2XML.getAttribute(n2, "definition"); final String oldDefinition = tables.put(name, definition); if (oldDefinition != null) throw new RuntimeException("Found multiple tables with name " + name + "!"); } for (Node n2 : L2XML.listNodesByNodeName(n1, "update")) { final Double revision = Double.valueOf(L2XML.getAttribute(n2, "revision")); final String query = L2XML.getAttribute(n2, "query"); final String oldQuery = updates.put(revision, query); if (oldQuery != null) throw new RuntimeException("Found multiple updates with revision " + revision + "!"); } } } createRevisionTable(); final double databaseRevision = getDatabaseRevision(); if (databaseRevision == -1) // no table exists { for (Entry<String, String> table : tables.entrySet()) { final String tableName = table.getKey(); final String tableDefinition = table.getValue(); installTable(tableName, tableDefinition); } if (updates.isEmpty()) insertRevision(0); else insertRevision(updates.lastKey()); } else // check for possibly required updates { for (Entry<String, String> table : tables.entrySet()) { final String tableName = table.getKey(); final String tableDefinition = table.getValue(); if (L2Database.tableExists(tableName)) continue; System.err.println("Table '" + tableName + "' is missing, so the server attempts to install it."); System.err.println("WARNING! It's highly recommended to check the results manually."); installTable(tableName, tableDefinition); } for (Entry<Double, String> update : updates.entrySet()) { final double updateRevision = update.getKey(); final String updateQuery = update.getValue(); if (updateRevision > databaseRevision) { executeUpdate(updateQuery); insertRevision(updateRevision); } } } }
From source file:com.wavemaker.runtime.ws.salesforce.SalesforceSupport.java
public List<List<Object>> runQuery(Map<String, Class<?>> types, Object... input) { executeQuery(types, "executeSforceQueryFromEditor", input); List<List<Object>> rtn = new ArrayList<List<Object>>(); TreeMap<Long, List<Object>> tmap = new TreeMap<Long, List<Object>>(); Set<Map.Entry<List<Object>, List<Tuple.Two<Long, Object>>>> entries = CastUtils .cast(this.resultRows.entrySet()); for (Map.Entry<List<Object>, List<Tuple.Two<Long, Object>>> entry : entries) { List<Tuple.Two<Long, Object>> list = entry.getValue(); tmap.put(list.get(0).v1, entry.getKey()); }//from ww w .j a v a2 s .c o m Set<Map.Entry<Long, List<Object>>> tmapEntries = tmap.entrySet(); for (Map.Entry<Long, List<Object>> entry : tmapEntries) { rtn.add(entry.getValue()); } return rtn; }
From source file:com.wavemaker.runtime.ws.salesforce.SalesforceSupport.java
public List<JSONObject> runNamedQuery(Map<String, Class<?>> types, Object... input) { executeQuery(types, "executeSforceQuery", input); List<JSONObject> rtn = new ArrayList<JSONObject>(); TreeMap<Long, List<Object>> tmap = new TreeMap<Long, List<Object>>(); Set<Map.Entry<List<Object>, List<Tuple.Two<Long, Object>>>> entries = CastUtils .cast(this.resultRows.entrySet()); for (Map.Entry<List<Object>, List<Tuple.Two<Long, Object>>> entry : entries) { List<Tuple.Two<Long, Object>> list = entry.getValue(); tmap.put(list.get(0).v1, entry.getKey()); }/*from ww w. j a v a2 s. c o m*/ Set<Map.Entry<Long, List<Object>>> tmapEntries = tmap.entrySet(); for (Map.Entry<Long, List<Object>> entry : tmapEntries) { rtn.add(this.resultJsonObjs.get(entry.getValue())); } return rtn; }
From source file:com.ichi2.async.DeckTask.java
private TaskData doInBackgroundConfSetSubdecks(TaskData... params) { Timber.d("doInBackgroundConfSetSubdecks"); Collection col = CollectionHelper.getInstance().getCol(mContext); Object[] data = params[0].getObjArray(); JSONObject deck = (JSONObject) data[0]; JSONObject conf = (JSONObject) data[1]; try {// w w w .ja v a 2 s .c om TreeMap<String, Long> children = col.getDecks().children(deck.getLong("id")); for (Map.Entry<String, Long> entry : children.entrySet()) { JSONObject child = col.getDecks().get(entry.getValue()); if (child.getInt("dyn") == 1) { continue; } TaskData newParams = new TaskData(new Object[] { child, conf }); boolean changed = doInBackgroundConfChange(newParams).getBoolean(); if (!changed) { return new TaskData(false); } } return new TaskData(true); } catch (JSONException e) { return new TaskData(false); } }
From source file:gemlite.shell.admin.dao.AdminDao.java
/** * region/*from www . j av a 2 s . c om*/ * * @return * @throws IOException */ private String showRegions() throws IOException { do { System.out.println("------------------------"); Map param = new HashMap(); param.put("beanName", "ListRegionsService"); Execution execution = FunctionService.onServer(clientPool).withArgs(param); ResultCollector rc = execution.execute("REMOTE_ADMIN_FUNCTION"); Object obj = rc.getResult(); if (obj == null) { System.out.println("can't get regions list"); return null; } ArrayList list = (ArrayList) obj; if (!(list.get(0) instanceof Set)) { System.out.println(list.get(0)); return null; } TreeSet regionSet = (TreeSet) list.get(0); Iterator regionIters = regionSet.iterator(); StringBuilder sb = new StringBuilder(); TreeMap<String, String> regionMap = new TreeMap<String, String>(); int no = 1; sb.append("NO.").append("\t").append("RegionName").append("\n"); while (regionIters.hasNext()) { String fullPath = (String) regionIters.next(); sb.append(no).append("\t").append(fullPath).append("\n"); regionMap.put(String.valueOf(no), fullPath); no++; } System.out.println(sb.toString()); System.out.println( "------------------------\nRegionNames,Your choice?No.or regionName,ALL(all) means export all regions,X to exit"); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); String line = bufferedReader.readLine(); if (line == null) { System.out.println("no input regionName!"); } else if (!"x".equalsIgnoreCase(line.trim()) && !regionMap.entrySet().contains(line.trim()) && !"ALL".equalsIgnoreCase(line.trim()) && !regionMap.keySet().contains(line.trim())) { System.out.println("error input:" + line); } else { if (regionMap.keySet().contains(line.trim())) return regionMap.get(String.valueOf(line.trim())); return line.trim(); } } while (true); }
From source file:org.openmicroscopy.shoola.agents.measurement.view.MeasurementViewerComponent.java
/** * Implemented as specified by the {@link MeasurementViewer} interface. * @see MeasurementViewer#setActiveChannels(Map) */// w w w .j ava2 s . c om public void setActiveChannels(Map activeChannels) { int state = model.getState(); switch (model.getState()) { case DISCARDED: case LOADING_DATA: throw new IllegalStateException( "This method cannot be " + "invoked in the DISCARDED, LOADING_DATA " + "state: " + state); } model.setActiveChannels(activeChannels); //Show or hide some shapes if they are visible on a channel or not TreeMap<Long, ROI> rois = model.getROI(); Collection<ROIFigure> figures = model.getAllFigures(); ROIFigure figure, f; ROI roi; TreeMap<Coord3D, ROIShape> shapeMap; ROIShape shape; Entry entry; if (rois != null) { Iterator j = rois.entrySet().iterator(); Iterator k; Coord3D coord; int c; while (j.hasNext()) { entry = (Entry) j.next(); roi = (ROI) entry.getValue(); shapeMap = roi.getShapes(); k = shapeMap.entrySet().iterator(); while (k.hasNext()) { entry = (Entry) k.next(); shape = (ROIShape) entry.getValue(); coord = shape.getCoord3D(); f = shape.getFigure(); c = coord.getChannel(); if (c >= 0) { if (f.canAnnotate()) { f.removeFigureListener(controller); f.setVisible(model.isChannelActive(c)); f.addFigureListener(controller); } } } } view.repaint(); } if (!view.inDataView() || !view.isVisible()) return; figures = getSelectedFigures(); if (figures.size() != 1) return; figure = figures.iterator().next(); List<ROIShape> shapeList = new ArrayList<ROIShape>(); roi = figure.getROI(); shapeMap = roi.getShapes(); Iterator j = shapeMap.entrySet().iterator(); while (j.hasNext()) { entry = (Entry) j.next(); shapeList.add((ROIShape) entry.getValue()); } if (shapeList.size() != 0) analyseShapeList(shapeList); }
From source file:ch.unil.genescore.pathway.GeneSetLibrary.java
License:asdf
/** get a weighted random sample; implementing Efraimidis et al. 2006 */ double[] getWeightedRandomSample(int setLength, double[] totSet, double[] totWeights) { //NaturalRanking ranker = new NaturalRanking(); double[] draws = new double[totWeights.length]; int[] ranks = new int[totWeights.length]; double[] out = new double[setLength]; TreeMap<Double, Integer> myRankTree = new TreeMap<Double, Integer>(); int treesize = 0; for (int i = 0; i < totWeights.length; i++) { draws[i] = Math.log(rand.nextDouble()) / totWeights[i]; if (treesize < setLength) { treesize++;//w w w . j a va2 s . com myRankTree.put(draws[i], i); } else if (treesize == setLength) if (myRankTree.firstKey() < draws[i]) { myRankTree.pollFirstEntry(); myRankTree.put(draws[i], i); } } Iterator<Entry<Double, Integer>> it = myRankTree.entrySet().iterator(); Entry<Double, Integer> ent; int count = 0; while (it.hasNext()) { ent = it.next(); ranks[count] = ent.getValue(); count++; //int rank = it.; } for (int i = 0; i < setLength; i++) { out[i] = totSet[ranks[i]]; } return out; }
From source file:org.kitodo.dataaccess.storage.memory.MemoryNode.java
/** * Pretty-prints this node into a StringBuilder. This method is called from * the toString function./*w w w . j a v a2s.com*/ * * @param out * StringBuilder to print to * @param indent * number of whitespaces to indent */ private void toStringRecursive(StringBuilder out, int indent) { String spc = new String(new char[indent]).replace("\0", " "); TreeMap<Long, Collection<ObjectType>> elements = new TreeMap<>(); TreeMap<String, Collection<ObjectType>> attributes = new TreeMap<>(); if (this instanceof IdentifiableNode) { out.append(spc); out.append('['); out.append(((IdentifiableNode) this).getIdentifier()); out.append("]\n"); } for (Entry<String, Collection<ObjectType>> e : edges.entrySet()) { Optional<Long> index = RDF.sequenceNumberOf(e.getKey()); if (index.isPresent()) { elements.put(index.get(), e.getValue()); } else { attributes.put(e.getKey(), e.getValue()); } } for (Entry<String, Collection<ObjectType>> x : attributes.entrySet()) { for (ObjectType y : x.getValue()) { out.append(spc); out.append(x.getKey()); if (y instanceof MemoryNode) { out.append(" {\n"); ((MemoryNode) y).toStringRecursive(out, indent + 2); out.append(spc); out.append("}\n"); } else { out.append(" = "); out.append(y.toString()); out.append('\n'); } } } for (Entry<Long, Collection<ObjectType>> x : elements.entrySet()) { for (ObjectType y : x.getValue()) { out.append(spc); out.append(RDF.toURL(x.getKey())); if (y instanceof MemoryNode) { out.append(" {\n"); ((MemoryNode) y).toStringRecursive(out, indent + 2); out.append(spc); out.append("}\n"); } else if (y instanceof IdentifiableNode) { out.append(" = "); out.append(((IdentifiableNode) y).getIdentifier()); out.append('\n'); } else { out.append(" = "); out.append(y.toString()); out.append('\n'); } } } }
From source file:com.indeed.lsmtree.core.TestImmutableBTreeIndex.java
public void testLargeKeys() throws IOException { final TreeMap<String, Long> map = Maps.newTreeMap(); final Random r = new Random(0); final String[] strings = new String[10000]; for (int i = 0; i < strings.length; i++) { final byte[] bytes = new byte[16384]; r.nextBytes(bytes);// w ww .j a va2s.c o m strings[i] = new String(Base64.encodeBase64(bytes)); } Arrays.sort(strings); Iterator<Generation.Entry<String, Long>> iterator = new AbstractIterator<Generation.Entry<String, Long>>() { int index = 0; @Override protected Generation.Entry<String, Long> computeNext() { if (index >= strings.length) return endOfData(); final String s = strings[index]; final long l = r.nextLong(); index++; map.put(s, l); return Generation.Entry.create(s, l); } }; ImmutableBTreeIndex.Writer.write(tmpDir, iterator, new StringSerializer(), new LongSerializer(), 65536, false); ImmutableBTreeIndex.Reader<String, Long> index = new ImmutableBTreeIndex.Reader<String, Long>(tmpDir, new StringSerializer(), new LongSerializer(), false); Iterator<Generation.Entry<String, Long>> it1 = index.iterator(); Iterator<Map.Entry<String, Long>> it2 = map.entrySet().iterator(); int i = 0; while (it2.hasNext()) { i++; assertTrue(it1.hasNext()); Generation.Entry<String, Long> next1 = it1.next(); Map.Entry<String, Long> next2 = it2.next(); assertEquals(next1.getKey(), next2.getKey()); assertEquals(next1.getValue(), next2.getValue()); } assertFalse(it1.hasNext()); }