List of usage examples for java.util List get
E get(int index);
From source file:Main.java
public static void main(String[] args) { Person p = new Person("A"); Animal a = new Animal("B"); Thing t = new Thing("C"); String text = "hello"; Integer number = 1000;//from ww w . j a v a 2 s . c o m List<Object> list = new ArrayList<Object>(); list.add(p); list.add(a); list.add(t); list.add(text); list.add(number); for (int i = 0; i < list.size(); i++) { Object o = list.get(i); if (o instanceof Person) { System.out.println("My name is " + ((Person) o).getName()); } else if (o instanceof Animal) { System.out.println("I live in " + ((Animal) o).getHabitat()); } else if (o instanceof Thing) { System.out.println("My color is " + ((Thing) o).getColor()); } else if (o instanceof String) { System.out.println("My text is " + o.toString()); } else if (o instanceof Integer) { System.out.println("My value is " + ((Integer) o)); } } }
From source file:com.l2jfree.tools.ProjectSettingsSynchronizer.java
public static void main(String[] args) throws IOException { final File src = new File(".").getCanonicalFile(); System.out.println("Copying from: " + src); System.out.println();/*ww w . java 2 s .com*/ final List<File> destinations = new ArrayList<File>(); for (File dest : src.getParentFile().listFiles()) { if (dest.isHidden() || !dest.isDirectory()) continue; destinations.add(dest); System.out.println("Copying to: " + dest); } System.out.println(); // .project System.out.println(".project"); System.out.println("================================================================================"); { final List<String> lines = FileUtils.readLines(new File(src, ".project")); for (File dest : destinations) { lines.set(2, lines.get(2).replaceAll(src.getName(), dest.getName())); writeLines(dest, ".project", lines); lines.set(2, lines.get(2).replaceAll(dest.getName(), src.getName())); } } System.out.println(); // .classpath System.out.println(".classpath"); System.out.println("================================================================================"); { final List<String> lines = FileUtils.readLines(new File(src, ".classpath")); for (File dest : destinations) { if (dest.getName().endsWith("-main") || dest.getName().endsWith("-datapack")) { final ArrayList<String> tmp = new ArrayList<String>(); for (String line : lines) if (!line.contains("classpathentry")) tmp.add(line); writeLines(dest, ".classpath", tmp); continue; } writeLines(dest, ".classpath", lines); } } System.out.println(); // .settings System.out.println(".settings"); System.out.println("================================================================================"); for (File settingsFile : new File(src, ".settings").listFiles()) { if (settingsFile.getName().endsWith(".prefs")) { System.out.println(".settings/" + settingsFile.getName()); System.out.println( "--------------------------------------------------------------------------------"); final List<String> lines = FileUtils.readLines(settingsFile); if (lines.get(0).startsWith("#")) lines.remove(0); for (File dest : destinations) { writeLines(new File(dest, ".settings"), settingsFile.getName(), lines); } System.out.println(); } } System.out.println(); }
From source file:mxnet.ImageClassification.java
public static void main(String[] args) { // Download the model and Image downloadModelImage();/*from w w w . ja va2 s. c o m*/ // Prepare the model List<Context> context = new ArrayList<Context>(); context.add(Context.cpu()); List<DataDesc> inputDesc = new ArrayList<>(); Shape inputShape = new Shape(new int[] { 1, 3, 224, 224 }); inputDesc.add(new DataDesc("data", inputShape, DType.Float32(), "NCHW")); Predictor predictor = new Predictor(modelPath, inputDesc, context, 0); // Prepare data NDArray nd = Image.imRead(imagePath, 1, true); nd = Image.imResize(nd, 224, 224, null); nd = NDArray.transpose(nd, new Shape(new int[] { 2, 0, 1 }), null)[0]; // HWC to CHW nd = NDArray.expand_dims(nd, 0, null)[0]; // Add N -> NCHW nd = nd.asType(DType.Float32()); // Inference with Float32 // Predict directly float[][] result = predictor.predict(new float[][] { nd.toArray() }); try { System.out.println("Predict with Float input"); System.out.println(printMaximumClass(result[0], modelPath)); } catch (IOException e) { System.err.println(e); } // predict with NDArray List<NDArray> ndList = new ArrayList<>(); ndList.add(nd); List<NDArray> ndResult = predictor.predictWithNDArray(ndList); try { System.out.println("Predict with NDArray"); System.out.println(printMaximumClass(ndResult.get(0).toArray(), modelPath)); } catch (IOException e) { System.err.println(e); } }
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 ww . j a v a2s.c o 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:com.plexobject.testplayer.dao.hibernate.MethodDaoHibernate.java
public static void main(String[] args) throws Exception { MethodDaoHibernate dao = new MethodDaoHibernate(); createTable();/* w w w .j a va 2 s . c om*/ /* 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:core.App.java
public static void main(String[] args) { // For XML/* w ww . j av a 2s. c o m*/ //ApplicationContext ctx = new GenericXmlApplicationContext("SpringConfig.xml"); // For Annotation ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringMongoConfig.class); MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate"); //Student user = new Student("3", "federico", "solterman", "26-10-1990"); // save //mongoOperation.save(user); // now user object got the created id. // System.out.println("1. user : " + user); // query to search user // Query searchUserQuery = new Query(Criteria.where("first_name").is("federico")) { //}; // find the saved user again. //Student savedUser = mongoOperation.findOne(searchUserQuery, Student.class); // System.out.println("2. find - savedUser : " + savedUser); //This method Fetch all students whose notes in a specific course were greater than 4 BasicQuery query = new BasicQuery( "{ $and: [{ note_1: {$gt:4 }, note_2: {$gt:4}, note_3: {$gt:4},note_final:{$gt:4 } } ] }"); List<StudentXCourseXNote> stu = mongoOperation.find(query, StudentXCourseXNote.class); StudentXCourseXNote aux; for (int i = 0; i < stu.size(); i++) { aux = stu.get(i); BasicQuery query1 = new BasicQuery("{id_registration:" + " \"" + aux.getId_student() + "\"}"); Student student = mongoOperation.findOne(query1, Student.class); System.out.println(student.toString()); } //Fetch all courses ordered by name for a given teacher BasicQuery query2 = new BasicQuery("{ last_name:\"Sulma\" }"); Teacher teacher = mongoOperation.findOne(query2, Teacher.class); BasicQuery query3 = new BasicQuery("{ id_teacher: \"" + teacher.getId_teacher() + "\"}"); List<TeacherXCourse> list = mongoOperation.find(query3, TeacherXCourse.class); TeacherXCourse aux2; for (int j = 0; j < list.size(); j++) { aux2 = list.get(j); BasicQuery query4 = new BasicQuery("{id_course: \"" + aux2.getId_course() + "\" }"); Course course = mongoOperation.findOne(query4, Course.class); System.out.println(course.toString()); } //This method add a new fields in the collection course BasicQuery queryPoint4 = new BasicQuery("{ },{ $set: { finish: boolean } },{ multi: true }"); Update update = new Update(); update.set("{}", ""); mongoOperation.updateFirst(queryPoint4, null, Course.class); // update password /*mongoOperation.updateFirst(searchUserQuery, Update.update("password", "new password"), Student.class);*/ // find the updated user object /*Student updatedUser = mongoOperation.findOne(searchUserQuery, Student.class);*/ //System.out.println("3. updatedUser : " + updatedUser); // delete // mongoOperation.remove(searchUserQuery, Student.class); // List, it should be empty now. /* List<Student> listUser = mongoOperation.findAll(Student.class); System.out.println("4. Number of user = " + listUser.size());*/ }
From source file:com.silentwu.schedule.component.WebAnalyzeService.java
public static void main(String[] args) throws IOException { System.out.println(URLDecoder.decode("%E6%88%90%E9%83%BD%E5%B8%82", "utf-8")); final WebAnalyzeService webAnalyzeService = new WebAnalyzeService(); final List<City> startCities = webAnalyzeService.findStartCities("cd"); System.out.println("startCities:\n" + startCities); final List<City> endCities = webAnalyzeService.findTargetCities(startCities.get(0).getId(), startCities.get(0).getChinaName(), "my"); System.out.println(endCities); // System.out.println(webAnalyzeService.findScheduleFromHtml()); }
From source file:com.github.ipaas.ifw.front.rewrite.FisRewrite.java
public static void main(String[] args) { try {/*from w ww. j a v a 2 s .co m*/ FisRewrite fr = new FisRewrite(); List<FisRewriteRule> rules = fr.getRules(); for (int i = 0; i < rules.size(); i++) { FisRewriteRule rule = rules.get(i); System.out.println(rule.getRequestUri()); System.out.println(rule.getTemplateFile()); List<String> dataFiles = rule.getDataFiles(); if (null != dataFiles) { for (int j = 0, len = dataFiles.size(); i < len; i++) { System.out.println(dataFiles.get(i)); } } } String requestUri = "/index.shtml"; FisRewriteRule frRule = fr.findRule(requestUri); System.out.println("find : " + frRule.getRequestUri()); } catch (FisException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:AverageCost.java
public static void main(String[] args) throws FileNotFoundException, IOException { //Directory of the n files String directory_path = "/home/gauss/rgrunitzki/Dropbox/Profissional/UFRGS/Doutorado/Artigo TRI15/SF Experiments/IQ-Learning/"; BufferedReader reader = null; //Line to analyse String line = ""; String csvDivisor = ";"; int totalLines = 1002; int totalRows = 532; String filesToRead[] = new File(directory_path).list(); Arrays.sort(filesToRead);// ww w . j a v a 2s. c o m System.out.println(filesToRead.length); List<List<DescriptiveStatistics>> summary = new ArrayList<>(); for (int i = 0; i <= totalLines; i++) { summary.add(new ArrayList<DescriptiveStatistics>()); for (int j = 0; j <= totalRows; j++) { summary.get(i).add(new DescriptiveStatistics()); } } //reads all files for (String file : filesToRead) { reader = new BufferedReader(new FileReader(directory_path + file)); int lineCounter = 0; //reads all file's line while ((line = reader.readLine()) != null) { if (lineCounter > 0) { String[] rows = line.trim().split(csvDivisor); //reads all line's row for (int r = 0; r < rows.length; r++) { summary.get(lineCounter).get(r).addValue(Double.parseDouble(rows[r])); } } lineCounter++; } //System.out.println(file.split("/")[file.split("/").length - 1] + csvDivisor + arithmeticMean(avgCost) + csvDivisor + standardDeviation(avgCost)); } //generate mean and standard deviation; for (List<DescriptiveStatistics> summaryLines : summary) { System.out.println(); for (DescriptiveStatistics summaryLineRow : summaryLines) { System.out.print(summaryLineRow.getMean() + ";" + summaryLineRow.getStandardDeviation() + ";"); } } }
From source file:jk.kamoru.test.IMAPMail.java
public static void main(String[] args) { /* if (args.length < 3) {/*from w w w. j a v a2 s . c o m*/ System.err.println( "Usage: IMAPMail <imap server hostname> <username> <password> [TLS]"); System.exit(1); } */ String server = "imap.handysoft.co.kr"; String username = "namjk24@handysoft.co.kr"; String password = "22222"; String proto = (args.length > 3) ? args[3] : null; IMAPClient imap; if (proto != null) { System.out.println("Using secure protocol: " + proto); imap = new IMAPSClient(proto, true); // implicit // enable the next line to only check if the server certificate has expired (does not check chain): // ((IMAPSClient) imap).setTrustManager(TrustManagerUtils.getValidateServerCertificateTrustManager()); // OR enable the next line if the server uses a self-signed certificate (no checks) // ((IMAPSClient) imap).setTrustManager(TrustManagerUtils.getAcceptAllTrustManager()); } else { imap = new IMAPClient(); } System.out.println("Connecting to server " + server + " on " + imap.getDefaultPort()); // We want to timeout if a response takes longer than 60 seconds imap.setDefaultTimeout(60000); File imap_log_file = new File("IMAMP-UNSEEN"); try { System.out.println(imap_log_file.getAbsolutePath()); PrintStream ps = new PrintStream(imap_log_file); // suppress login details imap.addProtocolCommandListener(new PrintCommandListener(ps, true)); } catch (FileNotFoundException e1) { imap.addProtocolCommandListener(new PrintCommandListener(System.out, true)); } try { imap.connect(server); } catch (IOException e) { throw new RuntimeException("Could not connect to server.", e); } try { if (!imap.login(username, password)) { System.err.println("Could not login to server. Check password."); imap.disconnect(); System.exit(3); } imap.setSoTimeout(6000); // imap.capability(); // imap.select("inbox"); // imap.examine("inbox"); imap.status("inbox", new String[] { "UNSEEN" }); // imap.logout(); imap.disconnect(); List<String> imap_log = FileUtils.readLines(imap_log_file); for (int i = 0; i < imap_log.size(); i++) { System.out.println(i + ":" + imap_log.get(i)); } String unseenText = imap_log.get(4); unseenText = unseenText.substring(unseenText.indexOf('(') + 1, unseenText.indexOf(')')); int unseenCount = Integer.parseInt(unseenText.split(" ")[1]); System.out.println(unseenCount); //imap_log.indexOf("UNSEEN ") } catch (IOException e) { System.out.println(imap.getReplyString()); e.printStackTrace(); System.exit(10); return; } }