List of usage examples for java.util HashMap HashMap
public HashMap()
From source file:com.ifeng.sorter.NginxApp.java
public static void main(String[] args) { String input = "src/test/resources/data/nginx_report.txt"; PrintWriter pw = null;//w ww . j a v a 2s .com Map<String, List<LogBean>> resultMap = new HashMap<String, List<LogBean>>(); List<String> ips = new ArrayList<String>(); try { List<String> lines = FileUtils.readLines(new File(input)); List<LogBean> items = new ArrayList<LogBean>(); for (String line : lines) { String[] values = line.split("\t"); if (values != null && values.length == 3) {// ip total seria try { String ip = values[0].trim(); String total = values[1].trim(); String seria = values[2].trim(); LogBean bean = new LogBean(ip, Integer.parseInt(total), seria); items.add(bean); } catch (NumberFormatException e) { e.printStackTrace(); } } } Collections.sort(items); for (LogBean bean : items) { String key = bean.getIp(); if (resultMap.containsKey(key)) { resultMap.get(key).add(bean); } else { List<LogBean> keyList = new ArrayList<LogBean>(); keyList.add(bean); resultMap.put(key, keyList); ips.add(key); } } pw = new PrintWriter("src/test/resources/output/result.txt", "UTF-8"); for (String ip : ips) { List<LogBean> list = resultMap.get(ip); for (LogBean bean : list) { pw.append(bean.toString()); pw.println(); } } } catch (IOException e) { e.printStackTrace(); } finally { pw.flush(); pw.close(); } }
From source file:cz.cas.lib.proarc.common.process.KakaduCompress.java
public static void main(String[] args) throws Exception { if (args != null && args.length > 2) { HashMap<String, String> env = new HashMap<String, String>(); env.put(AppConfiguration.PROPERTY_APP_HOME, args[0]); AppConfiguration conf = AppConfigurationFactory.getInstance().create(env); Configuration config = conf.getAuthenticators(); config = new ImportProfile(config).getNdkArchivalProcessor(); ExternalProcess ep = new KakaduCompress(config, new File(args[1]), new File(args[2])); ep.run();/* w ww . j a va 2 s. c o m*/ } }
From source file:com.apress.prospringintegration.jdbc.JdbcGateway.java
public static void main(String[] args) throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("/spring/jdbc/jdbc-gateway-context.xml"); MessageChannel input = context.getBean("input", MessageChannel.class); PollableChannel output = context.getBean("output", PollableChannel.class); Map<String, Object> rowMessage = new HashMap<String, Object>(); rowMessage.put("id", 3); rowMessage.put("firstname", "Mr"); rowMessage.put("lastname", "Bill"); rowMessage.put("status", 0); Message<Map<String, Object>> message = MessageBuilder.withPayload(rowMessage).build(); input.send(message);/*w w w.j a v a 2 s . com*/ Message<?> reply = output.receive(); System.out.println("Reply message: " + reply); Map<String, Object> rowMap = (Map<String, Object>) reply.getPayload(); for (String column : rowMap.keySet()) { System.out.println("column: " + column + " value: " + rowMap.get(column)); } }
From source file:example.stores.StarbucksClient.java
public static void main(String[] args) { Traverson traverson = new Traverson(URI.create("http://localhost:8080"), MediaTypes.HAL_JSON); Map<String, Object> parameters = new HashMap<>(); parameters.put("location", "40.740337,-73.995146"); parameters.put("distance", "0.5miles"); PagedResources<Resource<Store>> resources = traverson. // follow("stores", "search", "by-location").// withTemplateParameters(parameters).// toObject(TYPE_REFERENCE);// w w w .j av a2 s. c om PageMetadata metadata = resources.getMetadata(); System.out.println( String.format("Got %s of %s stores: ", resources.getContent().size(), metadata.getTotalElements())); for (Resource<Store> resource : resources) { Store store = resource.getContent(); System.out.println(String.format("- %s - %s", store.name, store.address)); } }
From source file:de.tudarmstadt.ukp.experiments.argumentation.clustering.entropy.MatrixExperiments.java
public static void main(String[] args) throws Exception { File in = new File(args[0]); List<String> lines = IOUtils.readLines(new FileInputStream(in)); int rows = lines.size(); int cols = lines.iterator().next().split("\\s+").length; double[][] matrix = new double[rows][cols]; Map<Integer, Double> clusterEntropy = new HashMap<>(); for (int i = 0; i < rows; i++) { String line = lines.get(i); String[] split = line.split("\\s+"); for (int j = 0; j < split.length; j++) { Double value = Double.valueOf(split[j]); matrix[i][j] = value;// ww w . ja va 2 s. c om } // entropy of the cluster Vector v = new DenseVector(matrix[i]); // System.out.print(VectorUtils.entropy(v)); double entropy = VectorUtils.entropy(VectorUtils.normalize(v)); System.out.print(entropy); System.out.print(" "); clusterEntropy.put(i, entropy); } Map<Integer, Double> sorted = sortByValue(clusterEntropy); System.out.println(sorted); HeatChart map = new HeatChart(matrix); // Step 2: Customise the chart. map.setTitle("This is my heat chart title"); map.setXAxisLabel("X Axis"); map.setYAxisLabel("Y Axis"); // Step 3: Output the chart to a file. map.saveToFile(new File("/tmp/java-heat-chart.png")); }
From source file:com.sm.replica.TestServer.java
public static void main(String[] args) { String[] opts = new String[] { "-store", "-path", "-port", "-mode" }; String[] defaults = new String[] { "store", "./data", "6900", "0" }; String[] paras = getOpts(args, opts, defaults); String store = paras[0];/*from w w w.j a v a 2 s . c o m*/ int port = Integer.valueOf(paras[2]); String path = paras[1]; int mode = Integer.valueOf(paras[3]); CacheStore cacheStore = new CacheStore(path, null, 0, store, false, mode); HashMap<String, CacheStore> storesMap = new HashMap<String, CacheStore>(); storesMap.put(store, cacheStore); logger.info("start server at " + port); ReplicaServer server = new ReplicaServer(port, storesMap); }
From source file:com.akana.demo.freemarker.templatetester.TestXML.java
public static void main(String[] args) throws Exception { /* You should do this ONLY ONCE in the whole application life-cycle: */ /* Create and adjust the configuration singleton */ Configuration cfg = new Configuration(Configuration.VERSION_2_3_22); cfg.setDirectoryForTemplateLoading(new File("/Users/ian.goldsmith/projects/freemarker")); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); /*//from ww w . j a v a 2 s . c om * You usually do these for MULTIPLE TIMES in the application * life-cycle: */ /* Create a data-model */ Map message = new HashMap(); message.put("contentAsXml", freemarker.ext.dom.NodeModel.parse(new File("/Users/ian.goldsmith/projects/freemarker/test.xml"))); Map root = new HashMap(); root.put("message", message); /* Get the template (uses cache internally) */ Template temp = cfg.getTemplate("testxml.ftl"); /* Merge data-model with template */ Writer out = new OutputStreamWriter(System.out); temp.process(root, out); // Note: Depending on what `out` is, you may need to call `out.close()`. // This is usually the case for file output, but not for servlet output. }
From source file:com.akana.demo.freemarker.templatetester.TestJSON.java
public static void main(String[] args) throws Exception { /* You should do this ONLY ONCE in the whole application life-cycle: */ /* Create and adjust the configuration singleton */ Configuration cfg = new Configuration(Configuration.VERSION_2_3_22); cfg.setDirectoryForTemplateLoading(new File("/Users/ian.goldsmith/projects/freemarker")); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); /*//from w ww. j av a 2 s . c o m * You usually do these for MULTIPLE TIMES in the application * life-cycle: */ /* Create a data-model */ Map message = new HashMap(); message.put("contentAsString", FileUtils.readFileToString( new File("/Users/ian.goldsmith/projects/freemarker/test.json"), StandardCharsets.UTF_8)); Map root = new HashMap(); root.put("message", message); /* Get the template (uses cache internally) */ Template temp = cfg.getTemplate("testjson.ftl"); /* Merge data-model with template */ Writer out = new OutputStreamWriter(System.out); temp.process(root, out); // Note: Depending on what `out` is, you may need to call `out.close()`. // This is usually the case for file output, but not for servlet output. }
From source file:invoice.GetInvoice.java
/** * @param args the command line arguments *//* w w w. jav a2 s. c o m*/ public static void main(String[] args) { NumberFormat nf = NumberFormat.getInstance(); nf.setGroupingUsed(false); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); nf.setRoundingMode(RoundingMode.HALF_UP); try { JSONObject arg_json = new JSONObject(args[0]); } catch (JSONException ex) { Logger.getLogger(GetInvoice.class.getName()).log(Level.SEVERE, null, ex); } HashMap<String, Object> hm = new HashMap<>(); hm.put("duplicate", ""); hm.put("distributor", "//oshan" + "\n" + "//kapuhempala" + "\n\nArea: " + "//galle"); hm.put("customer", "//owner" + "\n" + "//Agro" + "\n" + "//Agro add" + "\n" + "//0771894851"); hm.put("invNo", "GSLTS" + String.format("%04d", Integer.parseInt("//100"))); hm.put("invDate", "2014-01-10"); hm.put("invCode", "300"); double invoiceTotal = 500000; if (5 > 0) {//ShopDiscount double discountprice = (invoiceTotal * 99) / 100;//getShopDiscount() hm.put("invoiceDiscount", nf.format((invoiceTotal) * 99 / 100));//getRetail_discount() } else { hm.put("invoiceDiscount", ""); } hm.put("gross_total", nf.format(invoiceTotal)); hm.put("invoiceTotal", nf.format(((invoiceTotal) * (100 - 99) / 100)));//getRetail_discount() hm.put("salesPersonName", "rep"); hm.put("salesPersonContactNo", "0772189584"); JTable jTable1 = new JTable(); jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {}, new String[] { "ITEMCODE", "DESCRIPTION", "QTY", "FREEQTY", "PRICE", "AMOUNT" })); String reportSource = "./ireports/invoice.jrxml"; DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel(); try { JasperReport jr = JasperCompileManager.compileReport(reportSource); JasperPrint jp = JasperFillManager.fillReport(jr, hm, new JRTableModelDataSource(dtm)); JasperPrintManager.printReport(jp, false); } catch (JRException ex) { Logger.getLogger(GetInvoice.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("1"); }
From source file:Naive.java
public static void main(String[] args) throws Exception { // Basic access authentication setup String key = "CHANGEME: YOUR_API_KEY"; String secret = "CHANGEME: YOUR_API_SECRET"; String version = "preview1"; // CHANGEME: the API version to use String practiceid = "000000"; // CHANGEME: the practice ID to use // Find the authentication path Map<String, String> auth_prefix = new HashMap<String, String>(); auth_prefix.put("v1", "oauth"); auth_prefix.put("preview1", "oauthpreview"); auth_prefix.put("openpreview1", "oauthopenpreview"); URL authurl = new URL("https://api.athenahealth.com/" + auth_prefix.get(version) + "/token"); HttpURLConnection conn = (HttpURLConnection) authurl.openConnection(); conn.setRequestMethod("POST"); // Set the Authorization request header String auth = Base64.encodeBase64String((key + ':' + secret).getBytes()); conn.setRequestProperty("Authorization", "Basic " + auth); // Since this is a POST, the parameters go in the body conn.setDoOutput(true);/* ww w . j a v a2 s .c o m*/ String contents = "grant_type=client_credentials"; DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); wr.writeBytes(contents); wr.flush(); wr.close(); // Read the response BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuilder sb = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { sb.append(line); } rd.close(); // Decode from JSON and save the token for later String response = sb.toString(); JSONObject authorization = new JSONObject(response); String token = authorization.get("access_token").toString(); // GET /departments HashMap<String, String> params = new HashMap<String, String>(); params.put("limit", "1"); // Set up the URL, method, and Authorization header URL url = new URL("https://api.athenahealth.com/" + version + "/" + practiceid + "/departments" + "?" + urlencode(params)); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Authorization", "Bearer " + token); rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); sb = new StringBuilder(); while ((line = rd.readLine()) != null) { sb.append(line); } rd.close(); response = sb.toString(); JSONObject departments = new JSONObject(response); System.out.println(departments.toString()); // POST /appointments/{appointmentid}/notes params = new HashMap<String, String>(); params.put("notetext", "Hello from Java!"); url = new URL("https://api.athenahealth.com/" + version + "/" + practiceid + "/appointments/1/notes"); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Authorization", "Bearer " + token); // POST parameters go in the body conn.setDoOutput(true); contents = urlencode(params); wr = new DataOutputStream(conn.getOutputStream()); wr.writeBytes(contents); wr.flush(); wr.close(); rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); sb = new StringBuilder(); while ((line = rd.readLine()) != null) { sb.append(line); } rd.close(); response = sb.toString(); JSONObject note = new JSONObject(response); System.out.println(note.toString()); }