List of usage examples for java.util List size
int size();
From source file:com.rdsic.pileconstructionmanagement.test.Test.java
public static void main(String[] args) { String sql = "select * from user"; List<Map<String, Object>> list = (ArrayList) GenericHql.INSTANCE.querySQL(sql, 20); if (!list.isEmpty()) { System.out.println("cnt:" + list.size()); JSONObject r = new JSONObject(); r.put("items", list); System.out.println(r.toString()); list.stream().map((item) -> { System.out.println("RECORD"); return item; }).forEach((item) -> {// w w w . j a v a 2 s . c o m for (String k : item.keySet()) { JSONObject j = new JSONObject(item); System.out.println(j.toString()); System.out.println(StringUtils.rightPad(k, 20, " ") + item.get(k).toString()); } }); } System.exit(0); }
From source file:DbUtilsUseMapMySQL.java
public static void main(String[] args) { Connection conn = null;/*from w w w.j av a2 s . c o m*/ 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 mapList = (List) qRunner.query(conn, "select id, name from animals_table", new MapListHandler()); for (int i = 0; i < mapList.size(); i++) { Map map = (Map) mapList.get(i); System.out.println("id=" + map.get("id")); System.out.println("name=" + map.get("name")); System.out.println("-----------------"); } System.out.println("DbUtils_UseMap_MySQL: end."); } catch (SQLException e) { // handle the exception e.printStackTrace(); } finally { DbUtils.closeQuietly(conn); } }
From source file:com.plexobject.testplayer.dao.hibernate.MethodDaoHibernate.java
public static void main(String[] args) throws Exception { MethodDaoHibernate dao = new MethodDaoHibernate(); createTable();/*from w w w . j a v a 2 s .co m*/ /* for (int i=0; i<10; i++) { MethodEntry method = new MethodEntry( 2000+i, 2000+i-1, "caller", "callee", "void main(String[] args)", new Object[] {"args"}, true, i); dao.save(method); } */ List<MethodEntry> list = dao.findAll(); System.out.println("Printing " + list.size() + ":\n" + list); if (list.size() > 0) { System.out.println("First " + dao.findById(list.get(0).getId())); } }
From source file:Main.java
public static void main(String... args) { try {/*from ww w . ja v a2s .com*/ Class<?> c = Class.forName(args[0]); out.format("Class:%n %s%n%n", c.getCanonicalName()); out.format("Modifiers:%n %s%n%n", Modifier.toString(c.getModifiers())); out.format("Type Parameters:%n"); TypeVariable[] tv = c.getTypeParameters(); if (tv.length != 0) { out.format(" "); for (TypeVariable t : tv) out.format("%s ", t.getName()); out.format("%n%n"); } else { out.format(" -- No Type Parameters --%n%n"); } out.format("Implemented Interfaces:%n"); Type[] intfs = c.getGenericInterfaces(); if (intfs.length != 0) { for (Type intf : intfs) out.format(" %s%n", intf.toString()); out.format("%n"); } else { out.format(" -- No Implemented Interfaces --%n%n"); } out.format("Inheritance Path:%n"); List<Class> l = new ArrayList<Class>(); printAncestor(c, l); if (l.size() != 0) { for (Class<?> cl : l) out.format(" %s%n", cl.getCanonicalName()); out.format("%n"); } else { out.format(" -- No Super Classes --%n%n"); } out.format("Annotations:%n"); Annotation[] ann = c.getAnnotations(); if (ann.length != 0) { for (Annotation a : ann) out.format(" %s%n", a.toString()); out.format("%n"); } else { out.format(" -- No Annotations --%n%n"); } // production code should handle this exception more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { List<String> theList = new LinkedList<String>(); theList.add("A"); theList.add("B"); theList.add("C"); theList.add("D"); String[] my = theList.toArray(new String[theList.size()]); for (int i = 0; i < my.length; i++) { System.out.println(my[i]); }//from w ww. j ava 2 s . c o m }
From source file:com.aerospike.example.cache.AsACache.java
public static void main(String[] args) throws AerospikeException { try {//w ww .j av a2s . c o m Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: 127.0.0.1)"); 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", "127.0.0.1"); 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; } AsACache as = new AsACache(host, port, namespace, set); as.work(); } catch (Exception e) { log.error("Critical error", e); } }
From source file:org.openplans.delayfeeder.LoadFeeds.java
public static void main(String args[]) throws HibernateException, IOException { if (args.length != 1) { System.out.println("expected one argument: the path to a csv of agency,route,url"); }//from w w w .ja v a2 s.c o m GenericApplicationContext context = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context); xmlReader.loadBeanDefinitions("org/openplans/delayfeeder/application-context.xml"); xmlReader.loadBeanDefinitions("data-sources.xml"); SessionFactory sessionFactory = (SessionFactory) context.getBean("sessionFactory"); Session session = sessionFactory.getCurrentSession(); Transaction tx = session.beginTransaction(); FileReader fileReader = new FileReader(new File(args[0])); BufferedReader bufferedReader = new BufferedReader(fileReader); while (bufferedReader.ready()) { String line = bufferedReader.readLine().trim(); if (line.startsWith("#")) { continue; } if (line.length() < 3) { //blank or otherwise broken line continue; } String[] parts = line.split(","); String agency = parts[0]; String route = parts[1]; String url = parts[2]; Query query = session.createQuery("from RouteFeed where agency = :agency and route = :route"); query.setParameter("agency", agency); query.setParameter("route", route); @SuppressWarnings("rawtypes") List list = query.list(); RouteFeed feed; if (list.size() == 0) { feed = new RouteFeed(); feed.agency = agency; feed.route = route; feed.lastEntry = new GregorianCalendar(); } else { feed = (RouteFeed) list.get(0); } if (!url.equals(feed.url)) { feed.url = url; feed.lastEntry.setTimeInMillis(0); } session.saveOrUpdate(feed); } tx.commit(); }
From source file:com.javacreed.examples.spring.Example1.java
public static void main(final String[] args) throws Exception { final ComboPooledDataSource ds = DbUtils.createDs(); try {/* w w w . j a v a 2 s . c o m*/ final JdbcTemplate jdbcTemplate = new JdbcTemplate(ds); Example1.LOGGER.debug("Reading all rows"); final List<Data> rows = jdbcTemplate.query("SELECT * FROM `big_table`", Data.ROW_MAPPER); Example1.LOGGER.debug("All records read ({} records)", rows.size()); // Sleep a bit so that it shows better on the profiler TimeUnit.SECONDS.sleep(10); } finally { DbUtils.closeQuietly(ds); } Example1.LOGGER.debug("Done"); }
From source file:com.sun.labs.aura.grid.ec2.Ec2Sample.java
public static void main(String[] args) throws Exception { Properties props = new Properties(); props.load(Ec2Sample.class.getResourceAsStream("aws.properties")); Jec2 ec2 = new Jec2(props.getProperty("aws.accessId"), props.getProperty("aws.secretKey")); List<String> params = new ArrayList<String>(); List<ImageDescription> images = ec2.describeImages(params); System.out.println(String.format("%d available images", images.size())); for (ImageDescription img : images) { if (img.getImageState().equals("available")) { System.out.println(img.getImageId() + "\t" + img.getImageLocation() + "\t" + img.getImageOwnerId()); }/*from www .ja v a 2 s . co m*/ } // describe instances params = new ArrayList<String>(); List<ReservationDescription> instances = ec2.describeInstances(params); System.out.println(String.format("%d instances", instances.size())); String instanceId = null; for (ReservationDescription res : instances) { System.out.println(res.getOwner() + "\t" + res.getReservationId()); if (res.getInstances() != null) { for (Instance inst : res.getInstances()) { System.out.println("\t" + inst.getImageId() + "\t" + inst.getDnsName() + "\t" + inst.getState() + "\t" + inst.getKeyName()); instanceId = inst.getInstanceId(); } } } // test console output if (instanceId != null) { ConsoleOutput consOutput = ec2.getConsoleOutput(instanceId); System.out.println("Console Output:"); System.out.println(consOutput.getOutput()); } // show keypairs List<KeyPairInfo> info = ec2.describeKeyPairs(new String[] {}); System.out.println("keypair list"); for (KeyPairInfo i : info) { System.out.println("keypair : " + i.getKeyName() + ", " + i.getKeyFingerprint()); } }
From source file:com.rmzone.core.App.java
public static void main(String[] args) { // set up mongo ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringMongoConfig.class); MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate"); // create and save some users List<User> users = new ArrayList<User>(); users.add(new User("1001", "foo", "bar")); users.add(new User("1002", "mickey", "mouse")); for (User user : users) mongoOperation.save("users", user); // create and save some documents Tire tire = new Tire("Michelin", "Alpine", 1, users.get(0), Calendar.getInstance().getTime(), 14, 12, 3); mongoOperation.save("documents", tire); Engine engine = new Engine("Model T", "Wow", 1, users.get(0), Calendar.getInstance().getTime()); engine.setHorsePower(16.4f);//from w w w . j ava2 s . c o m mongoOperation.save("documents", engine); Car car = new Car("Pinto", "don't touch me!", 1, users.get(0), Calendar.getInstance().getTime()); car.setMake("Ford"); car.setColor("Blue"); car.setEngine(engine); // sorry not very elegant car.setTires(new ArrayList<Tire>()); for (int i = 0; i < 4; i++) car.getTires().add(tire); mongoOperation.save("documents", car); // dump all the data List<User> listUser = mongoOperation.getCollection("users", User.class); System.out.println("Number of users = " + listUser.size()); for (User user : listUser) System.out.println(user.toString()); List<DocumentMaster> listDocument = mongoOperation.getCollection("documents", DocumentMaster.class); System.out.println("Number of documents = " + listDocument.size()); for (DocumentMaster document1 : listDocument) System.out.println(document1.toString()); // delete everything mongoOperation.dropCollection("users"); mongoOperation.dropCollection("documents"); }