List of usage examples for java.util ArrayList ArrayList
public ArrayList()
From source file:Person.java
public static void main(String args[]) { ArrayList<Person> names = new ArrayList<Person>(); names.add(new Person("E", "T")); names.add(new Person("A", "G")); names.add(new Person("B", "H")); names.add(new Person("C", "J")); Iterator iter1 = names.iterator(); while (iter1.hasNext()) { System.out.println(iter1.next()); }//from w w w . java 2 s.c o m Collections.sort(names, new PersonComparator()); Iterator iter2 = names.iterator(); while (iter2.hasNext()) { System.out.println(iter2.next()); } }
From source file:Person.java
public static void main(String args[]) { ArrayList<Person> names = new ArrayList<Person>(); names.add(new Person("E", "T")); names.add(new Person("A", "G")); names.add(new Person("B", "H")); names.add(new Person("C", "J")); Iterator iter1 = names.iterator(); while (iter1.hasNext()) { System.out.println(iter1.next()); }//w w w . j a v a 2s . co m System.out.println("Before sorting"); Collections.sort(names, new PersonComparator()); Iterator iter2 = names.iterator(); while (iter2.hasNext()) { System.out.println(iter2.next()); } }
From source file:com.apress.prospringintegration.springenterprise.stocks.runner.MainRmiClient.java
public static void main(String[] args) { GenericApplicationContext context = new AnnotationConfigApplicationContext( "com.apress.prospringintegration.springenterprise.stocks.client"); QuoteServiceClient client = context.getBean("client", QuoteServiceClient.class); List<Quote> myQuotes = new ArrayList<Quote>(); myQuotes.add(client.getMyQuote("APRESS")); myQuotes.add(client.getMyQuote("SPRNG")); myQuotes.add(client.getMyQuote("INTGRN")); for (Quote myQuote : myQuotes) { System.out.println("Symbol : " + myQuote.getSymbol()); System.out.println("Price :" + myQuote.getPrice()); System.out.println("Exchange: " + myQuote.getExchangeId()); }/*from w w w .j a v a2s . c o m*/ }
From source file:com.ywh.train.Test.java
public static void main(String[] args) throws Exception { List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("includeStudent", "00")); parameters.add(new BasicNameValuePair("orderRequest.from_station_telecode", "SHH")); parameters.add(new BasicNameValuePair("orderRequest.start_time_str", "00:00--24:00")); parameters.add(new BasicNameValuePair("orderRequest.to_station_telecode", "CSQ")); parameters.add(new BasicNameValuePair("orderRequest.train_date", "2011-11-24")); parameters.add(new BasicNameValuePair("orderRequest.train_no", "")); parameters.add(new BasicNameValuePair("seatTypeAndNum", "")); parameters.add(new BasicNameValuePair("trainClass", "QB#D#Z#T#K#QT#")); parameters.add(new BasicNameValuePair("trainPassType", "QB")); String responseBody = "0,<span id='id_5l0000D10502' class='base_txtdiv' onmouseover=javascript:onStopHover('5l0000D10502#AOH#CSQ') onmouseout='onStopOut()'>D105</span>,<img src='/otsweb/images/tips/first.gif'> <br> 09:08,<img src='/otsweb/images/tips/last.gif'> <br> 18:21,09:13,--,--,<font color='darkgray'></font>,<font color='#008800'></font>,--,--,--,--,--,--,--,<input type='button' class='yuding_u' onmousemove=this.className='yuding_u_over' onmousedown=this.className='yuding_u_down' onmouseout=this.className='yuding_u' onclick=javascript:getSelected('D105#553#09:08#5l0000D10502#AOH#CSQ') value=''></input>," + "<span id='id_5l0000D10502' class='base_txtdiv' onmouseover=javascript:onStopHover('5l0000D10502#EPH#PXG') onmouseout='onStopOut()'>D105</span>, ? <br> 09:38, ?? <br> 17:09,07:31,--,--,<font color='darkgray'></font>,<font color='darkgray'></font>,--,--,--,--,--,--,--,<input type='button' class='yuding_x' value=''></input>"; List<TrainQueryInfo> tqis = Util.parserQueryInfo(responseBody); for (TrainQueryInfo tqi : tqis) { System.out.println(tqi);/*from ww w . ja v a2 s . c o m*/ } String citys = "@bji||BJP|0@bjn|?|VNP|1@bjx||BXP|2@cqb|?|CUW|3@sha||SHH|4@shn|?|SNH|5@shq||AOH|6@shx||SXH|7@tji||TJP|8@tjn|?|TIP|9@tjx||TXP|10@cch||CCT|11@cdd|?|ICW|12@cdu|?|CDW|13@csh||CSQ|14@csn|?|CWQ|15@fzh|?|FZS|16@fzn|??|FYS|17@gzb||GBQ|18@gzd||GGQ|19@gzh||GZQ|20@gzn|?|IZQ|21@heb||HBB|22@hfe|?|HFH|23@hkd|?|HMQ|24@hko|?|VUQ|25@hzh|?|HZH|26@hzn|??|XHH|27@jna|?|JNK|28@jnd|?|JAK|29@jnx|?|JGK|30@lzh||LZJ|31@nch|?|NCG|32@nji|?|NJH|33@njn|??|NKH|34@sjb||VVP|35@sjz||SJP|36@sya||SYT|37@syb||SBT|38@tyu||TYV|39@wha||WHN|40@xab||EAY|41@xan||XAY|42@zzh||ZZF|43@aya||AYF|44@bbu||BBH|45@bji|?|BJY|46@cna|??|CEH|47@czh||CZH|48@djy||DDW|49@dli||DLT|50@dsq||DQT|51@dzh||RXW|52@fdi|?|FES|53@han||AUH|54@hda||HDP|55@hko|?|HKN|56@hnx|?|EUH|57@hsh||HSP|58@hsh||HSN|59@jan|?|VAG|60@jgs||JGG|61@jhx|?|JBH|62@jji|?|JJG|63@jli|?|JLL|64@jsh||JUH|65@kfe|?|KFF|66@ksn|?|KNH|67@lan||UAH|68@lhe||LON|69@ljy|?|LKP|70@lym||LLF|71@lzh||LZD|72@nbd|?|NVH|73@nch|?|NCW|74@nto|?|NUH|75@pxi|??|PXG|76@pxx||PCW|77@qcs|?|QSW|78@qda|?|QDK|79@qzh||QEH|80@qzh||QYS|81@shg||SHD|82@sni|??|NIW|83@spi||SPT|84@sqi||SQF|85@sra||SRG|86@sya|??|SNN|87@sya||SEQ|88@szh|?|SZN|89@szh|?|SZH|90@szh||SZQ|91@tgu||TGP|92@tli|?|TLT|93@tsb|?|FUP|94@tsh|?|TSP|95@wch||WCN|96@wfd||WDT|97@wna|?|WNY|98@wxi||WXH|99@wys||WAS|100@wzn|?|VRH|101@xch||XCF|102@xhu||EFQ|103@xmb||XKS|104@xme||XMS|105@xxi||XXF|106@xya||XUN|107@xya||XFN|108@xyu||XUG|109@xzh|?|XCH|110@yan||YWY|111@ych|?|AFH|112@ych||YCG|113@yta||YTG|114@ywu||YWH|115@yxi||YON|116@yzh||YLH|117@zbo|?|ZBK|118@zhb|?|ZIQ|119@zji||ZJH|120@zmd||ZDN|121@zzh||ZZQ|122@zzh||ZEK|123@zzx||ZFK|124@aji||ARH|125@atb||ASH|126@bao|?|BWQ|127@bbn|?|BMH|128@bdh||BEP|129@bdi|?|BDP|130@bhs|??|BWH|131@bji||IBQ|132@bji||BLQ|133@cbb|?|CIN|134@cle|?|CLK|135@czb||ESH|136@czh|?|CXH|137@czx||ICQ|138@czx||CBP|139@dan||DAG|140@dgu||DAQ|141@dsh|?|DRQ|142@dtu||RUH|143@dya||DYH|144@dyb||EXH|145@dyd||IAW|146@dyu||EWH|147@dzd||DIP|148@dzh||DXP|149@ezh||ECN|150@fan|?|FAS|151@fdo||FIH|152@fhu||FHH|153@fqi|?|FQS|154@gmi||GMK|155@gqc|?|GAG|156@gyn|?|GYF|157@gzh|?|GNQ|158@hax||HIH|159@hax||VXN|160@hch|??|WKW|161@hgz||IGW|162@hji||HJS|163@hlb||HPD|164@hni|?|HNH|165@hqi||VQH|166@hsb|?|HDY|167@hsh||VCH|168@hsx||HEQ|169@hyd||HVQ|170@hzh||VON|171@jji||JJS|172@jme||JWQ|173@jsb||EGH|174@jsn|?|EAH|175@jxi||JXH|176@jxn|?|EPH|177@jzb||JZK|178@jzh||JZH|179@jzn|?|JOD|180@lbx|??|LPF|181@lch|?|UCK|182@lfa|?|LJP|183@lha||UFH|184@lji||LKS|185@lsh|?|LSG|186@lsh||LIQ|187@lxi||UXP|188@lyo||LMH|189@lyu|?|LVS|190@lyx||LPQ|191@mcb||MBN|192@mcn|?|MNF|193@mla||MHQ|194@mld||MQQ|195@nde|?|NES|196@nha|?|NHH|197@nla|?|NNQ|198@nxb|?|NEH|199@pjb||PBD|200@pti||PTS|201@qfd||QAK|202@qha|?|QYQ|203@qji||INH|204@qsy||QYH|205@qyu||QBQ|206@qzs|?|QZK|207@ran||RAH|208@rch||RCG|209@rgu||RUQ|210@sde||ORQ|211@sfa|?|OLH|212@sgu||SNQ|213@sjn|??|IMH|214@slo||SLQ|215@smn|?|SCF|216@smx||OQH|217@sxi|?|SOH|218@syu||BDH|219@szb||SND|220@szb|?|OHH|221@szd||SRH|222@szq|?|ITH|223@szq|?|KAH|224@tan|?|TID|225@tan||TMK|226@tms||TLS|227@tna|?|TVW|228@txi|?|TCH|229@tzd||TEK|230@tzh|?|TZH|231@wch||WEQ|232@wfa|??|WFK|233@wli||VHH|234@wnb|?|WBY|235@wni|?|WNQ|236@wqi||WWP|237@wxd||WGH|238@wxq||IFH|239@xga|?|XGN|240@xla|?|EAQ|241@xli||XPH|242@xnb|?|XRN|243@xpu||XOS|244@xpu||XIW|245@xta|?|XTP|246@xzd|?|UUH|247@ych||AIH|248@yds|??|YGH|249@yha|?|EVH|250@yji||URH|251@ylw||TWQ|252@ylz|?|YSY|253@yqb||YPP|254@yqi|?|UPH|255@yxi||ACG|256@yya||YYH|257@yyd||YIQ|258@zji||ZDH|259@zjn|?|ZEH|260@zmt||ZOQ|261@zqi||ZTK|262@zsb||ZGQ|263@zsh||ZSQ|264@zzx||ZAQ|265"; String city[] = citys.split("@"); System.out.println("---------start--------"); for (String tmp : city) { System.out.println(tmp); } System.out.println("---------end--------"); //String test = "? ? ?? ? ? ? ? --> ?? ??? : 260.0()--> ? Sat Nov 26 14:04:16 CST 2011 1 ? ?? ? ? Mon Nov 28 00:00:00 CST 2011 D105 Thu Jan 01 09:08:00 CST 1970 02 052 ?, 260.0 ? --> --> ??"; String test = "1 vxv"; System.out.println(test.replaceAll("\\s", "")); }
From source file:com.dianping.dpsf.other.echo.EchoClient.java
/** * @param args// w w w .j a v a2s . co m * @throws Exception */ public static void main(String[] args) throws Exception { PigeonClientMock.setServiceAddress("127.0.0.1:20001,127.0.0.1:20002"); ApplicationContext ctx = new ClassPathXmlApplicationContext("echo-client.xml"); IEcho s = (IEcho) ctx.getBean("echo"); // System.out.println(s.echo("aa")); // Thread.sleep(3000); // System.out.println(s.echo("aa")); // System.out.println("firing"); Random rnd = new Random(System.currentTimeMillis()); List<String[]> hostList = new ArrayList<String[]>(); hostList.add(new String[] { "127.0.0.1", "20001", "1" }); PigeonClientMock.getSc().onServiceHostChange("http://service.dianping.com/echoService", hostList); int i = 0; while (i < 100) { try { System.out.println(s.echo("aa")); } catch (Exception e) { System.out.println("EEEEEEEEEEEEEEEEEEEEEEE"); } Thread.sleep(2000); if (i == 1) { System.out.println("+++++++++++++++++++adding 20002++++++++++++++++"); hostList = new ArrayList<String[]>(); hostList.add(new String[] { "127.0.0.1", "20001", "1" }); hostList.add(new String[] { "127.0.0.1", "20002", "1" }); PigeonClientMock.getSc().onServiceHostChange("http://service.dianping.com/echoService", hostList); } if (i == 5) { System.out.println("+++++++++++++++++++adding 20003++++++++++++++++"); hostList = new ArrayList<String[]>(); hostList.add(new String[] { "127.0.0.1", "20001", "1" }); hostList.add(new String[] { "192.168.32.111", "20003", "1" }); PigeonClientMock.getSc().onServiceHostChange("http://service.dianping.com/echoService", hostList); } if (i == 10) { System.out.println("--------------------change wt------------"); PigeonClientMock.getSc().onHostWeightChange("127.0.0.1", 2); } i++; } }
From source file:com.khartec.waltz.jobs.UserPreferenceHarness.java
public static void main(String[] args) throws ParseException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class); UserPreferenceDao userPreferenceDao = ctx.getBean(UserPreferenceDao.class); List<UserPreference> preferences = new ArrayList<UserPreference>() { {//from w w w . j a v a 2 s . c o m add(ImmutableUserPreference.builder().key("org-unit.section.technologies.collapsed").value("false") .build()); add(ImmutableUserPreference.builder().key("org-unit.section.indicators.collapsed").value("true") .build()); add(ImmutableUserPreference.builder().key("org-unit.section.logicalflows.collapsed").value("true") .build()); } }; // int result = userPreferenceDao.savePreferencesForUser("admin", preferences); // System.out.println("result: " + result); int result = userPreferenceDao.savePreference("admin", ImmutableUserPreference.builder() .key("org-unit.section.logicalflows.hidden").value("true").build()); System.out.println("result: " + result); // List<UserPreference> prefs = userPreferenceDao.getPreferencesForUser("admin"); // prefs.forEach(u -> System.out.printf("user: %s, key: %s, value: %s\r\n", u.userName(), u.key(), u.value())); // userPreferenceDao.clearPreferencesForUser("kamran"); }
From source file:eu.freme.bpt.Main.java
public static void main(String[] args) { final List<String> services = new ArrayList<>(); for (EService eService : EService.values()) { services.add(eService.getName()); }// w w w . j av a2s .co m Pair<EService, String[]> serviceAndArgs = extractService(args, services); EService service = serviceAndArgs.getName(); // create options that will be parsed from the args /////// General BPT options /////// Option helpOption = new Option("h", "help", false, "Prints this message"); Option inputOption = Option.builder("if").longOpt("input-file").argName("input file").desc( "The input file or directory to process. In case of a directory, each file in that directory is processed. " + "If not given, standard in is used.") .hasArg().build(); Option outputOption = Option.builder("od").longOpt("output-dir").argName("output dir") .desc("The output directory. If not given, output is written to standard out.").hasArg().build(); Option propertiesOption = Option.builder("prop").longOpt("properties").argName("properties file") .desc("The properties file that contains configuration of the tool.").hasArg().build(); Options options = new Options().addOption(helpOption).addOption(inputOption).addOption(outputOption) .addOption(propertiesOption); /////// Common service options /////// Option informatOption = Option.builder("f").longOpt("informat").argName("FORMAT") .desc("The format of the input document(s). Defaults to 'turtle'").hasArg().build(); Option outformatOption = Option.builder("o").longOpt("outformat").argName("FORMAT") .desc("The desired output format of the service. Defaults to 'turtle'").hasArg().build(); options.addOption(informatOption).addOption(outformatOption); /////// Service specific options /////// if (service != null) { switch (service) { case E_TRANSLATION: ETranslation.addOptions(options); break; case E_ENTITY: EEntity.addOptions(options); break; case E_LINK: ELink.addOptions(options); break; case E_TERMINOLOGY: ETerminology.addOptions(options); break; case PIPELINING: Pipelining.addOptions(options); break; case E_PUBLISHING: // TODO ! default: logger.warn("Unknown service {}. Skipping!", service); break; } } else { ETranslation.addOptions(options); EEntity.addOptions(options); ELink.addOptions(options); ETerminology.addOptions(options); Pipelining.addOptions(options); } CommandLine commandLine = null; int exitValue; try { CommandLineParser parser = new DefaultParser(); commandLine = parser.parse(options, serviceAndArgs.getValue()); exitValue = 0; } catch (ParseException e) { System.err.println(e.getMessage()); exitValue = 1; } if ((exitValue != 0) || commandLine.hasOption("h") || service == null) { HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(132); formatter.printHelp("java -jar <this jar file> <e-service> ", options, true); System.exit(exitValue); } logger.debug("Commandline successfully parsed!"); try { BPT batchProcessingTool = new BPT(); if (commandLine.hasOption("prop")) { batchProcessingTool.loadProperties(commandLine.getOptionValue("prop")); } if (commandLine.hasOption("if")) { batchProcessingTool.setInput(commandLine.getOptionValue("if")); } if (commandLine.hasOption("od")) { batchProcessingTool.setOutput(commandLine.getOptionValue("od")); } if (commandLine.hasOption('f')) { batchProcessingTool.setInFormat(Format.valueOf(commandLine.getOptionValue('f').replace('-', '_'))); } if (commandLine.hasOption('o')) { batchProcessingTool.setOutFormat(Format.valueOf(commandLine.getOptionValue('o').replace('-', '_'))); } switch (service) { case E_TRANSLATION: batchProcessingTool.eTranslation(commandLine.getOptionValue("source-lang"), commandLine.getOptionValue("target-lang"), commandLine.getOptionValue("system"), commandLine.getOptionValue("domain"), commandLine.getOptionValue("key")); break; case E_ENTITY: batchProcessingTool.eEntity(commandLine.getOptionValue("language"), commandLine.getOptionValue("dataset"), commandLine.getOptionValue("mode")); break; case E_LINK: batchProcessingTool.eLink(commandLine.getOptionValue("templateid")); break; case E_TERMINOLOGY: batchProcessingTool.eTerminology(commandLine.getOptionValue("source-lang"), commandLine.getOptionValue("target-lang"), commandLine.getOptionValue("collection"), commandLine.getOptionValue("domain"), commandLine.getOptionValue("key"), commandLine.getOptionValue("mode")); break; case PIPELINING: batchProcessingTool.pipelining(commandLine.getOptionValue("templateid")); break; case E_PUBLISHING: default: logger.error("Unknown service {}. Aborting!", service); System.exit(3); } } catch (Exception e) { logger.error("Cannot handle input or output. Reason: ", e); System.exit(2); } }
From source file:com.bitsofproof.supernode.main.Main.java
public static void main(String[] args) throws Exception { log.info("bitsofproof supernode (c) 2013 bits of proof zrt."); log.trace("Spring context setup"); if (args.length == 0) { System.err.println(//w w w. j a v a 2s . co m "Usage: java com.bitsofproof.main.Main profile [profile...] -- [args...] [options...]"); return; } GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); List<String> a = new ArrayList<String>(); boolean profiles = true; for (String s : args) { if (s.equals("--")) { profiles = false; } else { if (profiles) { log.info("Loading profile: " + s); ctx.getEnvironment().addActiveProfile(s); } else { a.add(s); } } } ctx.load("classpath:context/server.xml"); ctx.load("classpath:context/*-profile.xml"); ctx.refresh(); ctx.getBean(App.class).start(a.toArray(new String[0])); }
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;/*from ww w . j a va 2s . c o m*/ 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:org.bigtextml.drivers.BigMapTest.java
public static void main(String[] args) { /*//from www . j a v a2s. c o 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; //bm.setMaxCapacity(1000); for (int i = 0; i < max; i++) { List<Integer> x = new ArrayList<Integer>(); for (int j = 0; j < 5; j++) { x.add(j); } x.add(i); bm.put(Integer.toString(i), x); } 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(); }