List of usage examples for java.util ArrayList ArrayList
public ArrayList()
From source file:ObjectAnalyzerTest.java
public static void main(String[] args) { ArrayList<Integer> squares = new ArrayList<Integer>(); for (int i = 1; i <= 5; i++) squares.add(i * i);/*from w ww . jav a 2 s .c o m*/ System.out.println(new ObjectAnalyzer().toString(squares)); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_5); document.open();//from www . ja v a2s . co m PdfContentByte cb = writer.getDirectContent(); PdfLayer radiogroup = PdfLayer.createTitle("Radio Group", writer); PdfLayer radio1 = new PdfLayer("Radiogroup: layer 1", writer); radio1.setOn(true); PdfLayer radio2 = new PdfLayer("Radiogroup: layer 2", writer); radio2.setOn(false); PdfLayer radio3 = new PdfLayer("Radiogroup: layer 3", writer); radio3.setOn(false); radiogroup.addChild(radio1); radiogroup.addChild(radio2); radiogroup.addChild(radio3); ArrayList options = new ArrayList(); options.add(radio1); options.add(radio2); options.add(radio3); writer.addOCGRadioGroup(options); cb.beginLayer(radio1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("option 1"), 50, 600, 0); cb.endLayer(); cb.beginLayer(radio2); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("option 2"), 50, 575, 0); cb.endLayer(); cb.beginLayer(radio3); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("option 3"), 50, 550, 0); cb.endLayer(); document.close(); }
From source file:com.siva.javamultithreading.MultiThreadExecutor.java
public static void main(String[] args) throws ExecutionException, IOException { //Populate the data List<DomainObject> list = new ArrayList<>(); DomainObject object = null;/*w ww .j av a2s .c om*/ for (int i = 0; i < 230000; i++) { object = new DomainObject(); object.setId("ID" + i); object.setName("NAME" + i); object.setComment("COMMENT" + i); list.add(object); } int maxNoOfRows = 40000; int noOfThreads = 1; int remaining = 0; if (list.size() > 40000) { noOfThreads = list.size() / maxNoOfRows; remaining = list.size() % maxNoOfRows; if (remaining > 0) { noOfThreads++; } } List<List<DomainObject>> dos = ListUtils.partition(list, maxNoOfRows); ExecutorService threadPool = Executors.newFixedThreadPool(noOfThreads); CompletionService<HSSFWorkbook> pool = new ExecutorCompletionService<>(threadPool); // Excel creation through multiple threads long startTime = System.currentTimeMillis(); for (List<DomainObject> listObj : dos) { pool.submit(new ExcelChunkSheetWriter(listObj)); } HSSFWorkbook hSSFWorkbook = null; HSSFWorkbook book = new HSSFWorkbook(); HSSFSheet sheet = book.createSheet("Report"); try { for (int i = 0; i < 5; i++) { hSSFWorkbook = pool.take().get(); System.out.println( "sheet row count : sheet.PhysicalNumberOfRows() = " + sheet.getPhysicalNumberOfRows()); int currentCount = sheet.getPhysicalNumberOfRows(); int incomingCount = hSSFWorkbook.getSheetAt(0).getPhysicalNumberOfRows(); if ((currentCount + incomingCount) > 60000) { sheet = book.createSheet("Report" + i); } ExcelUtil.copySheets(book, sheet, hSSFWorkbook.getSheetAt(0)); } } catch (InterruptedException ex) { Logger.getLogger(MultiThreadExecutor.class.getName()).log(Level.SEVERE, null, ex); } catch (ExecutionException ex) { Logger.getLogger(MultiThreadExecutor.class.getName()).log(Level.SEVERE, null, ex); } try { writeFile(book, new FileOutputStream("Report.xls")); } catch (Exception e) { e.printStackTrace(); } //System.out.println("No of Threads : " + noOfThreads + " Size : " + list.size() + " remaining : " + remaining); long endTime = System.currentTimeMillis(); System.out.println("Time taken: " + (endTime - startTime) + " ms"); threadPool.shutdown(); //startProcess(); }
From source file:in.sc.main.ABC.java
public static void main(String[] args) { List list = new ArrayList(); list.add("1"); list.add("2"); list.add("3"); Collections.reverse(list);/*from w w w . j a v a 2 s .c o m*/ list.iterator(); for (Object obj : reverse(list)) { System.out.print(obj + ", "); } D x = (D) new D(); if (x instanceof I) { System.out.println("I"); } if (x instanceof J) { System.out.println("J"); } if (x instanceof C) { System.out.println("C"); } if (x instanceof D) { System.out.println("D"); } xyz x1 = new xyz("Test"); int x2 = 111; Rank abc = Rank.FIRST; System.out.println("" + abc.SECOND); final int j = 2; switch (x2) { case 1: System.out.println("1"); break; case 10: System.out.println("10"); break; case j: System.out.println("2"); break; case 5: System.out.println("5"); break; default: System.out.println("Default"); break; } String str1 = "lower", str2 = "LOWER", str3 = "UPPER"; str1.toUpperCase(); str1.replace("LOWER", "UPPER"); System.out .println((str1.equals(str2)) + " " + (str1.equals(str3)) + " " + str1 + " " + str2 + " " + str3); for (int i = 0; i < 3; i++) { System.out.println("" + i); switch (i) { case 0: break; case 1: System.out.println("one"); case 2: System.out.println("two"); case 3: System.out.println("three"); } } System.out.println("done"); ABC a = new ABC("a", "b"); ABC b = new ABC(a); }
From source file:PCC.java
/** * @param args the command line arguments * @throws java.io.IOException//from w ww . ja va 2 s . c o m */ public static void main(String[] args) throws IOException { // TODO code application logic here PearsonsCorrelation corel = new PearsonsCorrelation(); PCC method = new PCC(); ArrayList<String> name = new ArrayList<>(); Multimap<String, String> genes = ArrayListMultimap.create(); BufferedWriter bw = new BufferedWriter(new FileWriter(args[1])); BufferedReader br = new BufferedReader(new FileReader(args[0])); String str; while ((str = br.readLine()) != null) { String[] a = str.split("\t"); name.add(a[0]); for (int i = 1; i < a.length; i++) { genes.put(a[0], a[i]); } } for (String key : genes.keySet()) { double[] first = new double[genes.get(key).size()]; int element1 = 0; for (String value : genes.get(key)) { double d = Double.parseDouble(value); first[element1] = d; element1++; } for (String key1 : genes.keySet()) { if (!key.equals(key1)) { double[] second = new double[genes.get(key1).size()]; int element2 = 0; for (String value : genes.get(key1)) { double d = Double.parseDouble(value); second[element2] = d; element2++; } double corrlation = corel.correlation(first, second); if (corrlation > 0.5) { bw.write(key + "\t" + key1 + "\t" + corrlation + "\t" + method.pvalue(corrlation, second.length) + "\n"); } } } } br.close(); bw.close(); }
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);// w w w . ja v a 2 s. co 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:twilio.SmsSender.java
public static void main(String[] args) throws TwilioRestException { TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN); Account account = client.getAccount(); MessageFactory messageFactory = account.getMessageFactory(); ArrayList params = new ArrayList(); params.add(new BasicNameValuePair("To", "+16464152856")); // Replace with a valid phone number for your account. params.add(new BasicNameValuePair("From", "+19899320208")); // Replace with a valid phone number for your account. params.add(new BasicNameValuePair("Body", "LOL!")); Message sms = messageFactory.create(params); }
From source file:caarray.client.test.full.LoadTest.java
/** * @param args/* w ww . j a va 2 s . co m*/ */ public static void main(String[] args) { List<ApiFacade> apiFacades = new ArrayList<ApiFacade>(); List<List<ConfigurableTestSuite>> testSuiteCollection = new ArrayList<List<ConfigurableTestSuite>>(); int numThreads = TestProperties.getNumThreads(); if (numThreads <= 1) { System.out.println( "Thread count for load test set to 1 - setting to default count of " + DEFAULT_THREADS); numThreads = DEFAULT_THREADS; } try { for (int i = apiFacades.size(); i < numThreads; i++) { apiFacades.add(new FullApiFacade()); } for (int i = testSuiteCollection.size(); i < numThreads; i++) { List<ConfigurableTestSuite> shortTests = TestMain.getShortTestSuites(apiFacades.get(i)); List<ConfigurableTestSuite> longTests = TestMain.getLongTestSuites(apiFacades.get(i)); List<ConfigurableTestSuite> testSuites = new ArrayList<ConfigurableTestSuite>(); testSuites.addAll(shortTests); testSuites.addAll(longTests); testSuiteCollection.add(testSuites); } TestResultReport[] threadReports = new TestResultReport[numThreads]; for (int i = 0; i < numThreads; i++) { threadReports[i] = new TestResultReport(); } Thread[] loadTestThreads = new Thread[numThreads]; for (int i = 0; i < numThreads; i++) { LoadTestThread thread = new LoadTestThread(apiFacades.get(i), testSuiteCollection.get(i), threadReports[i], i); loadTestThreads[i] = new Thread(thread); } System.out.println("Executing load tests for " + numThreads + " threads ..."); long start = System.currentTimeMillis(); for (int i = 0; i < numThreads; i++) { loadTestThreads[i].start(); } for (int i = 0; i < numThreads; i++) { loadTestThreads[i].join(); } long time = System.currentTimeMillis() - start; System.out.println("Load tests completed in " + (double) time / (double) 1000 + " seconds."); TestResultReport finalReport = new TestResultReport(); for (TestResultReport report : threadReports) { finalReport.merge(report); } System.out.println("Analyzing load test results ..."); finalReport.writeLoadTestReports(); } catch (Throwable t) { System.out.println("An exception occured execuitng the load tests: " + t.getClass()); System.out.println("Test suite aborted."); t.printStackTrace(); log.error("Exception encountered:", t); } }
From source file:net.meltdowntech.steamstats.SteamUser.java
public static void main(String[] args) { Util.startTimer();//from w w w.j a v a 2 s . c om List<Long> ids = new ArrayList<>(); ids.add(76561198038145439L); List<SteamUser> users = fetchUsers(ids); users.get(0).fetchPlaytime(); users.get(0).fetchLevel(); Util.printInfo("Playtime " + users.get(0).getPlaytime()); Util.printInfo("Level " + users.get(0).getLevel()); }
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();/* w w w. j a va 2 s.c o m*/ 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(); }