List of usage examples for java.util HashMap put
public V put(K key, V value)
From source file:ml.dmlc.xgboost4j.java.example.CustomObjective.java
public static void main(String[] args) throws XGBoostError { //load train mat (svmlight format) DMatrix trainMat = new DMatrix("../../demo/data/agaricus.txt.train"); //load valid mat (svmlight format) DMatrix testMat = new DMatrix("../../demo/data/agaricus.txt.test"); HashMap<String, Object> params = new HashMap<String, Object>(); params.put("eta", 1.0); params.put("max_depth", 2); params.put("silent", 1); //set round/*from ww w .j ava 2s . c o m*/ int round = 2; //specify watchList HashMap<String, DMatrix> watches = new HashMap<String, DMatrix>(); watches.put("train", trainMat); watches.put("test", testMat); //user define obj and eval IObjective obj = new LogRegObj(); IEvaluation eval = new EvalError(); //train a booster System.out.println("begin to train the booster model"); Booster booster = XGBoost.train(trainMat, params, round, watches, obj, eval); }
From source file:com.zenoss.zenpacks.zenjmx.ZenJmxMain.java
/** * @param args//from ww w . j av a 2 s.co m */ public static void main(String[] args) throws Exception { HashMap<String, Level> loggingLevel = new HashMap<String, Level>(); loggingLevel.put(ERROR, Level.ERROR); loggingLevel.put(WARNING, Level.WARN); loggingLevel.put(INFO, Level.INFO); loggingLevel.put(DEBUG, Level.DEBUG); Configuration config = Configuration.instance(); parseArguments(config, args); if (config.propertyExists(OptionsFactory.LOG_SEVERITY)) { String levelOpt = config.getProperty(OptionsFactory.LOG_SEVERITY); Level level = loggingLevel.get(levelOpt); if (level != null) { _logger.info("setting root logger to " + level); Logger.getRootLogger().setLevel(level); } else { _logger.warn("Ignoring unknown log severity " + levelOpt); } } String port = config.getProperty(OptionsFactory.LISTEN_PORT, OptionsFactory.DEFAULT_LISTENPORT); Server server = new Server(); Connector connector = new SocketConnector(); connector.setPort(Integer.parseInt(port)); server.setConnectors(new Connector[] { connector }); ServletHandler handler = new ServletHandler(); ServletHolder holder = new ServletHolder(new XmlRpcServlet()); handler.addServletWithMapping(holder, "/"); // handler.start(); handler.initialize(); server.setHandler(handler); try { server.start(); } catch (Exception e) { System.exit(10); } server.join(); }
From source file:Main.java
public static void main(String[] args) { ReferenceQueue referenceQueue = new ReferenceQueue(); Object object = new Object() { public String toString() { return "Referenced Object"; }//from w w w . jav a 2 s . c o m }; Object data = new Object() { public String toString() { return "Data"; } }; HashMap map = new HashMap(); Reference reference = null; System.out.println("Testing WeakReference."); reference = new WeakReference(object, referenceQueue); map.put(reference, data); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); System.gc(); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); object = null; data = null; System.gc(); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); }
From source file:Main.java
public static void main(String[] args) { ReferenceQueue referenceQueue = new ReferenceQueue(); Object object = new Object() { public String toString() { return "Referenced Object"; }/*from ww w . j a v a 2 s.c o m*/ }; Object data = new Object() { public String toString() { return "Data"; } }; HashMap map = new HashMap(); Reference reference = null; System.out.println("Testing PhantomReference."); reference = new PhantomReference(object, referenceQueue); map.put(reference, data); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); System.gc(); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); object = null; data = null; System.gc(); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); }
From source file:contractEditor.contractHOST1.java
public static void main(String[] args) { JSONObject obj = new JSONObject(); obj.put("name", "HOST1"); obj.put("context", "VM-deployment"); //obj.put("Context", new Integer); HashMap serviceDescription = new HashMap(); serviceDescription.put("location", "France"); serviceDescription.put("certificate", "true"); serviceDescription.put("volume", "100_GB"); serviceDescription.put("price", "6_euro"); obj.put("serviceDescription", serviceDescription); HashMap gauranteeTerm = new HashMap(); gauranteeTerm.put("availability", "more_98_percentage"); obj.put("gauranteeTerm", gauranteeTerm); //Constraint1 HashMap host_rule1 = new HashMap(); HashMap VM_rule1 = new HashMap(); host_rule1.put("ID", "HOST1"); VM_rule1.put("purpose", "test"); ArrayList rule1 = new ArrayList(); rule1.add("prohibition"); rule1.add(host_rule1);//w w w. ja v a 2 s. c o m rule1.add(VM_rule1); ArrayList policyInConstraint1 = new ArrayList(); policyInConstraint1.add(rule1); ArrayList creationConstraint1 = new ArrayList(); creationConstraint1.add("other"); creationConstraint1.add("true"); creationConstraint1.add("true"); creationConstraint1.add(policyInConstraint1); ArrayList totalConstraint = new ArrayList(); totalConstraint.add(creationConstraint1); obj.put("creationConstraint", totalConstraint); try { FileWriter file = new FileWriter("confSP" + File.separator + "Host1.json"); file.write(obj.toJSONString()); file.flush(); file.close(); } catch (IOException e) { e.printStackTrace(); } System.out.print(obj); /* JSONParser parser = new JSONParser(); try { Object obj2 = parser.parse(new FileReader("confSP\\confHost1.json")); JSONObject jsonObject = (JSONObject) obj2; HashMap serviceDescription2=(HashMap) jsonObject.get("serviceDescription"); method.printHashMap(serviceDescription2); HashMap gauranteeTerm2=(HashMap) jsonObject.get("gauranteeTerm"); method.printHashMap(gauranteeTerm2); ArrayList creationConstraint=(ArrayList) jsonObject.get("creationConstraint"); method.printArrayList(creationConstraint); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } */ }
From source file:contractEditor.contractHOST2.java
public static void main(String[] args) { JSONObject obj = new JSONObject(); obj.put("name", "HOST2"); obj.put("context", "VM-deployment"); //obj.put("Context", new Integer); HashMap serviceDescription = new HashMap(); serviceDescription.put("location", "UK"); serviceDescription.put("certificate", "false"); serviceDescription.put("volume", "200_GB"); serviceDescription.put("price", "5_euro"); obj.put("serviceDescription", serviceDescription); HashMap gauranteeTerm = new HashMap(); gauranteeTerm.put("availability", "more_99_percentage"); obj.put("gauranteeTerm", gauranteeTerm); //Constraint1 HashMap host_rule1 = new HashMap(); HashMap VM_rule1 = new HashMap(); host_rule1.put("ID", "HOST2"); VM_rule1.put("data", "private"); ArrayList rule1 = new ArrayList(); rule1.add("prohibition"); rule1.add(host_rule1);// www . j av a2 s .c o m rule1.add(VM_rule1); ArrayList policyInConstraint1 = new ArrayList(); policyInConstraint1.add(rule1); ArrayList creationConstraint1 = new ArrayList(); creationConstraint1.add("other"); creationConstraint1.add("true"); creationConstraint1.add("true"); creationConstraint1.add(policyInConstraint1); ArrayList totalConstraint = new ArrayList(); totalConstraint.add(creationConstraint1); obj.put("creationConstraint", totalConstraint); try { FileWriter file = new FileWriter("confSP" + File.separator + "Host2.json"); file.write(obj.toJSONString()); file.flush(); file.close(); } catch (IOException e) { e.printStackTrace(); } System.out.print(obj); /* JSONParser parser = new JSONParser(); try { Object obj2 = parser.parse(new FileReader("confSP\\confHost1.json")); JSONObject jsonObject = (JSONObject) obj2; HashMap serviceDescription2=(HashMap) jsonObject.get("serviceDescription"); method.printHashMap(serviceDescription2); HashMap gauranteeTerm2=(HashMap) jsonObject.get("gauranteeTerm"); method.printHashMap(gauranteeTerm2); ArrayList creationConstraint=(ArrayList) jsonObject.get("creationConstraint"); method.printArrayList(creationConstraint); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } */ }
From source file:contractEditor.contractHOST3.java
public static void main(String[] args) { JSONObject obj = new JSONObject(); obj.put("name", "HOST3"); obj.put("context", "VM-deployment"); //obj.put("Context", new Integer); HashMap serviceDescription = new HashMap(); serviceDescription.put("location", "China"); serviceDescription.put("certificate", "false"); serviceDescription.put("volume", "70_GB"); serviceDescription.put("price", "4_euro"); obj.put("serviceDescription", serviceDescription); HashMap gauranteeTerm = new HashMap(); gauranteeTerm.put("availability", "more_97_percentage"); obj.put("gauranteeTerm", gauranteeTerm); //Constraint1 HashMap host_rule1 = new HashMap(); HashMap VM_rule1 = new HashMap(); host_rule1.put("ID", "HOST3"); VM_rule1.put("application", "internal"); ArrayList rule1 = new ArrayList(); rule1.add("prohibition"); rule1.add(host_rule1);//from w w w . ja v a2 s . c o m rule1.add(VM_rule1); ArrayList policyInConstraint1 = new ArrayList(); policyInConstraint1.add(rule1); ArrayList creationConstraint1 = new ArrayList(); creationConstraint1.add("other"); creationConstraint1.add("true"); creationConstraint1.add("true"); creationConstraint1.add(policyInConstraint1); ArrayList totalConstraint = new ArrayList(); totalConstraint.add(creationConstraint1); obj.put("creationConstraint", totalConstraint); try { FileWriter file = new FileWriter("confSP" + File.separator + "Host3.json"); file.write(obj.toJSONString()); file.flush(); file.close(); } catch (IOException e) { e.printStackTrace(); } System.out.print(obj); /* JSONParser parser = new JSONParser(); try { Object obj2 = parser.parse(new FileReader("confSP\\confHost1.json")); JSONObject jsonObject = (JSONObject) obj2; HashMap serviceDescription2=(HashMap) jsonObject.get("serviceDescription"); method.printHashMap(serviceDescription2); HashMap gauranteeTerm2=(HashMap) jsonObject.get("gauranteeTerm"); method.printHashMap(gauranteeTerm2); ArrayList creationConstraint=(ArrayList) jsonObject.get("creationConstraint"); method.printArrayList(creationConstraint); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } */ }
From source file:Main.java
public static void main(String[] args) { HashMap<Character, Integer> map = new HashMap<Character, Integer>(); String test = "BUNANA"; char[] chars = test.toCharArray(); for (int i = 0; i < chars.length; i++) { if (!map.containsKey(chars[i])) { map.put(chars[i], 1); }// ww w . j a v a2s .c o m map.put(chars[i], map.get(chars[i]) + 1); } System.out.println(map.toString()); }
From source file:zz.pseas.ghost.login.taobao.MTaobaoLogin.java
public static void main(String[] args) throws UnsupportedEncodingException { String tbuserNmae = "TBname"; String tbpassWord = "TBpasssword"; GhostClient iPhone = new GhostClient("utf-8"); String ans = iPhone.get("https://login.m.taobao.com/login.htm"); Document doc = Jsoup.parse(ans); String url = doc.select("form#loginForm").first().attr("action"); String _tb_token = doc.select("input[name=_tb_token_]").first().attr("value"); String sid = doc.select("input[name=sid]").first().attr("value"); System.out.println(_tb_token); System.out.println(sid);/* www. j a va2s .co m*/ System.out.println(url); HashMap<String, String> map = new HashMap<String, String>(); map.put("TPL_password", tbpassWord); map.put("TPL_username", tbuserNmae); map.put("_tb_token_", _tb_token); map.put("action", "LoginAction"); map.put("event_submit_do_login", "1"); map.put("loginFrom", "WAP_TAOBAO"); map.put("sid", sid); String location = null; while (true) { CommonsPage commonsPage = iPhone.postForPage(url, map); location = commonsPage.getHeader("Location"); String postAns = new String(commonsPage.getContents(), "utf-8"); if (StringUtil.isNotEmpty(location) && StringUtil.isEmpty(postAns)) { break; } String s = Jsoup.parse(postAns).select("img.checkcode-img").first().attr("src"); String imgUrl = "https:" + s; byte[] bytes = iPhone.getBytes(imgUrl); FileUtil.writeFile(bytes, "g:/tbCaptcha.jpg"); String wepCheckId = Jsoup.parse(postAns).select("input[name=wapCheckId]").val(); String captcha = null; map.put("TPL_checkcode", captcha); map.put("wapCheckId", wepCheckId); } iPhone.get(location); String tk = iPhone.getCookieValue("_m_h5_tk"); if (StringUtil.isNotEmpty(tk)) { tk = tk.split("_")[0]; } else { tk = "undefined"; } String url2 = genUrl(tk); String ans1 = iPhone.get(url2); System.out.println(url2); System.out.println(ans1); tk = iPhone.getCookieValue("_m_h5_tk").split("_")[0]; if (StringUtil.isEmpty(tk)) { tk = "undefined"; } System.out.println(tk); url2 = genUrl(tk); iPhone.showCookies(); RequestConfig requestConfig = RequestConfig.custom().setProxy(new HttpHost("127.0.0.1", 8888)).build(); HttpUriRequest get = RequestBuilder.get().setConfig(requestConfig) //.addHeader("User-Agent","Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16") .addHeader("Host", "api.m.taobao.com").setUri(url2).build(); ans1 = iPhone.execute(get); System.out.println(ans1); }
From source file:com.knowbout.epg.FakeUpdate.java
public static void main(String[] args) { String configFile = "/etc/knowbout.tv/epg.xml"; int nextarg = 0; if (args.length > 1) { if (args.length == 3 && args[0].equals("-config")) { configFile = args[1];/*from w w w . jav a2s . c o m*/ nextarg = 2; } else { System.err.println( "Usage: java " + FakeUpdate.class.getName() + " [-config <xmlfile>] <program title>"); System.exit(1); } } if (args.length <= nextarg) { System.err .println("Usage: java " + FakeUpdate.class.getName() + " [-config <xmlfile>] <program title>"); System.exit(1); } String title = args[nextarg]; try { XMLConfiguration config = new XMLConfiguration(configFile); HashMap<String, String> hibernateProperties = new HashMap<String, String>(); Configuration database = config.subset("database"); hibernateProperties.put(Environment.DRIVER, database.getString("driver")); hibernateProperties.put(Environment.URL, database.getString("url")); hibernateProperties.put(Environment.USER, database.getString("user")); hibernateProperties.put(Environment.PASS, database.getString("password")); hibernateProperties.put(Environment.DATASOURCE, null); HibernateUtil.setProperties(hibernateProperties); Session session = HibernateUtil.openSession(); Transaction tx = session.beginTransaction(); String hqlUpdate = "update Program set lastModified = :now where title = :title"; int updatedEntities = session.createQuery(hqlUpdate).setTimestamp("now", new Date()) .setString("title", title).executeUpdate(); tx.commit(); session.close(); String alertUrl = config.getString("alertUrl"); HessianProxyFactory factory = new HessianProxyFactory(); AlertQueue alerts = (AlertQueue) factory.create(AlertQueue.class, alertUrl); alerts.checkAlerts(); } catch (ConfigurationException e) { log.fatal("Configuration error in file " + configFile, e); } catch (IOException e) { log.fatal("Error downloading or processing EPG information", e); } }