List of usage examples for java.util HashMap HashMap
public HashMap()
From source file:com.seavus.wordcountermaven.WordCounter.java
/** * @param args the command line arguments * @throws java.io.FileNotFoundException *//*from w w w . j a v a 2 s . c o m*/ public static void main(String[] args) throws FileNotFoundException { InputStream fileStream = WordCounter.class.getClassLoader().getResourceAsStream("test.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(fileStream)); Map<String, Integer> wordMap = new HashMap<>(); String line; boolean tokenFound = false; try { while ((line = br.readLine()) != null) { String[] tokens = line.trim().split("\\s+"); //trims surrounding whitespaces and splits lines into tokens for (String token : tokens) { for (Map.Entry<String, Integer> entry : wordMap.entrySet()) { if (StringUtils.equalsIgnoreCase(token, entry.getKey())) { wordMap.put(entry.getKey(), (wordMap.get(entry.getKey()) + 1)); tokenFound = true; } } if (!token.equals("") && !tokenFound) { wordMap.put(token.toLowerCase(), 1); } tokenFound = false; } } br.close(); } catch (IOException ex) { Logger.getLogger(WordCounter.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("string : " + "frequency\r\n" + "-------------------"); //prints out each unique word (i.e. case-insensitive string token) and its frequency to the console for (Map.Entry<String, Integer> entry : wordMap.entrySet()) { System.out.println(entry.getKey() + " : " + entry.getValue()); } }
From source file:minikbextractor.MiniKBextractor.java
/** * @param args the command line arguments */// w w w . jav a 2 s. co m public static void main(String[] args) { String adomFile = "in/agronomicTaxon.owl"; ArrayList<Source> sources = new ArrayList(); SparqlProxy spInAgrovoc = SparqlProxy .getSparqlProxy("http://amarger.murloc.fr:8080/Agrovoc2KB_TESTClass_out/"); HashMap<String, String> limitSpOutAgrovoc = new HashMap<>(); //limitSpOutAgrovoc.put("http://aims.fao.org/aos/agrovoc/c_5608", "http://amarger.murloc.fr:8080/Agrovoc_mini_Paspalum/"); limitSpOutAgrovoc.put("http://aims.fao.org/aos/agrovoc/c_148", "http://amarger.murloc.fr:8080/Agrovoc_mini_Aegilops/"); //imitSpOutAgrovoc.put("http://aims.fao.org/aos/agrovoc/c_5435", "http://amarger.murloc.fr:8080/Agrovoc_mini_Oryza/"); limitSpOutAgrovoc.put("http://aims.fao.org/aos/agrovoc/c_7950", "http://amarger.murloc.fr:8080/Agrovoc_mini_Triticum/"); String nameAgrovoc = "Agrovoc"; sources.add(new Source(spInAgrovoc, nameAgrovoc, limitSpOutAgrovoc, adomFile)); SparqlProxy spInTaxRef = SparqlProxy.getSparqlProxy("http://amarger.murloc.fr:8080/TaxRef2RKB_out_TEST/"); HashMap<String, String> limitSpOutTaxRef = new HashMap<>(); //limitSpOutTaxRef.put("http://inpn.mnhn.fr/espece/cd_nom/195870", "http://amarger.murloc.fr:8080/TaxRef_mini_Paspalum/"); limitSpOutTaxRef.put("http://inpn.mnhn.fr/espece/cd_nom/188834", "http://amarger.murloc.fr:8080/TaxRef_mini_Aegilops/"); //limitSpOutTaxRef.put("http://inpn.mnhn.fr/espece/cd_nom/195564", "http://amarger.murloc.fr:8080/TaxRef_mini_Oryza/"); limitSpOutTaxRef.put("http://inpn.mnhn.fr/espece/cd_nom/198676", "http://amarger.murloc.fr:8080/TaxRef_mini_Triticum/"); //String limitUriTaxRef = "http://inpn.mnhn.fr/espece/cd_nom/187444"; //Poaceae String nameTaxRef = "TaxRef "; sources.add(new Source(spInTaxRef, nameTaxRef, limitSpOutTaxRef, adomFile)); SparqlProxy spInNCBI = SparqlProxy.getSparqlProxy("http://amarger.murloc.fr:8080/Ncbi2RKB_out/"); HashMap<String, String> limitSpOutNCBI = new HashMap<>(); //limitSpOutNCBI.put("http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=147271", "http://amarger.murloc.fr:8080/NCBI_mini_Paspalum/"); limitSpOutNCBI.put("http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=4480", "http://amarger.murloc.fr:8080/NCBI_mini_Aegilops/"); //limitSpOutNCBI.put("http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=4527", "http://amarger.murloc.fr:8080/NCBI_mini_Oryza/"); limitSpOutNCBI.put("http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=4564", "http://amarger.murloc.fr:8080/NCBI_mini_Triticum/"); String nameNCBI = "NCBI"; sources.add(new Source(spInNCBI, nameNCBI, limitSpOutNCBI, adomFile)); for (Source s : sources) { //System.out.println(s.getStatUnderLimit()); s.exportAllSubRKB(); System.out.println("------------------------------------"); } System.exit(0); }
From source file:Main.java
public static void main(String[] args) { HashMap<String, Integer> map = new HashMap<String, Integer>(); map.put("item1", 1); map.put("item2", 2); map.put("item3", 1); map.put("item4", 7); map.put("item5", 3); map.put("item6", 4); for (Map.Entry<String, Integer> entry : map.entrySet()) { System.out.println("Item is:" + entry.getKey() + " with value:" + entry.getValue()); }//w w w . ja v a2 s . c o m Map<String, Integer> sortedMap = sortByValue(map); for (Map.Entry<String, Integer> entry : sortedMap.entrySet()) { System.out.println("Item is:" + entry.getKey() + " with value:" + entry.getValue()); } }
From source file:org.seedstack.spring.batch.fixtures.FlatFileBatchDemo.java
public static void main(String[] argv) throws Exception { String jobFile = argv[0];/*from w w w . j a v a2 s . c om*/ ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( new String[] { "simple-job-launcher-context.xml", jobFile }); Job job = applicationContext.getBean(Job.class); Map<String, JobParameter> jobParametersMap = new HashMap<>(); jobParametersMap.put("file", new JobParameter(argv[1])); JobParameters jobParameters = new JobParameters(jobParametersMap); JobLauncher jobLauncher = applicationContext.getBean(JobLauncher.class); JobExecution jobExecution = jobLauncher.run(job, jobParameters); printStatistics(jobExecution); }
From source file:MyComparator.java
public static void main(String[] args) { Map<String, Integer> unsortMap = new HashMap<String, Integer>(); unsortMap.put("B", 5); unsortMap.put("A", 8); unsortMap.put("D", 2); unsortMap.put("C", 7); System.out.println("Before sorting......"); System.out.println(unsortMap); Map<String, Integer> sortedMapAsc = Util.sortByComparator(unsortMap); System.out.println(sortedMapAsc); }
From source file:com.termmed.sampling.ConceptsWithMoreThanThreeRoleGroups.java
/** * The main method.//w w w . ja v a2 s . co m * * @param args the arguments * @throws Exception the exception */ public static void main(String[] args) throws Exception { System.out.println("Starting..."); Map<String, Set<String>> groupsMap = new HashMap<String, Set<String>>(); File relsFile = new File( "/Users/alo/Downloads/SnomedCT_RF2Release_INT_20160131-1/Snapshot/Terminology/sct2_Relationship_Snapshot_INT_20160131.txt"); BufferedReader br2 = new BufferedReader(new FileReader(relsFile)); String line2; int count2 = 0; while ((line2 = br2.readLine()) != null) { // process the line. count2++; if (count2 % 10000 == 0) { //System.out.println(count2); } List<String> columns = Arrays.asList(line2.split("\t", -1)); if (columns.size() >= 6) { if (columns.get(2).equals("1") && !columns.get(6).equals("0")) { if (!groupsMap.containsKey(columns.get(4))) { groupsMap.put(columns.get(4), new HashSet<String>()); } groupsMap.get(columns.get(4)).add(columns.get(6)); } } } System.out.println("Relationship groups loaded"); Gson gson = new Gson(); System.out.println("Reading JSON 1"); File crossoverFile1 = new File("/Users/alo/Downloads/crossover_role_to_group.json"); String contents = FileUtils.readFileToString(crossoverFile1, "utf-8"); Type collectionType = new TypeToken<Collection<ControlResultLine>>() { }.getType(); List<ControlResultLine> lineObject = gson.fromJson(contents, collectionType); Set<String> crossovers1 = new HashSet<String>(); for (ControlResultLine loopResult : lineObject) { crossovers1.add(loopResult.conceptId); } System.out.println("Crossovers 1 loaded, " + lineObject.size() + " Objects"); System.out.println("Reading JSON 2"); File crossoverFile2 = new File("/Users/alo/Downloads/crossover_group_to_group.json"); String contents2 = FileUtils.readFileToString(crossoverFile2, "utf-8"); List<ControlResultLine> lineObject2 = gson.fromJson(contents2, collectionType); Set<String> crossovers2 = new HashSet<String>(); for (ControlResultLine loopResult : lineObject2) { crossovers2.add(loopResult.conceptId); } System.out.println("Crossovers 2 loaded, " + lineObject2.size() + " Objects"); Set<String> foundConcepts = new HashSet<String>(); int count3 = 0; BufferedWriter writer = new BufferedWriter( new FileWriter(new File("ConceptsWithMoreThanThreeRoleGroups.csv"))); ; for (String loopConcept : groupsMap.keySet()) { if (groupsMap.get(loopConcept).size() > 3) { writer.write(loopConcept); writer.newLine(); foundConcepts.add(loopConcept); count3++; } } writer.close(); System.out.println("Found " + foundConcepts.size() + " concepts"); int countCrossover1 = 0; for (String loopConcept : foundConcepts) { if (crossovers1.contains(loopConcept)) { countCrossover1++; } } System.out.println(countCrossover1 + " are present in crossover_role_to_group"); int countCrossover2 = 0; for (String loopConcept : foundConcepts) { if (crossovers2.contains(loopConcept)) { countCrossover2++; } } System.out.println(countCrossover2 + " are present in crossover_group_to_group"); System.out.println("Done"); }
From source file:com.hisuntech.ArchOnlineSchoolAuth.test.aop.MyTest.java
public static void main(String[] args) throws HttpException, IOException { Map<String, String> sParaTemp = new HashMap<String, String>(); //RqPnCoPT3K9%252Fvwbh3InQ8DTlBqQF2KlM0p08vXXXXXXXXXXMK3zQ4hsFX%252F3tstP sParaTemp.put("WIDout_trade_no", "16051800000164"); //sParaTemp.put("WIDsubject", "16051800000164"); sParaTemp.put("WIDtotal_fee", "0.1"); sParaTemp.put("payType", "10"); // sParaTemp.put("seller_id", "2088021521071865"); // sParaTemp.put("service", "alipay.wap.create.direct.pay.by.user"); // sParaTemp.put("subject", "?-16051800000164"); // sParaTemp.put("total_fee", "0.01"); // sParaTemp.put("trade_no", "2016051821001004490280869093"); // sParaTemp.put("trade_status", "TRADE_SUCCESS"); // sParaTemp.put("sign_type", "RSA"); String url = "http://192.168.1.126:8080/ArchOnlineSchoolBack/getAlipayAdr/getAdr"; //String url = "http://101.200.75.226:8083/ArchOnlineSchoolBack/getAlipayAdr/getAdr"; HttpProtocolHandler httpProtocolHandler = HttpProtocolHandler.getInstance(); HttpRequest request = new HttpRequest(HttpResultType.BYTES); //?//from w w w .jav a2s.c o m request.setCharset(AlipayConfigTX.input_charset); request.setParameters(generatNameValuePair(sParaTemp)); request.setUrl(url); HttpResponse response = httpProtocolHandler.execute(request, "", ""); if (response == null) { System.out.println("return null;"); } String strResult = response.getStringResult(); System.out.println("return strResult;" + strResult); }
From source file:gov.nist.healthcare.ttt.webapp.api.GetCCDAFolderTest.java
public static void main(String[] args) throws Exception { long startTime = System.currentTimeMillis(); JSONObject res = new JSONObject(); HashMap<String, Object> json = new HashMap<>(); String sha = getHTML(/*from w ww .j av a 2 s .c om*/ "https://api.github.com/repos/siteadmin/2015-Certification-C-CDA-Test-Data/branches/master") .getJSONObject("commit").get("sha").toString(); JSONArray filesArray = getHTML( "https://api.github.com/repos/siteadmin/2015-Certification-C-CDA-Test-Data/git/trees/" + sha + "?recursive=1").getJSONArray("tree"); HashMap<String, Object> resultMap = new HashMap<>(); for (int i = 0; i < filesArray.length(); i++) { JSONObject file = filesArray.getJSONObject(i); if (!files2ignore.contains(file.get("path"))) { // Get path array String[] path = file.get("path").toString().split("/"); // System.out.println(String.join("/", path)); // for(String dir : path) { // if(Pattern.matches(extensionRegex, dir)) { // System.out.println("File!! " + dir); // } // } // json = buildJson2(new HashMap<>(), path, false, true); // resultMap = deepMerge(resultMap, json); // System.out.println(new JSONObject(json).toString(2)); buildJson3(resultMap, path); } } // String[] test = {"test", "retest", "file.txt"}; // json = buildJson2(json, test, false, true); System.out.println(new JSONObject(resultMap).toString(2)); PrintWriter out = new PrintWriter("filename.txt"); out.println(new JSONObject(resultMap).toString(2)); long endTime = System.currentTimeMillis(); long totalTime = endTime - startTime; System.out.println("Running time: " + totalTime / 1000.0 + "s"); // Try download // URL website = new URL("https://raw.githubusercontent.com/siteadmin/2015-Certification-C-CDA-Test-Data/master/Receiver%20SUT%20Test%20Data/170.315_b1_ToC_Amb/170.315_b1_toc_amb_ccd_r11_sample1_v1.xml"); // InputStream strm = website.openStream(); // System.out.println(IOUtils.toString(strm)); }
From source file:httprequestsample.HttpRequestSample.java
/** * @param args the command line arguments *//*from w w w . j a va 2s . c o m*/ public static void main(String[] args) { // TODO code application logic here ClientRequestHelper clientRequestHelper = new ClientRequestHelper(); clientRequestHelper.setProxy("10.61.11.39", 3128); HashMap<String, String> hmR = new HashMap<String, String>(); hmR.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"); hmR.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); hmR.put("Accept-Language", "en-US,en;q=0.5"); hmR.put("Content-Type", "application/x-www-form-urlencoded"); String result = clientRequestHelper.sendGet("http://www.otohits.net/account/login", hmR); Document doc = Jsoup.parse(result); Elements lstElement = doc.getElementsByAttributeValue("name", "__RequestVerificationToken"); String requestVeriToken = ""; HashMap<String, String> hmData = new HashMap<>(); if (lstElement != null && lstElement.size() > 0) { requestVeriToken = lstElement.get(0).attr("value"); } hmData.put("__RequestVerificationToken", requestVeriToken); hmData.put("Email", "getmoneykhmt3@gmail.com"); hmData.put("Password", "asd123"); result = clientRequestHelper.sendPost("http://www.otohits.net/account/login", hmR, hmData); System.out.println(result); }
From source file:com.vina.hlexchang.HttpRequestSample.java
/** * @param args the command line arguments *//*from w ww . j av a 2s. c om*/ public static void main(String[] args) { // TODO code application logic here ClientRequestHelper clientRequestHelper = new ClientRequestHelper(); // clientRequestHelper.setProxy("10.61.11.39", 3128); HashMap<String, String> hmR = new HashMap<String, String>(); hmR.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"); hmR.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); hmR.put("Accept-Language", "en-US,en;q=0.5"); hmR.put("Content-Type", "application/x-www-form-urlencoded"); String result = clientRequestHelper.sendGet("http://www.otohits.net/account/login", hmR); Document doc = Jsoup.parse(result); Elements lstElement = doc.getElementsByAttributeValue("name", "__RequestVerificationToken"); String requestVeriToken = ""; HashMap<String, String> hmData = new HashMap<>(); if (lstElement != null && lstElement.size() > 0) { requestVeriToken = lstElement.get(0).attr("value"); } hmData.put("__RequestVerificationToken", requestVeriToken); hmData.put("Email", "getmoneykhmt3@gmail.com"); hmData.put("Password", "asd123"); result = clientRequestHelper.sendPost("http://www.otohits.net/account/login", hmR, hmData); System.out.println(result); }