List of usage examples for java.util TreeMap TreeMap
public TreeMap()
From source file:com.nexmo.security.RequestSigning.java
/** * sign a set of request parameters, generating additional parameters to represent the timestamp and generated signature * uses the supplied pre-shared secret key to generate the signature * * @param params List of NameValuePair instances containing the query parameters for the request that is to be signed * @param secretKey the pre-shared secret key held by the client * * @return String the fully constructed url complete with signature *//*from w w w. ja v a2 s.c om*/ public static void constructSignatureForRequestParameters(List<NameValuePair> params, String secretKey) { // First, inject a 'timestamp=' parameter containing the current time in seconds since Jan 1st 1970 params.add(new BasicNameValuePair(PARAM_TIMESTAMP, "" + System.currentTimeMillis() / 1000)); Map<String, String> sortedParams = new TreeMap<>(); for (NameValuePair param : params) { String name = param.getName(); String value = param.getValue(); if (name.equals(PARAM_SIGNATURE)) continue; if (value == null) value = ""; if (!value.trim().equals("")) sortedParams.put(name, value); } // Now, walk through the sorted list of parameters and construct a string StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> param : sortedParams.entrySet()) { String name = param.getKey(); String value = param.getValue(); sb.append("&").append(clean(name)).append("=").append(clean(value)); } // Now, append the secret key, and calculate an MD5 signature of the resultant string sb.append(secretKey); String str = sb.toString(); String md5 = "no signature"; try { md5 = MD5Util.calculateMd5(str); } catch (Exception e) { log.error("error...", e); } log.debug("SECURITY-KEY-GENERATION -- String [ " + str + " ] Signature [ " + md5 + " ] "); params.add(new BasicNameValuePair(PARAM_SIGNATURE, md5)); }
From source file:forge.util.storage.StorageReaderFile.java
@Override public Map<String, T> readAll() { final Map<String, T> result = new TreeMap<String, T>(); int idx = 0;//from w w w .j a v a 2 s . c o m for (final String s : FileUtil.readFile(file)) { if (!lineContainsObject(s)) { continue; } final T item = read(s, idx); if (null == item) { final String msg = "An object stored in " + file.getPath() + " failed to load.\nPlease submit this as a bug with the mentioned file attached."; throw new RuntimeException(msg); } idx++; String newKey = keySelector.apply(item); if (result.containsKey(newKey)) { System.err.println("StorageReader: Overwriting an object with key " + newKey); } result.put(newKey, item); } return result; }
From source file:gemlite.core.internal.support.hotdeploy.scanner.RegistryMatchedContext.java
public RegistryMatchedContext() { scannedItems = new TreeMap<>(); }
From source file:com.epam.cme.core.util.MccSiteUrlHelper.java
public Map<String, String> getSitesAndUrls() { final Map<String, String> siteToUrl = new TreeMap<String, String>(); for (final CMSSiteModel cmsSiteModel : getCmsSiteService().getSites()) { final String url = getSiteUrl(cmsSiteModel); if (url != null && !url.isEmpty() && SiteChannel.TELCO.equals(cmsSiteModel.getChannel())) { siteToUrl.put(cmsSiteModel.getName(), url); }// w w w . j a va 2 s . co m } return siteToUrl; }
From source file:annis.service.objects.AnnisAttribute.java
@XmlElementWrapper(name = "value-set") @XmlElement(name = "value") public Collection<String> getValueSet() { Map<String, SortedSet<String>> sortedMap = new TreeMap<String, SortedSet<String>>(); for (String v : distinctValues) { if (sortedMap.containsKey(v.toLowerCase())) { sortedMap.get(v.toLowerCase()).add(v); }/*w ww.j a va 2 s. c o m*/ else { sortedMap.put(v.toLowerCase(), new TreeSet<String>()); sortedMap.get(v.toLowerCase()).add(v); } } distinctValues.clear(); for (String k : sortedMap.keySet()) { for (String s : sortedMap.get(k)) { distinctValues.add(s); } } return distinctValues; }
From source file:net.panthema.BispanningGame.MyGraphMLReader.java
MyGraphMLReader(javax.swing.JPanel panel) throws FileNotFoundException, GraphIOException { posMap = new TreeMap<Integer, Point2D>(); // Query user for filename JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Specify GraphML file to read"); chooser.setCurrentDirectory(new File(".")); FileNameExtensionFilter filter = new FileNameExtensionFilter("GraphML File", "graphml"); chooser.setFileFilter(filter);/*from w w w .ja va 2 s. c o m*/ if (chooser.showOpenDialog(panel) != JFileChooser.APPROVE_OPTION) return; File infile = chooser.getSelectedFile(); BufferedReader fileReader = new BufferedReader(new FileReader(infile)); newGraph = new MyGraph(); // create the graph transformer Transformer<GraphMetadata, MyGraph> graphTransformer = new Transformer<GraphMetadata, MyGraph>() { public MyGraph transform(GraphMetadata metadata) { assert (metadata.getEdgeDefault().equals(EdgeDefault.UNDIRECTED)); return newGraph; } }; // create the vertex transformer Transformer<NodeMetadata, Integer> vertexTransformer = new Transformer<NodeMetadata, Integer>() { public Integer transform(NodeMetadata metadata) { // create a new vertex Integer v = newGraph.getVertexCount(); // save layout information if (metadata.getProperty("x") != null && metadata.getProperty("y") != null) { double x = Double.parseDouble(metadata.getProperty("x")); double y = Double.parseDouble(metadata.getProperty("y")); posMap.put(v, new Point2D.Double(x, y)); } newGraph.addVertex(v); return v; } }; // create the edge transformer Transformer<EdgeMetadata, MyEdge> edgeTransformer = new Transformer<EdgeMetadata, MyEdge>() { public MyEdge transform(EdgeMetadata metadata) { MyEdge e = new MyEdge(newGraph.getEdgeCount()); if (metadata.getProperty("color") != null) e.color = Integer.parseInt(metadata.getProperty("color")); return e; } }; // create the useless hyperedge transformer Transformer<HyperEdgeMetadata, MyEdge> hyperEdgeTransformer = new Transformer<HyperEdgeMetadata, MyEdge>() { public MyEdge transform(HyperEdgeMetadata metadata) { return null; } }; // create the graphMLReader2 GraphMLReader2<MyGraph, Integer, MyEdge> graphReader = new GraphMLReader2<MyGraph, Integer, MyEdge>( fileReader, graphTransformer, vertexTransformer, edgeTransformer, hyperEdgeTransformer); // Get the new graph object from the GraphML file graphReader.readGraph(); }
From source file:com.github.lucapino.sheetmaker.parsers.mediainfo.MediaInfoExtractor.java
private void print(String rootPath) throws Exception { FileFilter filter = new FileFilter() { @Override/*from w ww. ja v a 2 s . c o m*/ public boolean accept(File pathname) { String lowerCaseName = pathname.getName().toLowerCase(); return (lowerCaseName.endsWith("ifo") && lowerCaseName.startsWith("vts")) || lowerCaseName.endsWith("mkv") || lowerCaseName.endsWith("iso") || lowerCaseName.endsWith("avi"); } }; // parse all the tree under rootPath File rootFolder = new File(rootPath); File[] files = rootFolder.listFiles(); Arrays.sort(files); Map<File, List<File>> mediaMap = new TreeMap<>(); for (File file : files) { System.out.println(file.getName()); // name of the folder -> name of media List<File> fileList; if (file.isDirectory()) { fileList = recurseSubFolder(filter, file); if (!fileList.isEmpty()) { System.out.println("adding " + fileList); mediaMap.put(file, fileList); } } else { if (filter.accept(file)) { fileList = new ArrayList<>(); fileList.add(file); System.out.println("adding " + fileList); mediaMap.put(file, fileList); } } } Set<File> fileNamesSet = mediaMap.keySet(); File outputFile = new File("/home/tagliani/tmp/HD-report.xls"); Workbook wb = new HSSFWorkbook(new FileInputStream(outputFile)); Sheet sheet = wb.createSheet("Toshiba"); MediaInfo MI = new MediaInfo(); int j = 0; for (File mediaFile : fileNamesSet) { List<File> filesList = mediaMap.get(mediaFile); for (File fileInList : filesList) { List<String> audioTracks = new ArrayList<>(); List<String> videoTracks = new ArrayList<>(); List<String> subtitlesTracks = new ArrayList<>(); MI.Open(fileInList.getAbsolutePath()); String durationInt = MI.Get(MediaInfo.StreamKind.General, 0, "Duration", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); System.out.println(fileInList.getName() + " -> " + durationInt); if (StringUtils.isNotEmpty(durationInt) && Integer.valueOf(durationInt) >= 60 * 60 * 1000) { Row row = sheet.createRow(j); String duration = MI.Get(MediaInfo.StreamKind.General, 0, "Duration/String", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); // Create a cell and put a value in it. row.createCell(0).setCellValue(WordUtils.capitalizeFully(mediaFile.getName())); if (fileInList.getName().toLowerCase().endsWith("iso") || fileInList.getName().toLowerCase().endsWith("ifo")) { row.createCell(1).setCellValue("DVD"); } else { row.createCell(1) .setCellValue(FilenameUtils.getExtension(fileInList.getName()).toUpperCase()); } row.createCell(2).setCellValue(FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(mediaFile))); // row.createCell(3).setCellValue(fileInList.getAbsolutePath()); row.createCell(3).setCellValue(duration); // MPEG-2 720x576 @ 25fps 16:9 String format = MI.Get(MediaInfo.StreamKind.Video, 0, "Format", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); row.createCell(4).setCellValue(format); String width = MI.Get(MediaInfo.StreamKind.Video, 0, "Width", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); String height = MI.Get(MediaInfo.StreamKind.Video, 0, "Height", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); row.createCell(5).setCellValue(width + "x" + height); String fps = MI.Get(MediaInfo.StreamKind.Video, 0, "FrameRate", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); row.createCell(6).setCellValue(fps); String aspectRatio = MI.Get(MediaInfo.StreamKind.Video, 0, "DisplayAspectRatio/String", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); row.createCell(7).setCellValue(aspectRatio); int audioStreamNumber = MI.Count_Get(MediaInfo.StreamKind.Audio); for (int i = 0; i < audioStreamNumber; i++) { String audioTitle = MI.Get(MediaInfo.StreamKind.Audio, i, "Title", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); String language = MI.Get(MediaInfo.StreamKind.Audio, i, "Language/String3", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); String codec = MI.Get(MediaInfo.StreamKind.Audio, i, "Codec", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); String channels = MI.Get(MediaInfo.StreamKind.Audio, i, "Channel(s)", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); String sampleRate = MI.Get(MediaInfo.StreamKind.Audio, i, "SamplingRate/String", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); // AC3 ITA 5.1 48.0KHz StringBuilder sb = new StringBuilder(); if (StringUtils.isEmpty(audioTitle)) { sb.append(codec).append(" ").append(language.toUpperCase()).append(" ") .append(channels); } else { sb.append(audioTitle); } sb.append(" ").append(sampleRate); audioTracks.add(sb.toString()); } int textStreamNumber = MI.Count_Get(MediaInfo.StreamKind.Text); for (int i = 0; i < textStreamNumber; i++) { String textLanguage = MI.Get(MediaInfo.StreamKind.Text, i, "Language/String", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); subtitlesTracks.add(textLanguage); } MI.Close(); row.createCell(8).setCellValue(audioTracks.toString()); row.createCell(9).setCellValue(subtitlesTracks.toString()); j++; } } // System.out.println(mediaName); } try (FileOutputStream fileOut = new FileOutputStream(outputFile)) { wb.write(fileOut); } }