Example usage for java.util ArrayList ArrayList

List of usage examples for java.util ArrayList ArrayList

Introduction

In this page you can find the example usage for java.util ArrayList ArrayList.

Prototype

public ArrayList() 

Source Link

Document

Constructs an empty list with an initial capacity of ten.

Usage

From source file:com.aliyun.openservices.odps.console.ODPSConsole.java

public static void main(String[] args) throws ODPSConsoleException {

    List<String> options = new ArrayList<String>();
    // ?confignull
    String config = prepareOptions(args, options);

    // session context
    ExecutionContext sessionContext = ExecutionContext.load(config);

    checkSDKEnviron();//ww w.ja  va  2 s  . c  o m

    DefaultOutputWriter writer = sessionContext.getOutputWriter();

    writer.writeDebug("ODPSConsole Start");
    try {

        // apache.commons.logging???
        System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");

        // sessionContextcommand
        // ??command????
        AbstractCommand oa = CommandParserUtils.parseOptions(
                config == null ? args : (String[]) options.toArray(new String[0]), sessionContext);

        oa.run();
    } catch (OdpsException e) {
        writer.writeError(ODPSConsoleConstants.FAILED_MESSAGE + e.getMessage());
        // debug??stack?
        writer.writeDebug(StringUtils.stringifyException(e));

        System.exit(1);
    } catch (ODPSConsoleException e) {
        writer.writeError(ODPSConsoleConstants.FAILED_MESSAGE + e.getMessage());
        writer.writeDebug(StringUtils.stringifyException(e));

        System.exit(e.getExitCode());
    } catch (Exception e) {
        // ,
        e.printStackTrace();

        System.exit(1);
    }

    sessionContext.getOutputWriter().writeDebug("ODPSConsole End");
    // 
    System.exit(0);
}

From source file:com.alexoree.jenkins.Main.java

public static void main(String[] args) throws Exception {
    // create Options object
    Options options = new Options();

    options.addOption("t", false, "throttle the downloads, waits 5 seconds in between each d/l");

    // automatically generate the help statement
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("jenkins-sync", options);

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);
    boolean throttle = cmd.hasOption("t");

    String plugins = "https://updates.jenkins-ci.org/latest/";
    List<String> ps = new ArrayList<String>();
    Document doc = Jsoup.connect(plugins).get();
    for (Element file : doc.select("td a")) {
        //System.out.println(file.attr("href"));
        if (file.attr("href").endsWith(".hpi") || file.attr("href").endsWith(".war")) {
            ps.add(file.attr("href"));
        }//from  w ww  . j  av  a2s  .  c om
    }

    File root = new File(".");
    //https://updates.jenkins-ci.org/latest/AdaptivePlugin.hpi
    new File("./latest").mkdirs();

    //output zip file
    String zipFile = "jenkinsSync.zip";
    // create byte buffer
    byte[] buffer = new byte[1024];
    FileOutputStream fos = new FileOutputStream(zipFile);
    ZipOutputStream zos = new ZipOutputStream(fos);

    //download the plugins
    for (int i = 0; i < ps.size(); i++) {
        System.out.println("[" + i + "/" + ps.size() + "] downloading " + plugins + ps.get(i));
        String outputFile = download(root.getAbsolutePath() + "/latest/" + ps.get(i), plugins + ps.get(i));

        FileInputStream fis = new FileInputStream(outputFile);
        // begin writing a new ZIP entry, positions the stream to the start of the entry data
        zos.putNextEntry(new ZipEntry(outputFile.replace(root.getAbsolutePath(), "")
                .replace("updates.jenkins-ci.org/", "").replace("https:/", "")));
        int length;
        while ((length = fis.read(buffer)) > 0) {
            zos.write(buffer, 0, length);
        }
        zos.closeEntry();
        fis.close();
        if (throttle)
            Thread.sleep(WAIT);
        new File(root.getAbsolutePath() + "/latest/" + ps.get(i)).deleteOnExit();
    }

    //download the json metadata
    plugins = "https://updates.jenkins-ci.org/";
    ps = new ArrayList<String>();
    doc = Jsoup.connect(plugins).get();
    for (Element file : doc.select("td a")) {
        //System.out.println(file.attr("href"));
        if (file.attr("href").endsWith(".json")) {
            ps.add(file.attr("href"));
        }
    }
    for (int i = 0; i < ps.size(); i++) {
        download(root.getAbsolutePath() + "/" + ps.get(i), plugins + ps.get(i));

        FileInputStream fis = new FileInputStream(root.getAbsolutePath() + "/" + ps.get(i));
        // begin writing a new ZIP entry, positions the stream to the start of the entry data
        zos.putNextEntry(new ZipEntry(plugins + ps.get(i)));
        int length;
        while ((length = fis.read(buffer)) > 0) {
            zos.write(buffer, 0, length);
        }
        zos.closeEntry();
        fis.close();
        new File(root.getAbsolutePath() + "/" + ps.get(i)).deleteOnExit();
        if (throttle)
            Thread.sleep(WAIT);
    }

    // close the ZipOutputStream
    zos.close();
}

From source file:com.discursive.jccook.xml.bardsearch.TermFreq.java

public static void main(String[] pArgs) throws Exception {
    logger.info("Threshold is 200");
    Integer threshold = new Integer(200);

    IndexReader reader = IndexReader.open("index");
    TermEnum enumVar = reader.terms();/*from  w  w  w.  j a  v a2  s . c o m*/
    List termList = new ArrayList();
    while (enumVar.next()) {
        if (enumVar.docFreq() >= threshold.intValue() && enumVar.term().field().equals("speech")) {
            Freq freq = new Freq(enumVar.term().text(), enumVar.docFreq());
            termList.add(freq);
        }
    }
    Collections.sort(termList);
    Collections.reverse(termList);

    System.out.println("Frequency | Term");
    Iterator iterator = termList.iterator();
    while (iterator.hasNext()) {
        Freq freq = (Freq) iterator.next();
        System.out.print(freq.frequency);
        System.out.println(" | " + freq.term);
    }
}

From source file:ke.co.tawi.babblesms.server.utils.randomgenerate.IncomingLogGenerator.java

/**
 * @param args//from  w  w  w .  j  a  v  a  2s .  c  o  m
 */
public static void main(String[] args) {
    System.out.println("Have started IncomingSMSGenerator.");
    File outFile = new File("/tmp/logs/incomingSMS.csv");
    RandomDataGenerator randomDataImpl = new RandomDataGenerator();

    String randomStrFile = "/tmp/random.txt";

    List<String> randomStrings = new ArrayList<>();
    int randStrLength = 0;

    long startDate = 1412380800; // Unix time in seconds for Oct 4 2014
    long stopDate = 1420070340; // Unix time for in seconds Dec 31 2014

    SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 2011-06-01 00:16:45" 

    List<String> shortcodeUuids = new ArrayList<>();
    shortcodeUuids.add("094def52-bc18-4a9e-9b84-c34cc6476c75");
    shortcodeUuids.add("e9570c5d-0cc4-41e5-81df-b0674e9dda1e");
    shortcodeUuids.add("a118c8ea-f831-4288-986d-35e22c91fc4d");
    shortcodeUuids.add("a2688d72-291b-470c-8926-31a903f5ed0c");
    shortcodeUuids.add("9bef62f6-e682-4efd-98e9-ca41fa4ef993");

    int shortcodeCount = shortcodeUuids.size() - 1;

    try {
        randomStrings = FileUtils.readLines(new File(randomStrFile));
        randStrLength = randomStrings.size();

        for (int j = 0; j < 30000; j++) {
            FileUtils.write(outFile,
                    // shortcodeUuids.get(randomDataImpl.nextInt(0, shortcodeCount)) + "|"   // Destination 
                    UUID.randomUUID().toString() + "|" // Unique Code
                            + randomDataImpl.nextLong(new Long("254700000000").longValue(),
                                    new Long("254734999999").longValue())
                            + "|" // Origin
                            + shortcodeUuids.get(randomDataImpl.nextInt(0, shortcodeCount)) + "|"
                            + randomStrings.get(randomDataImpl.nextInt(0, randStrLength - 1)) + "|" // Message
                            + "N|" // deleted
                            + dateFormatter.format(
                                    new Date(randomDataImpl.nextLong(startDate, stopDate) * 1000))
                            + "\n", // smsTime                  
                    true); // Append to file                              
        }

    } catch (IOException e) {
        System.err.println("IOException in main.");
        e.printStackTrace();
    }

    System.out.println("Have finished IncomingSMSGenerator.");
}

From source file:MainClass.java

License:asdf

public static void main(String[] args) throws Exception {
    Document document = new Document(PageSize.A4);
    Paragraph hello = new Paragraph("(English:) hello, ");
    PdfWriter.getInstance(document, new FileOutputStream("HelloWorld1.pdf"));
    document.open();//from  w w w. ja v  a 2  s .  co m
    Chapter universe = new Chapter("asdf", 1);
    Section section;
    document.add(universe);

    document.close();
    document = new Document(PageSize.A4);

    PdfWriter.getInstance(document, new FileOutputStream("HelloWorld2.pdf"));
    document.open();
    Chapter people = new Chapter("asdf", 2);
    section = people.addSection("B");
    section.add(hello);
    document.add(people);

    document.close();
    document = new Document(PageSize.A4);

    PdfWriter.getInstance(document, new FileOutputStream("HelloWorld3.pdf"));
    document.open();
    Chapter animals = new Chapter("asdf", 3);
    section = animals.addSection("B");
    section.add(hello);
    document.add(animals);
    document.close();

    ArrayList bookmarks = new ArrayList();
    PdfReader reader = new PdfReader("HelloWorld1.pdf");
    document = new Document(reader.getPageSizeWithRotation(1));
    PdfCopy copy = new PdfCopy(document, new FileOutputStream("HelloWorldCopyBookmarks.pdf"));
    document.open();
    copy.addPage(copy.getImportedPage(reader, 1));
    bookmarks.addAll(SimpleBookmark.getBookmark(reader));
    reader = new PdfReader("HelloWorld2.pdf");
    copy.addPage(copy.getImportedPage(reader, 1));
    List tmp = SimpleBookmark.getBookmark(reader);
    SimpleBookmark.shiftPageNumbers(tmp, 1, null);
    bookmarks.addAll(tmp);
    reader = new PdfReader("HelloWorld3.pdf");
    copy.addPage(copy.getImportedPage(reader, 1));
    tmp = SimpleBookmark.getBookmark(reader);
    SimpleBookmark.shiftPageNumbers(tmp, 2, null);
    bookmarks.addAll(tmp);
    copy.setOutlines(bookmarks);
    document.close();
}

From source file:app.commons.SpELUtils.java

public static void main(String[] args) {
    final List<Integer> root = new ArrayList<Integer>() {
        {/*from www.ja  v a  2  s.c  om*/
            this.add(new Integer(1));
            this.add(new Integer(2));
            this.add(new Integer(3));
        }
    };
    System.out.println(parseExpression("#this", root));
}

From source file:com.mirth.connect.cli.launcher.CommandLineLauncher.java

public static void main(String[] args) {
    System.setProperty("log4j.configuration", "log4j-cli.properties");
    logger = Logger.getLogger(CommandLineLauncher.class);

    try {/* ww  w .  jav  a  2s .com*/
        ManifestFile mirthCliJar = new ManifestFile("cli-lib/mirth-cli.jar");
        ManifestFile mirthClientCoreJar = new ManifestFile("cli-lib/mirth-client-core.jar");
        ManifestDirectory cliLibDir = new ManifestDirectory("cli-lib");
        cliLibDir.setExcludes(new String[] { "mirth-client-core.jar" });

        ManifestEntry[] manifest = new ManifestEntry[] { mirthCliJar, mirthClientCoreJar, cliLibDir };

        List<URL> classpathUrls = new ArrayList<URL>();
        addManifestToClasspath(manifest, classpathUrls);
        addSharedLibsToClasspath(classpathUrls);
        URLClassLoader classLoader = new URLClassLoader(classpathUrls.toArray(new URL[classpathUrls.size()]));
        Class<?> cliClass = classLoader.loadClass("com.mirth.connect.cli.CommandLineInterface");
        Constructor<?>[] constructors = cliClass.getDeclaredConstructors();

        for (int i = 0; i < constructors.length; i++) {
            Class<?> parameters[] = constructors[i].getParameterTypes();

            if (parameters.length == 1) {
                constructors[i].newInstance(new Object[] { args });
                i = constructors.length;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.ok2c.lightmtp.examples.SendMailExample.java

public static void main(final String[] args) throws Exception {

    if (args.length < 3) {
        System.out.println("Usage: sender recipient1[;recipient2;recipient3;...] file");
        System.exit(0);/*  w w w .  ja  va 2s .  c  om*/
    }

    String sender = args[0];
    List<String> recipients = new ArrayList<String>();
    StringTokenizer tokenizer = new StringTokenizer(args[1], ";");
    while (tokenizer.hasMoreTokens()) {
        String s = tokenizer.nextToken();
        s = s.trim();
        if (s.length() > 0) {
            recipients.add(s);
        }
    }

    File src = new File(args[2]);
    if (!src.exists()) {
        System.out.println("File '" + src + "' does not exist");
        System.exit(0);
    }

    DeliveryRequest request = new BasicDeliveryRequest(sender, recipients, new FileSource(src));

    MailUserAgent mua = new DefaultMailUserAgent(TransportType.SMTP, IOReactorConfig.DEFAULT);
    mua.start();

    try {

        InetSocketAddress address = new InetSocketAddress("localhost", 2525);

        Future<DeliveryResult> future = mua.deliver(new SessionEndpoint(address), 0, request, null);

        DeliveryResult result = future.get();
        System.out.println("Delivery result: " + result);

    } finally {
        mua.shutdown();
    }
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step5bAgreementMeasures.java

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    String inputDir = args[0];/*from w  w  w . j  a  v  a  2s . co m*/

    // all annotations
    List<AnnotatedArgumentPair> allArgumentPairs = new ArrayList<>();

    Collection<File> files = IOHelper.listXmlFiles(new File(inputDir));

    for (File file : files) {
        allArgumentPairs.addAll((List<AnnotatedArgumentPair>) XStreamTools.getXStream().fromXML(file));
    }

    // for collecting the rank of n-th best worker per HIT
    SortedMap<Integer, DescriptiveStatistics> nThWorkerOnHITRank = new TreeMap<>();
    // confusion matrix wrt. gold data for each n-th best worker on HIT
    SortedMap<Integer, ConfusionMatrix> nThWorkerOnHITConfusionMatrix = new TreeMap<>();

    // initialize maps
    for (int i = 0; i < TOP_K_VOTES; i++) {
        nThWorkerOnHITRank.put(i, new DescriptiveStatistics());
        nThWorkerOnHITConfusionMatrix.put(i, new ConfusionMatrix());
    }

    for (AnnotatedArgumentPair argumentPair : allArgumentPairs) {
        // sort turker rank and their vote
        SortedMap<Integer, String> rankAndVote = new TreeMap<>();

        System.out.println(argumentPair.mTurkAssignments.size());

        for (AnnotatedArgumentPair.MTurkAssignment assignment : argumentPair.mTurkAssignments) {
            rankAndVote.put(assignment.getTurkRank(), assignment.getValue());
        }

        String goldLabel = argumentPair.getGoldLabel();

        System.out.println(rankAndVote);

        // top K workers for the HIT
        List<String> topKVotes = new ArrayList<>(rankAndVote.values()).subList(0, TOP_K_VOTES);

        // rank of top K workers
        List<Integer> topKRanks = new ArrayList<>(rankAndVote.keySet()).subList(0, TOP_K_VOTES);

        System.out.println("Top K votes: " + topKVotes);
        System.out.println("Top K ranks: " + topKRanks);

        // extract only category (a1, a2, or equal)
        List<String> topKVotesOnlyCategory = new ArrayList<>();
        for (String vote : topKVotes) {
            String category = vote.split("_")[2];
            topKVotesOnlyCategory.add(category);
        }

        System.out.println("Top " + TOP_K_VOTES + " workers' decisions: " + topKVotesOnlyCategory);

        if (goldLabel == null) {
            System.out.println("No gold label estimate for " + argumentPair.getId());
        } else {
            // update statistics
            for (int i = 0; i < TOP_K_VOTES; i++) {
                nThWorkerOnHITConfusionMatrix.get(i).increaseValue(goldLabel, topKVotesOnlyCategory.get(i));

                // rank is +1 (we don't start ranking from zero)
                nThWorkerOnHITRank.get(i).addValue(topKRanks.get(i) + 1);
            }
        }
    }

    for (int i = 0; i < TOP_K_VOTES; i++) {
        System.out.println("n-th worker : " + (i + 1) + " -----------");
        System.out.println(nThWorkerOnHITConfusionMatrix.get(i).printNiceResults());
        System.out.println(nThWorkerOnHITConfusionMatrix.get(i));
        System.out.println("Average rank: " + nThWorkerOnHITRank.get(i).getMean() + ", stddev "
                + nThWorkerOnHITRank.get(i).getStandardDeviation());
    }

}

From source file:akori.Impact.java

static public void main(String[] args) throws IOException {
    String PATH = "E:\\Trabajos\\AKORI\\datosmatrizgino\\";
    String PATHIMG = "E:\\NetBeansProjects\\AKORI\\Proccess_1\\ImagesPages\\";
    for (int i = 1; i <= 32; ++i) {
        for (int k = 1; k <= 15; ++k) {
            System.out.println("Matrix " + i + "-" + k);
            BufferedImage img = null;
            try {
                img = ImageIO.read(new File(PATHIMG + i + ".png"));
            } catch (IOException ex) {
                ex.getStackTrace();/*w w w. j ava2s .  co  m*/
            }

            int ymax = img.getHeight();
            int xmax = img.getWidth();

            double[][] imagen = new double[ymax][xmax];

            BufferedReader in = null;
            try {
                in = new BufferedReader(new FileReader(PATH + i + "-" + k + ".txt"));
            } catch (FileNotFoundException ex) {
                ex.getStackTrace();
            }

            String linea;
            ArrayList<String> lista = new ArrayList<String>();
            HashMap<String, String> lista1 = new HashMap<String, String>();
            try {
                for (int j = 0; (linea = in.readLine()) != null; ++j) {
                    String[] datos = linea.split(",");
                    int x = (int) Double.parseDouble(datos[1]);
                    int y = (int) Double.parseDouble(datos[2]);
                    if (x >= xmax || y >= ymax || x <= 0 || y <= 0) {
                        continue;
                    }
                    lista.add(x + "," + y);
                }
            } catch (Exception ex) {
                ex.getStackTrace();
            }

            try {
                in.close();
            } catch (IOException ex) {
                ex.getStackTrace();
            }

            Iterator iter = lista.iterator();
            int[][] matrix = new int[lista.size()][2];

            for (int j = 0; iter.hasNext(); ++j) {
                String xy = (String) iter.next();
                String[] datos = xy.split(",");
                matrix[j][0] = Integer.parseInt(datos[0]);
                matrix[j][1] = Integer.parseInt(datos[1]);
            }

            for (int j = 0; j < matrix.length; ++j) {

                int std = 50;
                int x = matrix[j][0];
                int y = matrix[j][1];
                imagen[y][x] += 1;
                double aux;
                normalMatrix(imagen, y, x, std);

            }

            FileWriter fw = new FileWriter(PATH + "Matrix" + i + "-" + k + ".txt");
            BufferedWriter bw = new BufferedWriter(fw);
            for (int j = 0; j < imagen.length; ++j) {
                for (int t = 0; t < imagen[j].length; ++t) {
                    if (t + 1 == imagen[j].length)
                        bw.write(imagen[j][t] + "");
                    else
                        bw.write(imagen[j][t] + ",");
                }
                bw.write("\n");
            }
            bw.close();
        }
    }
}