List of usage examples for java.util Map get
V get(Object key);
From source file:com.github.besherman.fingerprint.Main.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withDescription("creates a fingerprint file for the directory").hasArg() .withArgName("dir").create('c')); options.addOption(OptionBuilder.withDescription("shows a diff between two fingerprint files") .withArgName("left-file> <right-file").hasArgs(2).create('d')); options.addOption(OptionBuilder.withDescription("shows a diff between a fingerprint and a directory") .withArgName("fingerprint> <dir").hasArgs(2).create('t')); options.addOption(OptionBuilder.withDescription("shows duplicates in a directory").withArgName("dir") .hasArgs(1).create('u')); options.addOption(/* w w w.ja va 2s. c o m*/ OptionBuilder.withDescription("output to file").withArgName("output-file").hasArg().create('o')); PosixParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException ex) { System.out.println(ex.getMessage()); System.out.println(""); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fingerprint-dir", options, true); System.exit(7); } if (cmd.hasOption('c')) { Path root = Paths.get(cmd.getOptionValue('c')); if (!Files.isDirectory(root)) { System.err.println("root is not a directory"); System.exit(7); } OutputStream out = System.out; if (cmd.hasOption('o')) { Path p = Paths.get(cmd.getOptionValue('o')); out = Files.newOutputStream(p); } Fingerprint fp = new Fingerprint(root, ""); fp.write(out); } else if (cmd.hasOption('d')) { String[] ar = cmd.getOptionValues('d'); Path leftFingerprintFile = Paths.get(ar[0]), rightFingerprintFile = Paths.get(ar[1]); if (!Files.isRegularFile(leftFingerprintFile)) { System.out.printf("%s is not a file%n", leftFingerprintFile); System.exit(7); } if (!Files.isRegularFile(rightFingerprintFile)) { System.out.printf("%s is not a file%n", rightFingerprintFile); System.exit(7); } Fingerprint left, right; try (InputStream input = Files.newInputStream(leftFingerprintFile)) { left = new Fingerprint(input); } try (InputStream input = Files.newInputStream(rightFingerprintFile)) { right = new Fingerprint(input); } Diff diff = new Diff(left, right); // TODO: if we have redirected output diff.print(System.out); } else if (cmd.hasOption('t')) { throw new RuntimeException("Not yet implemented"); } else if (cmd.hasOption('u')) { Path root = Paths.get(cmd.getOptionValue('u')); Fingerprint fp = new Fingerprint(root, ""); Map<String, FilePrint> map = new HashMap<>(); fp.stream().forEach(f -> { if (map.containsKey(f.getHash())) { System.out.println(" " + map.get(f.getHash()).getPath()); System.out.println("= " + f.getPath()); System.out.println(""); } else { map.put(f.getHash(), f); } }); } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fingd", options, true); } }
From source file:Main.java
public static void main(String[] args) { String text = "A,B,C,D"; String[] keyValue = text.split(","); Map<Integer, String> myMap = new HashMap<Integer, String>(); for (int i = 0; i < keyValue.length; i++) { myMap.put(i, keyValue[i]);/*from ww w . ja v a 2 s . c o m*/ } Set keys = myMap.keySet(); Iterator itr = keys.iterator(); while (itr.hasNext()) { Integer key = (Integer) itr.next(); String value = (String) myMap.get(key); System.out.println(key + " - " + value); } }
From source file:com.joliciel.talismane.terminology.Main.java
public static void main(String[] args) throws Exception { String termFilePath = null;//from w ww.j a v a 2 s. co m String outFilePath = null; Command command = Command.extract; int depth = -1; String databasePropertiesPath = null; String projectCode = null; Map<String, String> argMap = TalismaneConfig.convertArgs(args); String logConfigPath = argMap.get("logConfigFile"); if (logConfigPath != null) { argMap.remove("logConfigFile"); Properties props = new Properties(); props.load(new FileInputStream(logConfigPath)); PropertyConfigurator.configure(props); } Map<String, String> innerArgs = new HashMap<String, String>(); for (Entry<String, String> argEntry : argMap.entrySet()) { String argName = argEntry.getKey(); String argValue = argEntry.getValue(); if (argName.equals("command")) command = Command.valueOf(argValue); else if (argName.equals("termFile")) termFilePath = argValue; else if (argName.equals("outFile")) outFilePath = argValue; else if (argName.equals("depth")) depth = Integer.parseInt(argValue); else if (argName.equals("databaseProperties")) databasePropertiesPath = argValue; else if (argName.equals("projectCode")) projectCode = argValue; else innerArgs.put(argName, argValue); } if (termFilePath == null && databasePropertiesPath == null) throw new TalismaneException("Required argument: termFile or databasePropertiesPath"); if (termFilePath != null) { String currentDirPath = System.getProperty("user.dir"); File termFileDir = new File(currentDirPath); if (termFilePath.lastIndexOf("/") >= 0) { String termFileDirPath = termFilePath.substring(0, termFilePath.lastIndexOf("/")); termFileDir = new File(termFileDirPath); termFileDir.mkdirs(); } } long startTime = new Date().getTime(); try { TerminologyServiceLocator terminologyServiceLocator = TerminologyServiceLocator.getInstance(); TerminologyService terminologyService = terminologyServiceLocator.getTerminologyService(); TerminologyBase terminologyBase = null; if (projectCode == null) throw new TalismaneException("Required argument: projectCode"); File file = new File(databasePropertiesPath); FileInputStream fis = new FileInputStream(file); Properties dataSourceProperties = new Properties(); dataSourceProperties.load(fis); terminologyBase = terminologyService.getPostGresTerminologyBase(projectCode, dataSourceProperties); if (command.equals(Command.analyse) || command.equals(Command.extract)) { if (depth < 0) throw new TalismaneException("Required argument: depth"); if (command.equals(Command.analyse)) { innerArgs.put("command", "analyse"); } else { innerArgs.put("command", "process"); } TalismaneFrench talismaneFrench = new TalismaneFrench(); TalismaneConfig config = new TalismaneConfig(innerArgs, talismaneFrench); PosTagSet tagSet = TalismaneSession.getPosTagSet(); Charset outputCharset = config.getOutputCharset(); TermExtractor termExtractor = terminologyService.getTermExtractor(terminologyBase); termExtractor.setMaxDepth(depth); termExtractor.setOutFilePath(termFilePath); termExtractor.getIncludeChildren().add(tagSet.getPosTag("P")); termExtractor.getIncludeChildren().add(tagSet.getPosTag("P+D")); termExtractor.getIncludeChildren().add(tagSet.getPosTag("CC")); termExtractor.getIncludeWithParent().add(tagSet.getPosTag("DET")); if (outFilePath != null) { if (outFilePath.lastIndexOf("/") >= 0) { String outFileDirPath = outFilePath.substring(0, outFilePath.lastIndexOf("/")); File outFileDir = new File(outFileDirPath); outFileDir.mkdirs(); } File outFile = new File(outFilePath); outFile.delete(); outFile.createNewFile(); Writer writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(outFilePath), outputCharset)); TermAnalysisWriter termAnalysisWriter = new TermAnalysisWriter(writer); termExtractor.addTermObserver(termAnalysisWriter); } Talismane talismane = config.getTalismane(); talismane.setParseConfigurationProcessor(termExtractor); talismane.process(); } else if (command.equals(Command.list)) { List<Term> terms = terminologyBase.getTermsByFrequency(2); for (Term term : terms) { LOG.debug("Term: " + term.getText()); LOG.debug("Frequency: " + term.getFrequency()); LOG.debug("Heads: " + term.getHeads()); LOG.debug("Expansions: " + term.getExpansions()); LOG.debug("Contexts: " + term.getContexts()); } } } finally { long endTime = new Date().getTime(); long totalTime = endTime - startTime; LOG.info("Total time: " + totalTime); } }
From source file:com.glaf.core.util.JsonUtils.java
public static void main(String[] args) throws Exception { Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); dataMap.put("key01", ""); dataMap.put("key02", 12345); dataMap.put("key03", 789.85D); dataMap.put("date", new Date()); Collection<Object> actorIds = new HashSet<Object>(); actorIds.add("sales01"); actorIds.add("sales02"); actorIds.add("sales03"); actorIds.add("sales04"); actorIds.add("sales05"); dataMap.put("actorIds", actorIds.toArray()); dataMap.put("x_sale_actor_actorIds", actorIds); Map<String, Object> xxxMap = new java.util.HashMap<String, Object>(); xxxMap.put("0", "--------"); xxxMap.put("1", "?"); xxxMap.put("2", ""); xxxMap.put("3", ""); dataMap.put("trans", xxxMap); String str = JsonUtils.encode(dataMap); System.out.println(str);// w w w.j av a 2 s. c om Map<?, ?> p = JsonUtils.decode(str); System.out.println(p); System.out.println(p.get("date").getClass().getName()); String xx = "{name:\"trans\",nodeType:\"select\",children:{\"1\":\"?\",\"3\":\"\",\"2\":\"\",\"0\":\"--------\"}}"; Map<String, Object> xMap = JsonUtils.decode(xx); System.out.println(xMap); Set<Entry<String, Object>> entrySet = xMap.entrySet(); for (Entry<String, Object> entry : entrySet) { String key = entry.getKey(); Object value = entry.getValue(); System.out.println(key + " = " + value); System.out.println(key.getClass().getName() + " " + value.getClass().getName()); if (value instanceof JSONObject) { JSONObject json = (JSONObject) value; Iterator<?> iter = json.keySet().iterator(); while (iter.hasNext()) { String kk = (String) iter.next(); System.out.println(kk + " = " + json.get(kk)); } } } }
From source file:CheckFonts.java
public static void main(String[] a) throws Exception { Map<String, File> filesMUI = ResUtils.listFiles(OUT_DIR, "mui"); for (Map.Entry<String, File> e : filesMUI.entrySet()) { System.out.println(e.getKey()); ReaderWriterMUI mui = new ReaderWriterMUI(FileUtils.readFileToByteArray(e.getValue())); mui.read();// w ww .j av a2 s . c o m Map<Object, Map<Object, byte[]>> res = mui.getCompiledResources(); res = SkipResources.minus(e.getKey().replace("/be-BY/", "/en-US/"), res, SkipResources.SKIP_EXTRACT); Map<Object, byte[]> dialogs = res.get(ResUtils.TYPE_DIALOG); if (dialogs == null) { continue; } for (Map.Entry<Object, byte[]> en : dialogs.entrySet()) { ResourceDialog dialog = new ParserDialog(new MemoryFile(en.getValue())).parse(); for (ResourceDialog.DlgItemTemplateEx it : dialog.items) { if (!(it.title instanceof String)) { continue; } // int linesCount = 1; // try { // int h = it.cy; // if (h == dialog.pointsize - 1) { // h++; // } // linesCount = h / dialog.pointsize; // } catch (ArithmeticException ex) { // ex.printStackTrace(); // System.out.println(en.getKey() + "/" + it.id + " - zero height"); // } // if (linesCount == 0) { // System.out.println(en.getKey() + "/" + it.id + " - zero height"); // continue; // } int w = getDimension(dialog, (String) it.title).width; if (w > it.cx) { System.out.println(en.getKey() + "/" + it.id + " - \"" + it.title + "\" need width: " + w + ", but width: " + it.cx + " [" + it.x + "," + it.y + "," + it.cx + "," + it.cy + "]"); } } } } }
From source file:edu.odu.cs.cs350.yellow1.ui.cli.Main.java
/** * Parses CLI to recievedArgs and feeds user input params to mutate function * @param args From user input//from ww w . j a va2s . com */ public static void main(String[] args) { ClI commandLine = new ClI(args); try { commandLine.parse(); } catch (RequireArgumentsNotRecieved e) { System.err.println(e.getMessage()); System.exit(0); } Map<String, String> recievedArgs = commandLine.getRecievedArguments(); String srcFolder = recievedArgs.get("src"); String fileToBeMutated = recievedArgs.get("mutF"); String testSuitePath = recievedArgs.get("testSte"); String goldOutput = recievedArgs.get("goldOut"); try { mutate(srcFolder, fileToBeMutated, testSuitePath, goldOutput); } catch (BuildFileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } System.exit(0); }
From source file:com.joliciel.talismane.TalismaneMain.java
public static void main(String[] args) throws Exception { Map<String, String> argsMap = StringUtils.convertArgs(args); OtherCommand otherCommand = null;// w w w .jav a 2 s . c o m if (argsMap.containsKey("command")) { try { otherCommand = OtherCommand.valueOf(argsMap.get("command")); argsMap.remove("command"); } catch (IllegalArgumentException e) { // not anotherCommand } } String sessionId = ""; TalismaneServiceLocator locator = TalismaneServiceLocator.getInstance(sessionId); TalismaneService talismaneService = locator.getTalismaneService(); TalismaneSession talismaneSession = talismaneService.getTalismaneSession(); if (otherCommand == null) { // regular command TalismaneConfig config = talismaneService.getTalismaneConfig(argsMap, sessionId); if (config.getCommand() == null) return; Talismane talismane = config.getTalismane(); talismane.process(); } else { // other command String logConfigPath = argsMap.get("logConfigFile"); if (logConfigPath != null) { argsMap.remove("logConfigFile"); Properties props = new Properties(); props.load(new FileInputStream(logConfigPath)); PropertyConfigurator.configure(props); } switch (otherCommand) { case serializeLexicon: { LexiconSerializer serializer = new LexiconSerializer(); serializer.serializeLexicons(argsMap); break; } case testLexicon: { String lexiconFilePath = null; String[] wordList = null; for (String argName : argsMap.keySet()) { String argValue = argsMap.get(argName); if (argName.equals("lexicon")) { lexiconFilePath = argValue; } else if (argName.equals("words")) { wordList = argValue.split(","); } else { throw new TalismaneException("Unknown argument: " + argName); } } File lexiconFile = new File(lexiconFilePath); LexiconDeserializer lexiconDeserializer = new LexiconDeserializer(talismaneSession); List<PosTaggerLexicon> lexicons = lexiconDeserializer.deserializeLexicons(lexiconFile); for (PosTaggerLexicon lexicon : lexicons) talismaneSession.addLexicon(lexicon); PosTaggerLexicon mergedLexicon = talismaneSession.getMergedLexicon(); for (String word : wordList) { LOG.info("################"); LOG.info("Word: " + word); List<LexicalEntry> entries = mergedLexicon.getEntries(word); for (LexicalEntry entry : entries) { LOG.info(entry + ", Full morph: " + entry.getMorphologyForCoNLL()); } } break; } } } }
From source file:org.bigtextml.drivers.BigMapReadTest.java
public static void main(String[] args) { /*//from w ww. j a v a 2s . co m ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"InMemoryDataMining.xml"}); */ System.out.println(System.getProperty("InvokedFromSpring")); //Map<String,List<Integer>> bm = context.getBean("bigMapTest",BigMap.class); Map<String, List<Integer>> bm = ManagementServices.getBigMap("tmCache"); System.out.println(((BigMap) bm).getCacheName()); int max = 1000000; String key = Integer.toString(max - 1); //bm.remove(key); for (int i = 0; i < 3; i++) { long millis = System.currentTimeMillis(); System.out.println(bm.get(Integer.toString(500000))); System.out.println(System.currentTimeMillis() - millis); } bm.clear(); }
From source file:edu.uchicago.mpcs.CrimeTopology.CrimeTopology.java
public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException, AuthorizationException { Map stormConf = Utils.readStormConfig(); String zookeepers = StringUtils.join((List<String>) (stormConf.get("storm.zookeeper.servers")), ","); System.out.println(zookeepers); ZkHosts zkHosts = new ZkHosts(zookeepers); SpoutConfig kafkaConfig = new SpoutConfig(zkHosts, "siruif-crime", "/siruif-crime", "crime_id"); kafkaConfig.scheme = new SchemeAsMultiScheme(new StringScheme()); kafkaConfig.zkServers = (List<String>) stormConf.get("storm.zookeeper.servers"); kafkaConfig.zkRoot = "/siruif-crime"; kafkaConfig.zkPort = 2181;/*from ww w. j a va2 s. c o m*/ KafkaSpout kafkaSpout = new KafkaSpout(kafkaConfig); TopologyBuilder builder = new TopologyBuilder(); builder.setSpout("raw-siruif-crime", kafkaSpout, 1); builder.setBolt("filter-siruif-crime", new FilterCrimeBolt(), 1).shuffleGrouping("raw-siruif-crime"); builder.setBolt("extract-siruif-ward", new UpdateCrimeBolt(), 1).fieldsGrouping("filter-siruif-crime", new Fields("ward")); Map conf = new HashMap(); conf.put(backtype.storm.Config.TOPOLOGY_WORKERS, 2); if (args != null && args.length > 0) { StormSubmitter.submitTopology(args[0], conf, builder.createTopology()); } else { conf.put(backtype.storm.Config.TOPOLOGY_DEBUG, true); LocalCluster cluster = new LocalCluster(zookeepers, 2181L); cluster.submitTopology("siruif-crime-topology", conf, builder.createTopology()); } }
From source file:br.edimarmanica.weir2.rule.Loader.java
public static void main(String[] args) { Site site = br.edimarmanica.dataset.weir.book.Site.BOOKMOOCH; Map<String, String> entityValues = loadEntityValues( new File(Paths.PATH_INTRASITE + "/" + site.getPath() + "/extracted_values/rule_379.csv"), loadEntityID(site));/*from w w w . j a va 2 s . co m*/ for (String entity : entityValues.keySet()) { System.out.println(entity + "->" + entityValues.get(entity)); } }