List of usage examples for java.util List size
int size();
From source file:DbUtilsUseBeanMySQL.java
public static void main(String[] args) { Connection conn = null;// w w w . j av a 2s.c om String jdbcURL = "jdbc:mysql://localhost/octopus"; String jdbcDriver = "com.mysql.jdbc.Driver"; String user = "root"; String password = "root"; try { DbUtils.loadDriver(jdbcDriver); conn = DriverManager.getConnection(jdbcURL, user, password); QueryRunner qRunner = new QueryRunner(); List beans = (List) qRunner.query(conn, "select id, name from animals_table", new BeanListHandler(Employee.class)); for (int i = 0; i < beans.size(); i++) { Employee bean = (Employee) beans.get(i); bean.print(); } } catch (SQLException e) { // handle the exception e.printStackTrace(); } finally { DbUtils.closeQuietly(conn); } }
From source file:edu.msu.cme.rdp.taxatree.TreeBuilder.java
public static void main(String[] args) throws IOException { if (args.length != 3) { System.err.println("USAGE: TreeBuilder <idmapping> <merges.bin> <newick_out>"); return;/*from w w w . j a v a 2 s. co m*/ } IdMapping<Integer> idMapping = IdMapping.fromFile(new File(args[0])); DataInputStream mergeStream = new DataInputStream(new BufferedInputStream(new FileInputStream(args[1]))); TaxonHolder lastMerged = null; int taxid = 0; final Map<Integer, Double> distMap = new HashMap(); Map<Integer, TaxonHolder> taxonMap = new HashMap(); try { while (true) { if (mergeStream.readBoolean()) { // Singleton int cid = mergeStream.readInt(); int intId = mergeStream.readInt(); TaxonHolder<Taxon> holder; List<String> seqids = idMapping.getIds(intId); if (seqids.size() == 1) { holder = new TaxonHolder(new Taxon(taxid++, seqids.get(0), "")); } else { holder = new TaxonHolder(new Taxon(taxid++, "", "")); for (String seqid : seqids) { int id = taxid++; distMap.put(id, 0.0); TaxonHolder th = new TaxonHolder(new Taxon(id, seqid, "")); th.setParent(holder); holder.addChild(th); } } lastMerged = holder; taxonMap.put(cid, holder); } else { int ci = mergeStream.readInt(); int cj = mergeStream.readInt(); int ck = mergeStream.readInt(); double dist = (double) mergeStream.readInt() / DistanceCalculator.MULTIPLIER; TaxonHolder holder = new TaxonHolder(new Taxon(taxid++, "", "")); taxonMap.put(ck, holder); holder.addChild(taxonMap.get(ci)); taxonMap.get(ci).setParent(holder); distMap.put(ci, dist); holder.addChild(taxonMap.get(cj)); taxonMap.get(cj).setParent(holder); distMap.put(cj, dist); lastMerged = holder; } } } catch (EOFException e) { } if (lastMerged == null) { throw new IOException("No merges in file"); } PrintStream newickTreeOut = new PrintStream(new File(args[2])); NewickPrintVisitor visitor = new NewickPrintVisitor(newickTreeOut, false, new NewickDistanceFactory() { public float getDistance(int i) { return distMap.get(i).floatValue(); } }); lastMerged.biDirectionDepthFirst(visitor); newickTreeOut.close(); }
From source file:net.oneandone.shared.artifactory.App.java
public static void main(String[] args) throws ParseException, IOException, NotFoundException { initLogging();/* w ww . ja v a 2 s. c om*/ LOG.info("CLI: {}", Arrays.toString(args)); final Options options = new Options() .addOption("l", "uri", true, "Base-URI in the form of " + DEFAULT_ARTIFACTORY_URI) .addOption("u", "user", true, "Username").addOption("p", "password", true, "Password") .addOption("d", "debug", false, "Turn on debugging"); final CommandLine commandline = new BasicParser().parse(options, args); if (commandline.hasOption("d")) { LOG.info("Setting debug"); java.util.logging.Logger.getLogger("net.oneandone.shared.artifactory").setLevel(Level.ALL); } final List<String> argList = commandline.getArgList(); LOG.info("ARGS: {}", argList); Injector injector = Guice.createInjector(new ArtifactoryModule()); App instance = injector.getInstance(App.class); instance.preemptiveRequestInterceptor.addCredentialsForHost("web.de", "foo", "bar"); List<ArtifactoryStorage> search = instance.searchByGav.search("repo1-cache", Gav.valueOf(argList.get(0))); LOG.info("Got {} search results", search.size()); }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("Java"); list.add("Oracle"); list.add("CSS"); list.add("XML"); System.out.println("List: " + list); int count = list.size(); System.out.println("Size of List: " + count); // Print each element with its index for (int i = 0; i < count; i++) { String element = list.get(i); System.out.println("Index=" + i + ", Element=" + element); }// w w w . jav a 2s .c o m List<String> subList = list.subList(1, 3); System.out.println(subList); // Remove "CSS" from the list list.remove("CSS"); // Same as list.remove(2); System.out.println(list); }
From source file:io.rhiot.spec.IoTSpec.java
public static void main(String[] args) throws Exception { CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption(Option.builder("c").longOpt(CONFIG).desc( "Location of the test configuration file. A default value is 'src/main/resources/test.yaml' for easy IDE testing") .hasArg().build());/* w ww .j ava2s . c om*/ options.addOption(Option.builder("i").longOpt(INSTANCE).desc("Instance of the test; A default value is 1") .hasArg().build()); options.addOption(Option.builder("r").longOpt(REPORT) .desc("Location of the test report. A default value is 'target/report.csv'").hasArg().build()); CommandLine line = parser.parse(options, args); ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); TestProfile test = mapper.readValue(new File(line.getOptionValue(CONFIG, "src/main/resources/test.yaml")), TestProfile.class); int instance = Integer.valueOf(line.getOptionValue(INSTANCE, "1")); test.setInstance(instance); String report = line.getOptionValue(REPORT, "target/report.csv"); test.setReport(new CSVReport(report)); LOG.info("Test '" + test.getName() + "' instance " + instance + " started"); final List<Driver> drivers = test.getDrivers(); ExecutorService executorService = Executors.newFixedThreadPool(drivers.size()); List<Future<Void>> results = executorService.invokeAll(drivers, test.getDuration(), TimeUnit.MILLISECONDS); executorService.shutdownNow(); executorService.awaitTermination(5, TimeUnit.SECONDS); results.forEach(result -> { try { result.get(); } catch (ExecutionException execution) { LOG.warn("Exception running driver", execution); } catch (Exception interrupted) { } }); drivers.forEach(driver -> { driver.stop(); try { test.getReport().print(driver); } catch (Exception e) { LOG.warn("Failed to write reports for the driver " + driver); } LOG.debug("Driver " + driver); LOG.debug("\t " + driver.getResult()); }); test.getReport().close(); LOG.info("Test '" + test.getName() + "' instance " + instance + " finished"); }
From source file:edu.berkeley.path.next.CTMEngine.CTMEngineApp.java
public static void main(String[] args) throws InterruptedException { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ctm-engine.xml"); context.start();//from w w w. java 2s.com final Logger logger = LogManager.getLogger(CTMEngineApp.class.getName()); logger.info("trafficMonitorApp initialized "); JmsPublish jmsPublish = context.getBean(JmsPublish.class); // linkManager creates the data to publish representing ccFramework output LinkManager linkManager = context.getBean(LinkManager.class); logger.info("trafficMonitorApp initialized "); //get a list of output links that we will publish over and over java.util.List<LinkDataRaw> links = new ArrayList<LinkDataRaw>(); links = linkManager.getLinkList(); logger.info("trafficMonitorApp links to publish: " + links.size()); //counters int x = 0; int oneHour = 216000; int oneMinute = 3600; while (x < oneMinute) { //use SLF interface which provides for parameterized logging logger.info("CTMEngineApp sendLinkList counter: " + x); jmsPublish.sendLinkList(links); //sleep for a third of a second //Thread.sleep(10); x++; } }
From source file:com.packtpub.mahout.cookbook.chapter01.App.java
public static void main(String[] args) throws IOException, TasteException, OptionException { CreateCsvRatingsFile();/*from w w w. ja va 2s. co m*/ // create data source (model) - from the csv file File ratingsFile = new File(outputFile); DataModel model = new FileDataModel(ratingsFile); // create a simple recommender on our data CachingRecommender cachingRecommender = new CachingRecommender(new SlopeOneRecommender(model)); // for all users for (LongPrimitiveIterator it = model.getUserIDs(); it.hasNext();) { long userId = it.nextLong(); // get the recommendations for the user List<RecommendedItem> recommendations = cachingRecommender.recommend(userId, 10); // if empty write something if (recommendations.size() == 0) { System.out.print("User "); System.out.print(userId); System.out.println(": no recommendations"); } // print the list of recommendations for each for (RecommendedItem recommendedItem : recommendations) { System.out.print("User "); System.out.print(userId); System.out.print(": "); System.out.println(recommendedItem); } } }
From source file:com.termmed.sampling.ConceptsWithMoreThanThreeRoleGroups.java
/** * The main method.//ww w. j a v a 2 s. c o 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:it.crs4.features.MergeImgSets.java
public static void main(String[] args) throws Exception { Options opts = new Options(); CommandLine cmd = null;//from w w w. j a v a2s. c o m try { cmd = parseCmdLine(opts, args); } catch (ParseException e) { System.err.println("ERROR: " + e.getMessage()); System.exit(1); } String[] posArgs = cmd.getArgs(); if (posArgs.length < 2) { HelpFormatter fmt = new HelpFormatter(); fmt.printHelp("java MergeImgSets IMG_SET_LIST OUT_FN", opts); System.exit(2); } String setsFn = posArgs[0]; String outFn = posArgs[1]; int replication = 1; if (cmd.hasOption("replication")) { replication = Integer.parseInt(cmd.getOptionValue("replication")); } List<List<String>> filesets = getFilesets(setsFn); int sizeZ = filesets.size(); if (0 == sizeZ) { System.out.println("File set list is empty, nothing to do."); System.exit(0); } int sizeC = filesets.get(0).size(); for (List<String> fs : filesets) { if (fs.size() != sizeC) { System.err.println("File sets must have equal size"); System.exit(1); } } write(filesets, outFn, replication); }
From source file:com.aerospike.examples.pk.StorePrimaryKey.java
public static void main(String[] args) throws AerospikeException { try {/*from ww w . jav a 2 s .c om*/ Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: 172.28.128.6)"); options.addOption("p", "port", true, "Server port (default: 3000)"); options.addOption("n", "namespace", true, "Namespace (default: test)"); options.addOption("s", "set", true, "Set (default: demo)"); options.addOption("u", "usage", false, "Print usage."); CommandLineParser parser = new PosixParser(); CommandLine cl = parser.parse(options, args, false); String host = cl.getOptionValue("h", "172.28.128.6"); String portString = cl.getOptionValue("p", "3000"); int port = Integer.parseInt(portString); String namespace = cl.getOptionValue("n", "test"); String set = cl.getOptionValue("s", "demo"); log.debug("Host: " + host); log.debug("Port: " + port); log.debug("Namespace: " + namespace); log.debug("Set: " + set); @SuppressWarnings("unchecked") List<String> cmds = cl.getArgList(); if (cmds.size() == 0 && cl.hasOption("u")) { logUsage(options); return; } StorePrimaryKey as = new StorePrimaryKey(host, port, namespace, set); as.work(); } catch (Exception e) { log.error("Critical error", e); } }