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.kalypso.gml.ui.internal.coverage.CoverageColormapHandler.java
private static List<PolygonColorMapEntry> translateColormap( final TreeMap<Double, ColorMapEntry> newRasterColorMap) { /* Translate raster colormap to polygon colormap with same classification */ final List<PolygonColorMapEntry> newPolygonColorMap = new ArrayList<>(newRasterColorMap.size()); Entry<Double, ColorMapEntry> lastEntry = null; for (final Entry<Double, ColorMapEntry> entry : newRasterColorMap.entrySet()) { if (lastEntry != null) { final ColorMapEntry value = entry.getValue(); final Color color = value.getColorAndOpacity(); final BigDecimal fromValue = new BigDecimal(lastEntry.getValue().getQuantity()); final BigDecimal toValue = new BigDecimal(entry.getValue().getQuantity()); final PolygonColorMapEntry newEntry = StyleFactory.createPolygonColorMapEntry(color, color, fromValue, toValue); // REMARK: always use width '2': hides ugly artifacts in map (because fill and outline do not exactly match). newEntry.getStroke().setWidth(2); // TODO: use should decide if triangles are visible (no stroke, faster), or hidden (stroke with same color), // slower. newPolygonColorMap.add(newEntry); }//from ww w.ja v a2s .co m lastEntry = entry; } return newPolygonColorMap; }
From source file:com.data2semantics.yasgui.server.db.ConnectionFactory.java
private static void applyDeltas(Connection connect, File configDir) throws UnsupportedEncodingException, IOException, SQLException { @SuppressWarnings("unchecked") ArrayList<File> listFiles = new ArrayList<File>( FileUtils.listFiles(new File(configDir.getAbsolutePath() + "/config"), FileFilterUtils.prefixFileFilter("delta_"), null)); TreeMap<Integer, File> files = new TreeMap<Integer, File>(); for (File file : listFiles) { String basename = file.getName(); basename = basename.substring("delta_".length()); basename = basename.substring(0, basename.length() - ".sql".length()); int index = Integer.parseInt(basename); files.put(index, file);/*from w ww . jav a 2 s . com*/ } ArrayList<Integer> currentDeltas = getDeltas(connect); //treemap is naturally sorted, so just iterate through them for (Entry<Integer, File> entry : files.entrySet()) { if (!currentDeltas.contains(entry.getKey())) { ScriptRunner runner = new ScriptRunner(connect, false, true); FileInputStream fileStream = new FileInputStream(entry.getValue()); runner.runScript(new BufferedReader(new InputStreamReader(fileStream, "UTF-8"))); fileStream.close(); setDeltaApplied(connect, entry.getKey()); } } }
From source file:org.mycore.frontend.cli.MCRBasicCommands.java
/** * Shows the help text for one or more commands. * * @param pattern/* w ww .jav a2 s .c o m*/ * the command, or a fragment of it */ @MCRCommand(syntax = "help {0}", help = "Show the help text for the commands beginning with {0}.", order = 10) public static void listKnownCommandsBeginningWithPrefix(String pattern) { TreeMap<String, List<org.mycore.frontend.cli.MCRCommand>> matchingCommands = MCRCommandManager .getKnownCommands().entrySet().stream() .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().stream().filter( cmd -> cmd.getSyntax().contains(pattern) || cmd.getHelpText().contains(pattern)) .collect(Collectors.toList()), (k, v) -> k, TreeMap::new)); matchingCommands.entrySet().removeIf(e -> e.getValue().isEmpty()); if (matchingCommands.isEmpty()) { MCRCommandLineInterface.output("Unknown command:" + pattern); } else { MCRCommandLineInterface.output(""); matchingCommands.forEach((grp, cmds) -> { outputGroup(grp); cmds.forEach(org.mycore.frontend.cli.MCRCommand::outputHelp); }); } }
From source file:module.entities.NameFinder.DB.java
public static void saveClusterAnnotatedDocuments(TreeMap<Integer, String> docs) throws SQLException { String insertSQL = "INSERT INTO assignments_herc (annotator_id,text_id,json_out) VALUES (-1,?,?)"; PreparedStatement stmt = connection.prepareStatement(insertSQL); for (Map.Entry<Integer, String> pair : docs.entrySet()) { stmt.setInt(1, pair.getKey());/*ww w .j ava 2 s. co m*/ stmt.setString(2, pair.getValue()); stmt.addBatch(); } stmt.executeBatch(); }
From source file:com.sshtools.common.vomanagementtool.common.VOHelper.java
private static String createStringFromTreeMap(TreeMap treemap) { String content = ""; Iterator<Map.Entry<String, TreeMap>> entries = treemap.entrySet().iterator(); while (entries.hasNext()) { Map.Entry<String, TreeMap> entry = entries.next(); String vonameinMap = entry.getKey(); List voDetails = (List) entry.getValue(); for (int i = 0; i < voDetails.size(); i++) { TreeMap details = (TreeMap) voDetails.get(i); String server = (String) details.get("server"); String port = (String) details.get("port"); String dn = (String) details.get("dn"); String servervoname = (String) details.get("servervoname"); String lscString = "\"" + vonameinMap + "\"" + " \"" + server + "\"" + " \"" + port + "\"" + " \"" + dn + "\"" + " \"" + servervoname + "\""; content += lscString + "\n"; }// w w w. java 2 s.c o m } return content; }
From source file:com.sshtools.common.vomanagementtool.common.VOHelper.java
public static boolean removeVOFromFavourites(String voName) { boolean isRemoved = false; TreeMap allFavVOs = getVOGroup(FAVOURITES); Iterator<Map.Entry<String, TreeMap>> entries = allFavVOs.entrySet().iterator(); while (entries.hasNext()) { Map.Entry<String, TreeMap> entry = entries.next(); String vonameinMap = entry.getKey(); if (voName.equals(vonameinMap)) { //Check also if it is a self-VO, if yes, need to remove folders too TreeMap allEGIVOs = getVOGroup(EGI); TreeMap allOTHERSVO = getVOGroup(OTHERS); if (!allEGIVOs.containsKey(voName) && !allOTHERSVO.containsKey(voName)) { try { delete(new File(vomsdir + File.separator + voName)); } catch (IOException e) { JOptionPane.showMessageDialog(null, "Cannot remove dirctory '" + vomsdir + File.separator + voName + "'.", "Error: Remove VO from " + FAVOURITES, JOptionPane.ERROR_MESSAGE); }//from w ww. j av a 2 s .c o m } allFavVOs.remove(vonameinMap); isRemoved = true; break; } } if (isRemoved) { String newContent = createStringFromTreeMap(allFavVOs); try { writeToFile(favouritesFile, newContent); } catch (IOException e) { isRemoved = false; JOptionPane.showMessageDialog(null, "Failed to remove VO from Favourites. Cannot write to file '" + favouritesFile + "'", "Error: Remove VO", JOptionPane.ERROR_MESSAGE); } } return isRemoved; }
From source file:org.esxx.Response.java
static private Object jsToCSV(ContentType ct, Scriptable object) throws IOException { Context cx = Context.getCurrentContext(); String separator = Parsers.getParameter(ct, "x-separator", ","); String quote = Parsers.getParameter(ct, "x-quote", "\""); String escape = Parsers.getParameter(ct, "x-escape", "\""); if ("none".equals(separator)) separator = ""; if ("none".equals(quote)) quote = ""; if ("none".equals(escape)) escape = ""; if (separator.length() > 1 || quote.length() > 1 || escape.length() > 1) { throw new IOException( "x-separator, x-quote and x-escape values must be " + "empty or a single character"); }/*w w w. jav a2s .co m*/ KeyValueWrapper rows = new KeyValueWrapper(object); TreeMap<String, Integer> columns = new TreeMap<String, Integer>(); // Find all possible colunms for (Object r : rows.getValues(cx)) { KeyValueWrapper row = new KeyValueWrapper(r); for (Object c : row.getKeys()) { columns.put(StringUtil.toSortable(c), null); } } // "Sort" them int cnt = 0; for (Map.Entry<String, Integer> e : columns.entrySet()) { e.setValue(cnt++); } // Write lines StringWriter sw = new StringWriter(); CSVWriter csv = new CSVWriter(sw, separator.isEmpty() ? '\0' : separator.charAt(0), quote.isEmpty() ? '\0' : quote.charAt(0), escape.isEmpty() ? '\0' : escape.charAt(0)); Object headers = rows.getValue(cx, "headers"); if (headers != Context.getUndefinedValue()) { writeCSVRow(cx, csv, columns, headers); } for (Object k : rows.getKeys()) { if (!"headers".equals(k.toString())) { writeCSVRow(cx, csv, columns, rows.getValue(cx, k)); } } return sw.toString(); }
From source file:com.act.lcms.db.model.StandardIonResult.java
private static LinkedHashMap<String, XZ> deserializeStandardIonAnalysisResult(String jsonEntry) throws IOException { // We have to re-sorted the deserialized results so that we meet the contract expected by the caller. Map<String, XZ> deserializedResult = OBJECT_MAPPER.readValue(jsonEntry, typeRefForStandardIonAnalysis); TreeMap<Double, String> sortedIntensityToIon = new TreeMap<>(Collections.reverseOrder()); for (Map.Entry<String, XZ> val : deserializedResult.entrySet()) { sortedIntensityToIon.put(val.getValue().getIntensity(), val.getKey()); }// w w w. ja v a 2 s.c o m LinkedHashMap<String, XZ> sortedResult = new LinkedHashMap<>(); for (Map.Entry<Double, String> val : sortedIntensityToIon.entrySet()) { String ion = val.getValue(); sortedResult.put(ion, deserializedResult.get(ion)); } return sortedResult; }
From source file:net.sf.keystore_explorer.crypto.signing.MidletSigner.java
/** * Sign a JAD file outputting the modified JAD to a different file. * * @param jadFile//from w w w . ja va 2s.c o m * JAD file * @param outputJadFile * Output JAD file * @param jarFile * JAR file * @param privateKey * Private RSA key to sign with * @param certificateChain * Certificate chain for private key * @param certificateNumber * Certificate number * @throws IOException * If an I/O problem occurs while signing the MIDlet * @throws CryptoException * If a crypto problem occurs while signing the MIDlet */ public static void sign(File jadFile, File outputJadFile, File jarFile, RSAPrivateKey privateKey, X509Certificate[] certificateChain, int certificateNumber) throws IOException, CryptoException { Properties jadProperties = readJadFile(jadFile); Properties newJadProperties = new Properties(); // Copy over existing attrs (excepting digest and any certificates at // provided number) for (Enumeration enumPropNames = jadProperties.propertyNames(); enumPropNames.hasMoreElements();) { String propName = (String) enumPropNames.nextElement(); // Ignore digest attr if (propName.equals(MIDLET_JAR_RSA_SHA1_ATTR)) { continue; } // Ignore certificates at provided number if (propName.startsWith(MessageFormat.format(SUB_MIDLET_CERTIFICATE_ATTR, certificateNumber))) { continue; } newJadProperties.put(propName, jadProperties.getProperty(propName)); } // Get certificate attrs for (int i = 0; i < certificateChain.length; i++) { X509Certificate certificate = certificateChain[i]; String base64Cert = null; try { base64Cert = new String(Base64.encode(certificate.getEncoded())); } catch (CertificateEncodingException ex) { throw new CryptoException(res.getString("Base64CertificateFailed.exception.message"), ex); } String midletCertificateAttr = MessageFormat.format(MIDLET_CERTIFICATE_ATTR, certificateNumber, (i + 1)); newJadProperties.put(midletCertificateAttr, base64Cert); } // Get signed Base 64 SHA-1 digest of JAR file as attr byte[] signedJarDigest = signJarDigest(jarFile, privateKey); String base64SignedJarDigest = new String(Base64.encode(signedJarDigest)); newJadProperties.put(MIDLET_JAR_RSA_SHA1_ATTR, base64SignedJarDigest); // Sort properties alphabetically TreeMap<String, String> sortedJadProperties = new TreeMap<String, String>(); for (Enumeration names = newJadProperties.propertyNames(); names.hasMoreElements();) { String name = (String) names.nextElement(); String value = newJadProperties.getProperty(name); sortedJadProperties.put(name, value); } // Write out new JAD properties to JAD file FileWriter fw = null; try { fw = new FileWriter(outputJadFile); for (Iterator itrSorted = sortedJadProperties.entrySet().iterator(); itrSorted.hasNext();) { Map.Entry property = (Map.Entry) itrSorted.next(); fw.write(MessageFormat.format(JAD_ATTR_TEMPLATE, property.getKey(), property.getValue())); fw.write(CRLF); } } finally { IOUtils.closeQuietly(fw); } }
From source file:com.alibaba.jstorm.ui.UIUtils.java
public static List<TableData> getWorkerMetricsTable(Map<String, MetricInfo> metrics, Integer window, Map<String, String> paramMap) { List<TableData> ret = new ArrayList<TableData>(); TableData table = new TableData(); ret.add(table);//from w w w . j a va 2 s. c o m List<String> headers = table.getHeaders(); List<Map<String, ColumnData>> lines = table.getLines(); table.setName("Worker " + UIDef.METRICS); List<String> keys = getSortedKeys(UIUtils.getKeys(metrics.values())); headers.add(UIDef.PORT); headers.add(MetricDef.NETTY); headers.addAll(keys); TreeMap<String, MetricInfo> tmpMap = new TreeMap<String, MetricInfo>(); tmpMap.putAll(metrics); Map<String, MetricInfo> showMap = new TreeMap<String, MetricInfo>(); long pos = JStormUtils.parseLong(paramMap.get(UIDef.POS), 0); long index = 0; for (Entry<String, MetricInfo> entry : tmpMap.entrySet()) { if (index < pos) { index++; } else if (pos <= index && index < pos + UIUtils.ONE_TABLE_PAGE_SIZE) { showMap.put(entry.getKey(), entry.getValue()); index++; } else { break; } } for (Entry<String, MetricInfo> entry : showMap.entrySet()) { Map<String, ColumnData> line = new HashMap<String, ColumnData>(); lines.add(line); String slot = entry.getKey(); MetricInfo metric = entry.getValue(); ColumnData slotColumn = new ColumnData(); slotColumn.addText(slot); line.put(UIDef.PORT, slotColumn); ColumnData nettyColumn = new ColumnData(); line.put(MetricDef.NETTY, nettyColumn); if (StringUtils.isBlank(paramMap.get(UIDef.TOPOLOGY))) { nettyColumn.addText(MetricDef.NETTY); } else { LinkData linkData = new LinkData(); nettyColumn.addLinkData(linkData); linkData.setUrl(UIDef.LINK_WINDOW_TABLE); linkData.setText(MetricDef.NETTY); linkData.addParam(UIDef.CLUSTER, paramMap.get(UIDef.CLUSTER)); linkData.addParam(UIDef.PAGE_TYPE, UIDef.PAGE_TYPE_NETTY); linkData.addParam(UIDef.TOPOLOGY, paramMap.get(UIDef.TOPOLOGY)); } for (String key : keys) { String value = UIUtils.getValue(metric, key, window); ColumnData valueColumn = new ColumnData(); valueColumn.addText(value); line.put(key, valueColumn); } } return ret; }