Example usage for java.util List addAll

List of usage examples for java.util List addAll

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).

Usage

From source file:commonline.query.gui.Frame.java

public static void main(String args[]) throws Exception {
    Plastic3DLookAndFeel.setTabStyle(Plastic3DLookAndFeel.TAB_STYLE_METAL_VALUE);
    UIManager.setLookAndFeel("com.jgoodies.looks.plastic.Plastic3DLookAndFeel");

    System.setProperty("com.apple.macos.useScreenMenuBar", "true");

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("MainContext.xml");

    List dataSources = new ArrayList();
    dataSources.addAll(context.getBeansOfType(RecordParserDataSource.class).values());
    CommonlineRecordRepository repository = (CommonlineRecordRepository) context.getBean("clRepository");

    Frame frame = new Frame(System.getProperty("os.name").toLowerCase().indexOf("mac") != -1, dataSources,
            repository);//from w w w.ja v  a2 s  .  co  m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String[] args) {
    final List<String> asu = new ArrayList<String>();
    asu.add("2");
    asu.add("11");
    asu.add("7");
    asu.add("10");
    asu.add("7");
    asu.add("12");
    asu.add("2");
    asu.add("11");
    asu.add("11");
    asu.add("7");
    asu.add("7");
    asu.add("7");

    List<String> list = new ArrayList<String>();
    Map<String, Integer> counts = new HashMap<String, Integer>();
    list.addAll(asu);
    for (String item : list) {
        Integer count = counts.get(item);
        if (count == null) {
            count = 1;/*from  w ww .j ava 2s  .  co  m*/
        } else {
            count = count + 1;
        }
        counts.put(item, count);
    }
    Collections.sort(asu, new Comparator<String>() {
        @Override
        public int compare(final String left, final String right) {
            int result = counts.get(left).compareTo(counts.get(right));
            if (result == 0) {
                result = left.compareTo(right);
            }
            return result;
        }
    });
    System.out.println(asu);
}

From source file:MainClass.java

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

    List list = new ArrayList();
    list.add("A");
    list.add("B");
    list.add("C");
    List list2 = new ArrayList();
    list2.add("X");
    list2.add("Y");
    list2.add("Z");
    list.addAll(list2);
    list.addAll(1, list2);/*from   w w w  .  j a  v  a  2s. com*/

    System.out.println(list);
}

From source file:com.twentyn.chemicalClassifier.Runner.java

public static void main(String[] args) throws Exception {
    BufferedReader reader = new BufferedReader(new FileReader(args[0]));
    BufferedWriter writer = new BufferedWriter(new FileWriter(args[1]));

    try {/* ww  w . j  a v a 2 s.  com*/
        Oscar oscar = new Oscar();

        String line = null;
        /* NOTE: this is exactly the wrong way to write a TSV reader.  Caveat emptor.
         * See http://tburette.github.io/blog/2014/05/25/so-you-want-to-write-your-own-CSV-code/
         * and then use org.apache.commons.csv.CSVParser instead.
         */
        while ((line = reader.readLine()) != null) {
            // TSV means split on tabs!  Nothing else will do.
            List<String> fields = Arrays.asList(line.split("\t"));
            // Choke if our invariants aren't satisfied.  We expect ever line to have a name and an InChI.
            if (fields.size() != 2) {
                throw new RuntimeException(
                        String.format("Found malformed line (all lines must have two fields: %s", line));
            }
            String name = fields.get(1);
            List<ResolvedNamedEntity> entities = oscar.findAndResolveNamedEntities(name);

            System.out.println("**********");
            System.out.println("Name: " + name);
            List<String> outputFields = new ArrayList<>(fields.size() + 1);
            outputFields.addAll(fields);
            if (entities.size() == 0) {
                System.out.println("No match");
                outputFields.add("noMatch");
            } else if (entities.size() == 1) {
                ResolvedNamedEntity entity = entities.get(0);
                NamedEntity ne = entity.getNamedEntity();
                if (ne.getStart() != 0 || ne.getEnd() != name.length()) {
                    System.out.println("Partial match");
                    printEntity(entity);
                    outputFields.add("partialMatch");
                } else {
                    System.out.println("Exact match");
                    printEntity(entity);
                    outputFields.add("exactMatch");
                    List<ChemicalStructure> structures = entity.getChemicalStructures(FormatType.STD_INCHI);
                    for (ChemicalStructure s : structures) {
                        outputFields.add(s.getValue());
                    }
                }
            } else { // Multiple matches found!
                System.out.println("Multiple matches");
                for (ResolvedNamedEntity e : entities) {
                    printEntity(e);
                }
                outputFields.add("multipleMatches");
            }

            writer.write(String.join("\t", outputFields));
            writer.newLine();
        }
    } finally {
        writer.flush();
        writer.close();
    }
}

From source file:com.twitter.bazel.checkstyle.PythonCheckstyle.java

public static void main(String[] args) throws IOException {
    CommandLineParser parser = new DefaultParser();

    // create the Options
    Options options = new Options();
    options.addOption(Option.builder("f").required(true).hasArg().longOpt("extra_action_file")
            .desc("bazel extra action protobuf file").build());
    options.addOption(Option.builder("p").required(true).hasArg().longOpt("pylint_file")
            .desc("Executable pylint file to invoke").build());

    try {//from  ww w . ja va 2s.c om
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        String extraActionFile = line.getOptionValue("f");
        String pylintFile = line.getOptionValue("p");

        Collection<String> sourceFiles = getSourceFiles(extraActionFile);
        if (sourceFiles.size() == 0) {
            LOG.info("No python files found by checkstyle");
            return;
        }

        LOG.info(sourceFiles.size() + " python files found by checkstyle");

        // Create and run the command
        List<String> commandBuilder = new ArrayList<>();
        commandBuilder.add(pylintFile);
        commandBuilder.addAll(sourceFiles);
        runLinter(commandBuilder);

    } catch (ParseException exp) {
        LOG.severe(String.format("Invalid input to %s: %s", CLASSNAME, exp.getMessage()));
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java " + CLASSNAME, options);
    }
}

From source file:Main.java

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

    List<String> list = new ArrayList<String>();
    list.add("A");
    list.add("B");
    list.add("C");
    List<String> list2 = new ArrayList<String>();
    list2.add("X");
    list2.add("Y");
    list2.add("Z");
    list.addAll(list2);
    list.addAll(1, list2);//from  w w w . j  a v a2s .  c  om

    System.out.println(list);
}

From source file:caarray.client.test.full.LoadTest.java

/**
 * @param args/*from   w  ww  . ja  v a 2  s  . c om*/
 */
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:com.etsy.arbiter.Arbiter.java

public static void main(String[] args) throws ParseException, ConfigurationException, IOException,
        ParserConfigurationException, TransformerException {
    Options options = getOptions();//from w ww.  jav  a 2 s .  c o  m

    CommandLineParser cmd = new GnuParser();
    CommandLine parsed = cmd.parse(options, args);

    if (parsed.hasOption("h")) {
        printUsage(options);
    }

    if (!parsed.hasOption("i")) {
        throw new ParseException("Missing required argument: i");
    }

    if (!parsed.hasOption("o")) {
        throw new ParseException("Missing required argument: o");
    }

    String[] configFiles = parsed.getOptionValues("c");
    String[] lowPrecedenceConfigFiles = parsed.getOptionValues("l");

    String[] inputFiles = parsed.getOptionValues("i");
    String outputDir = parsed.getOptionValue("o");

    List<Config> parsedConfigFiles = readConfigFiles(configFiles, false);
    parsedConfigFiles.addAll(readConfigFiles(lowPrecedenceConfigFiles, true));
    Config merged = ConfigurationMerger.mergeConfiguration(parsedConfigFiles);

    List<Workflow> workflows = readWorkflowFiles(inputFiles);

    boolean generateGraphviz = parsed.hasOption("g");
    String graphvizFormat = parsed.getOptionValue("g", "svg");

    OozieWorkflowGenerator generator = new OozieWorkflowGenerator(merged);
    generator.generateOozieWorkflows(outputDir, workflows, generateGraphviz, graphvizFormat);
}

From source file:org.test.LookupSVNUsers.java

/**
 * @param args/*  w ww  . j  a  va  2  s. c  o  m*/
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {

    if (args.length != 2) {
        log.error("USAGE: <svn users file(input)> <git authors file (output)>");

        System.exit(-1);
    }

    Set<String> unmatchedNameSet = new LinkedHashSet<String>();

    Map<String, GitUser> gitUserMap = new LinkedHashMap<String, GitUser>();

    String svnAuthorsFile = args[0];

    List<String> lines = FileUtils.readLines(new File(svnAuthorsFile));

    for (String line : lines) {

        // intentionally handle both upper and lower case varients of the same name.
        String svnUserName = line.trim();

        if (svnUserName.contains("("))
            continue; // skip over this line as we can't use it on the url

        if (gitUserMap.keySet().contains(svnUserName))
            continue; // skip this duplicate.

        log.info("starting on user = " + svnUserName);

        String gitName = extractFullName(svnUserName);

        if (gitName == null) {

            gitName = extractFullName(svnUserName.toLowerCase());
        }

        if (gitName == null) {
            unmatchedNameSet.add(svnUserName);
        } else {

            gitUserMap.put(svnUserName, new GitUser(svnUserName, gitName));
            log.info("mapped user (" + svnUserName + ") to: " + gitName);

        }

    }

    List<String> mergedList = new ArrayList<String>();

    mergedList.add("# GENERATED ");

    List<String> userNameList = new ArrayList<String>();

    userNameList.addAll(gitUserMap.keySet());

    Collections.sort(userNameList);

    for (String userName : userNameList) {

        GitUser gUser = gitUserMap.get(userName);

        mergedList.add(gUser.getSvnAuthor() + " = " + gUser.getGitUser() + " <" + gUser.getSvnAuthor()
                + "@users.sourceforge.net>");

    }

    for (String username : unmatchedNameSet) {

        log.warn("failed to match SVN User = " + username);

        // add in the unmatched entries as is.
        mergedList.add(username + " = " + username + " <" + username + "@users.sourceforge.net>");
    }

    FileUtils.writeLines(new File(args[1]), "UTF-8", mergedList);

}

From source file:com.jslsolucoes.tagria.doc.generator.DocGenerator.java

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

    String workspace = args[0];//from  w ww  . jav a2s.  c  o m
    Map<String, List<Tag>> groupments = new HashMap<>();

    String html = FileUtils.readFileToString(
            new File(workspace + "/tagria-lib/src/main/resources/META-INF/html.tld"), CHARSET);
    String ajax = FileUtils.readFileToString(
            new File(workspace + "/tagria-lib/src/main/resources/META-INF/ajax.tld"), CHARSET);
    XStream xStream = new XStream();
    xStream.processAnnotations(Taglib.class);
    Taglib taglibForHtml = (Taglib) xStream.fromXML(html);
    Taglib taglibForAjax = (Taglib) xStream.fromXML(ajax);
    List<Tag> tags = new ArrayList<Tag>();
    tags.addAll(taglibForHtml.getTags());
    tags.addAll(taglibForAjax.getTags());

    for (Tag tag : tags) {

        List<Tag> groups = groupments.get(tag.getGroup());
        if (groups == null) {
            groupments.put(tag.getGroup(), new ArrayList<>());
        }
        groupments.get(tag.getGroup()).add(tag);

        StringBuilder template = new StringBuilder(
                "<%@include file=\"../app/taglibs.jsp\"%>                              "
                        + "<html:view title=\"{title}\">                                 "
                        + "                  <html:panel>                                                      "
                        + "                     <html:panelHead label=\"" + tag.getName()
                        + "\"></html:panelHead>               "
                        + "                     <html:panelBody>                                                "
                        + "                        <html:tabPanel>                                                "
                        + "                           <html:tab label=\"{about}\" active=\"true\">                     "
                        + "                              <html:alert state=\"warning\">                              "
                        + "                                      " + tag.getDescription()
                        + "                           "
                        + "                              </html:alert>                                          "
                        + "                           </html:tab>                                                "
                        + "                           <html:tab label=\"{attributes}\">                              ");

        if (CollectionUtils.isEmpty(tag.getAttributes())) {
            template.append("<html:alert state=\"info\" label=\"{tag.empty.attributes}\"></html:alert>");
        } else {

            template.append("<html:table><html:tableLine>"
                    + "<html:tableColumn header=\"true\"><fmt:message key=\"tag.attribute\"/></html:tableColumn>"
                    + "<html:tableColumn header=\"true\"><fmt:message key=\"tag.required\"/></html:tableColumn>"
                    + "<html:tableColumn header=\"true\"><fmt:message key=\"tag.type\"/></html:tableColumn>"
                    + "<html:tableColumn header=\"true\"><fmt:message key=\"tag.description\"/></html:tableColumn>"
                    +

                    "</html:tableLine>");

            for (Attribute attribute : tag.getAttributes()) {

                template.append("<html:tableLine>" + "<html:tableColumn>" + attribute.getName()
                        + "</html:tableColumn>" + "<html:tableColumn>"
                        + (attribute.getRequired() == null ? false : true) + "</html:tableColumn>"
                        + "<html:tableColumn>" + attribute.getType() + "</html:tableColumn>"
                        + "<html:tableColumn>" + attribute.getDescription() + "</html:tableColumn>" +

                        "</html:tableLine>");
            }

            template.append("</html:table>");
        }

        template.append("                                                                        "
                + "                           </html:tab>                                                "
                + "                           <html:tab label=\"{demo}\">                                    "
                + "                              " + tag.getExample()
                + "                                          "
                + "                           </html:tab>                                                "
                + "                           <html:tab label=\"{source}\">                                 "
                + "                              <html:code>                                             "
                + "                                 &lt;html:view&gt;" + tag.getExampleEscaped()
                + "&lt;/html:view&gt;                                 "
                + "                              </html:code>                                          "
                + "                           </html:tab>                                                "
                + "                        </html:tabPanel>                                             "
                + "                     </html:panelBody>                                                "
                + "                  </html:panel>                                                      "
                + "               </html:view>                                                         ");
        FileUtils.writeStringToFile(new File(
                workspace + "/tagria-doc/src/main/webapp/WEB-INF/jsp/component/" + tag.getName() + ".jsp"),
                template.toString(), CHARSET);
    }

    for (List<Tag> values : groupments.values()) {
        Collections.sort(values, new Comparator<Tag>() {
            @Override
            public int compare(Tag o1, Tag o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });
    }

    StringBuilder menu = new StringBuilder("<html:div cssClass=\"menu\"><html:listGroup>");
    for (String key : new TreeSet<String>(groupments.keySet())) {
        menu.append("<html:listGroupItem><html:collapsable label=\"" + key + "\"><html:listGroup>");
        for (Tag tag : groupments.get(key)) {
            menu.append("<html:listGroupItem><html:link label=\"" + StringUtils.capitalize(tag.getName())
                    + "\" target=\"conteudo\" url=\"/component/" + tag.getName()
                    + "\"></html:link></html:listGroupItem>");
        }
        menu.append("</html:listGroup></html:collapsable></html:listGroupItem>");
    }
    menu.append("</html:listGroup></html:div>");

    File home = new File(workspace + "/tagria-doc/src/main/webapp/WEB-INF/jsp/app/index.jsp");
    FileUtils.writeStringToFile(home, FileUtils.readFileToString(home, CHARSET)
            .replaceAll("<html:div cssClass=\"menu\">[\\s\\S]*?</html:div>", menu.toString()), CHARSET);

}