Example usage for java.util ArrayList addAll

List of usage examples for java.util ArrayList addAll

Introduction

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

Prototype

public 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.

Usage

From source file:CustomAuthenticationExample.java

public static void main(String[] args) {

    // register the auth scheme
    AuthPolicy.registerAuthScheme(SecretAuthScheme.NAME, SecretAuthScheme.class);

    // include the scheme in the AuthPolicy.AUTH_SCHEME_PRIORITY preference,
    // this can be done on a per-client or per-method basis but we'll do it
    // globally for this example
    HttpParams params = DefaultHttpParams.getDefaultParams();
    ArrayList schemes = new ArrayList();
    schemes.add(SecretAuthScheme.NAME);//from   ww w .ja v  a 2  s. c om
    schemes.addAll((Collection) params.getParameter(AuthPolicy.AUTH_SCHEME_PRIORITY));
    params.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, schemes);

    // now that our scheme has been registered we can execute methods against
    // servers that require "Secret" authentication... 
}

From source file:com.xandrev.altafitcalendargenerator.Main.java

public static void main(String[] args) {
    CalendarPrinter printer = new CalendarPrinter();
    XLSExtractor extractor = new XLSExtractor();
    if (args != null && args.length > 0) {

        try {//w  w w  .j  a va2 s.c  o m
            Options opt = new Options();
            opt.addOption("f", true, "Filepath of the XLS file");
            opt.addOption("t", true, "Type name of activities");
            opt.addOption("m", true, "Month index");
            opt.addOption("o", true, "Output filename of the generated ICS");
            BasicParser parser = new BasicParser();
            CommandLine cliParser = parser.parse(opt, args);
            if (cliParser.hasOption("f")) {
                String fileName = cliParser.getOptionValue("f");
                LOG.debug("File name to be imported: " + fileName);

                String activityNames = cliParser.getOptionValue("t");
                LOG.debug("Activity type names: " + activityNames);

                ArrayList<String> nameList = new ArrayList<>();
                String[] actNames = activityNames.split(",");
                if (actNames != null) {
                    nameList.addAll(Arrays.asList(actNames));
                }
                LOG.debug("Sucessfully activities parsed: " + nameList.size());

                if (cliParser.hasOption("m")) {
                    String monthIdx = cliParser.getOptionValue("m");
                    LOG.debug("Month index: " + monthIdx);
                    int month = Integer.parseInt(monthIdx) - 1;

                    if (cliParser.hasOption("o")) {
                        String outputfilePath = cliParser.getOptionValue("o");
                        LOG.debug("Output file to be generated: " + monthIdx);

                        LOG.debug("Starting to extract the spreadsheet");
                        HashMap<Integer, ArrayList<TimeTrack>> result = extractor.importExcelSheet(fileName);
                        LOG.debug("Extracted the spreadsheet done");

                        LOG.debug("Starting the filter of the data");
                        HashMap<Date, String> cal = printer.getCalendaryByItem(result, nameList, month);
                        LOG.debug("Finished the filter of the data");

                        LOG.debug("Creating the ics Calendar");
                        net.fortuna.ical4j.model.Calendar calendar = printer.createICSCalendar(cal);
                        LOG.debug("Finished the ics Calendar");

                        LOG.debug("Printing the ICS file to: " + outputfilePath);
                        printer.saveCalendar(calendar, outputfilePath);
                        LOG.debug("Finished the ICS file to: " + outputfilePath);
                    }
                }
            }
        } catch (ParseException ex) {
            LOG.error("Error parsing the argument list: ", ex);
        }
    }
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> arrayList = new ArrayList<String>();
    arrayList.add("1");
    arrayList.add("2");
    arrayList.add("3");

    Vector<String> v = new Vector<String>();
    v.add("4");//from   w  w w .  j  a va  2 s.  c o m
    v.add("5");

    // append all elements of Vector to ArrayList
    arrayList.addAll(v);

    for (String str : arrayList)
        System.out.println(str);

}

From source file:edu.oregonstate.eecs.mcplan.domains.taxi.TaxiMDP.java

public static void main(final String[] argv) {
    final int Nother_taxis = 2;
    final double slip = 0.1;
    final double discount = 0.9;
    final RandomGenerator rng = new MersenneTwister(42);
    final TaxiState template = TaxiWorlds.dietterich2000(rng, Nother_taxis, slip);
    final TaxiMDP mdp = new TaxiMDP(template);
    final int Nfeatures = new PrimitiveTaxiRepresentation(template).phi().length;
    final SparseValueIterationSolver<TaxiState, TaxiAction> vi = new SparseValueIterationSolver<TaxiState, TaxiAction>(
            mdp, discount);//from ww w  .  j  a v a  2s .  co m
    vi.run();

    final PrimitiveTaxiRepresenter repr = new PrimitiveTaxiRepresenter(template);
    final ArrayList<Attribute> attr = new ArrayList<Attribute>();
    attr.addAll(repr.attributes());
    attr.add(WekaUtil.createNominalAttribute("__label__", mdp.A().cardinality()));
    final Instances instances = WekaUtil.createEmptyInstances("taxi_" + Nother_taxis + "_pistar", attr);
    final Policy<TaxiState, TaxiAction> pistar = vi.pistar();
    final Generator<TaxiState> g = mdp.S().generator();
    while (g.hasNext()) {
        final TaxiState s = g.next();
        pistar.setState(s, 0L);
        final TaxiAction astar = pistar.getAction();
        final double[] phi = new double[Nfeatures + 1];
        Fn.memcpy_as_double(phi, new PrimitiveTaxiRepresentation(s).phi(), Nfeatures);
        phi[Nfeatures] = mdp.A().index(astar);
        WekaUtil.addInstance(instances, new DenseInstance(1.0, phi));
    }

    WekaUtil.writeDataset(new File("."), instances);
}

From source file:edu.oregonstate.eecs.mcplan.domains.yahtzee2.subtask.StraightMdp.java

public static void main(final String[] argv) throws FileNotFoundException {
    //      final StraightMdp M = new StraightMdp( false );
    //      final YahtzeeDiceState s = new YahtzeeDiceState( new Hand( new int[] { 0, 2, 2, 1, 0, 0 } ), 1 );
    //      final KeepAction a = new KeepAction( new int[] { 0, 1, 1, 0, 0, 0 } );
    ///*from  ww w  .j a  v  a 2  s  .c o m*/
    //      final Pair<ArrayList<YahtzeeDiceState>, ArrayList<Double>> P = M.sparseP( s, a );
    //
    //      for( int i = 0; i < P.first.size(); ++i ) {
    //         System.out.println( P.first.get( i ) + " (" + P.second.get( i ) + ")" );
    //      }

    final RandomGenerator rng = new MersenneTwister(42);
    final double discount = 1.0;

    final boolean small = false;
    final StraightMdp mdp = new StraightMdp(small);
    final int Nfeatures = Hand.Nfaces + 1; // +1 for rerolls
    final SparseValueIterationSolver<YahtzeeDiceState, YahtzeeAction> vi = new SparseValueIterationSolver<YahtzeeDiceState, YahtzeeAction>(
            mdp, discount, 1e-16);
    vi.run();

    final ArrayList<Attribute> attr = new ArrayList<Attribute>();
    attr.addAll(YahtzeeSubtaskStateSpace.attributes());
    attr.add(WekaUtil.createNominalAttribute("__label__", mdp.A().cardinality()));
    final Instances instances = WekaUtil
            .createEmptyInstances("yahtzee_straight_" + (small ? "small" : "large") + "_pistar", attr);
    final Policy<YahtzeeDiceState, YahtzeeAction> pistar = vi.pistar();
    final Generator<YahtzeeDiceState> g = mdp.S().generator();
    while (g.hasNext()) {
        final YahtzeeDiceState s = g.next();
        if (s.isTerminal()) {
            continue;
        }
        pistar.setState(s, 0L);
        final YahtzeeAction astar = pistar.getAction();
        System.out.println("" + s + " -> " + astar);
        final double[] phi = new double[Nfeatures + 1];
        int idx = 0;
        for (int i = 0; i < Hand.Nfaces; ++i) {
            phi[idx++] = s.hand.dice[i];
        }
        phi[idx++] = s.rerolls;
        phi[Nfeatures] = mdp.A().index(astar);
        WekaUtil.addInstance(instances, new DenseInstance(1.0, phi));
    }

    WekaUtil.writeDataset(new File("."), instances);

    final Csv.Writer csv = new Csv.Writer(
            new PrintStream(new FileOutputStream(new File(instances.relationName() + "_action-key.csv"))));
    for (final Map.Entry<ValueType<int[]>, Integer> e : YahtzeeSubtaskActionSpace.index_map.entrySet()) {
        csv.cell(e.getValue()).cell(new KeepAction(e.getKey().get())).newline();
    }

    //      final MeanVarianceAccumulator ret = new MeanVarianceAccumulator();
    //      final MeanVarianceAccumulator steps = new MeanVarianceAccumulator();
    //      final int Ngames = 100000;
    //      for( int i = 0; i < Ngames; ++i ) {
    //         final FuelWorldState s0;
    //         if( choices ) {
    //            s0 = FuelWorldState.createDefaultWithChoices( rng );
    //         }
    //         else {
    //            s0 = FuelWorldState.createDefault( rng );
    //         }
    //         final FuelWorldSimulator sim = new FuelWorldSimulator( s0 );
    //
    //         final Episode<FuelWorldState, FuelWorldAction> episode
    //            = new Episode<FuelWorldState, FuelWorldAction>( sim, JointPolicy.create( pistar ) );
    //         final RewardAccumulator<FuelWorldState, FuelWorldAction> racc
    //            = new RewardAccumulator<FuelWorldState, FuelWorldAction>( sim.nagents(), discount );
    //         episode.addListener( racc );
    //
    //         final long tstart = System.nanoTime();
    //         episode.run();
    //         final long tend = System.nanoTime();
    //         final double elapsed_ms = (tend - tstart) * 1e-6;
    //
    //         ret.add( racc.v()[0] );
    //         steps.add( racc.steps() );
    //      }
    //
    //      System.out.println( "****************************************" );
    //      System.out.println( "Average return: " + ret.mean() );
    //      System.out.println( "Return variance: " + ret.variance() );
    //      System.out.println( "Confidence: " + ret.confidence() );
    //      System.out.println( "Steps (mean): " + steps.mean() );
    //      System.out.println( "Steps (var): " + steps.variance() );
}

From source file:edu.oregonstate.eecs.mcplan.domains.fuelworld.FuelWorldMDP.java

public static void main(final String[] argv) {
    final RandomGenerator rng = new MersenneTwister(42);
    final double discount = 0.99;
    final boolean choices = true;
    final FuelWorldState template;
    if (choices) {
        template = FuelWorldState.createDefaultWithChoices(rng);
    } else {/*from  w  w  w .j  a va 2s . c o  m*/
        template = FuelWorldState.createDefault(rng);
    }

    for (int i = 0; i < template.adjacency.size(); ++i) {
        System.out.print(i);
        System.out.print(" -> {");
        final TIntList succ = template.adjacency.get(i);
        for (int j = 0; j < succ.size(); ++j) {
            System.out.print(" " + succ.get(j));
        }
        System.out.println(" }");
    }

    final FuelWorldMDP mdp = new FuelWorldMDP(template);
    final int Nfeatures = new PrimitiveFuelWorldRepresentation(template).phi().length;
    final SparseValueIterationSolver<FuelWorldState, FuelWorldAction> vi = new SparseValueIterationSolver<FuelWorldState, FuelWorldAction>(
            mdp, discount);
    vi.run();

    final PrimitiveFuelWorldRepresenter repr = new PrimitiveFuelWorldRepresenter();
    final ArrayList<Attribute> attr = new ArrayList<Attribute>();
    attr.addAll(repr.attributes());
    attr.add(WekaUtil.createNominalAttribute("__label__", mdp.A().cardinality()));
    final Instances instances = WekaUtil
            .createEmptyInstances("fuelworld" + (choices ? "_choices" : "") + "_pistar", attr);
    final Policy<FuelWorldState, FuelWorldAction> pistar = vi.pistar();
    final Generator<FuelWorldState> g = mdp.S().generator();
    while (g.hasNext()) {
        final FuelWorldState s = g.next();
        if (s.location == s.goal) {
            continue;
        }
        pistar.setState(s, 0L);
        final FuelWorldAction astar = pistar.getAction();
        System.out.println("" + s + " -> " + astar);
        final double[] phi = new double[Nfeatures + 1];
        Fn.memcpy_as_double(phi, new PrimitiveFuelWorldRepresentation(s).phi(), Nfeatures);
        phi[Nfeatures] = mdp.A().index(astar);
        WekaUtil.addInstance(instances, new DenseInstance(1.0, phi));
    }

    WekaUtil.writeDataset(new File("."), instances);

    final MeanVarianceAccumulator ret = new MeanVarianceAccumulator();
    final MeanVarianceAccumulator steps = new MeanVarianceAccumulator();
    final int Ngames = 100000;
    for (int i = 0; i < Ngames; ++i) {
        final FuelWorldState s0;
        if (choices) {
            s0 = FuelWorldState.createDefaultWithChoices(rng);
        } else {
            s0 = FuelWorldState.createDefault(rng);
        }
        final FuelWorldSimulator sim = new FuelWorldSimulator(s0);

        final Episode<FuelWorldState, FuelWorldAction> episode = new Episode<FuelWorldState, FuelWorldAction>(
                sim, JointPolicy.create(pistar));
        final RewardAccumulator<FuelWorldState, FuelWorldAction> racc = new RewardAccumulator<FuelWorldState, FuelWorldAction>(
                sim.nagents(), discount);
        episode.addListener(racc);

        final long tstart = System.nanoTime();
        episode.run();
        final long tend = System.nanoTime();
        final double elapsed_ms = (tend - tstart) * 1e-6;

        ret.add(racc.v()[0]);
        steps.add(racc.steps());
    }

    System.out.println("****************************************");
    System.out.println("Average return: " + ret.mean());
    System.out.println("Return variance: " + ret.variance());
    System.out.println("Confidence: " + ret.confidence());
    System.out.println("Steps (mean): " + steps.mean());
    System.out.println("Steps (var): " + steps.variance());
}

From source file:deck36.storm.plan9.php.KittenRobbersTopology.java

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

    String env = null;/*from  w ww  .j  av a2s  .c  o  m*/

    if (args != null && args.length > 0) {
        env = args[0];
    }

    if (!"dev".equals(env))
        if (!"prod".equals(env)) {
            System.out.println("Usage: $0 (dev|prod)\n");
            System.exit(1);
        }

    // Topology config
    Config conf = new Config();

    // Load parameters and add them to the Config
    Map configMap = YamlLoader.loadYamlFromResource("config_" + env + ".yml");

    conf.putAll(configMap);

    log.info(JSONValue.toJSONString((conf)));

    // Set topology loglevel to DEBUG
    conf.put(Config.TOPOLOGY_DEBUG, JsonPath.read(conf, "$.deck36_storm.debug"));

    // Create Topology builder
    TopologyBuilder builder = new TopologyBuilder();

    // if there are not special reasons, start with parallelism hint of 1
    // and multiple tasks. By that, you can scale dynamically later on.
    int parallelism_hint = JsonPath.read(conf, "$.deck36_storm.default_parallelism_hint");
    int num_tasks = JsonPath.read(conf, "$.deck36_storm.default_num_tasks");

    String badgeName = KittenRobbersTopology.class.getSimpleName();

    // construct command to invoke the external bolt implementation
    ArrayList<String> command = new ArrayList(15);

    // Add main execution program (php, hhvm, zend, ..) and parameters
    command.add((String) JsonPath.read(conf, "$.deck36_storm.php.executor"));
    command.addAll((List<String>) JsonPath.read(conf, "$.deck36_storm.php.executor_params"));

    // Add main command to be executed (app/console, the phar file, etc.) and global context parameters (environment etc.)
    command.add((String) JsonPath.read(conf, "$.deck36_storm.php.main"));
    command.addAll((List<String>) JsonPath.read(conf, "$.deck36_storm.php.main_params"));

    // Add main route to be invoked and its parameters
    command.add((String) JsonPath.read(conf, "$.deck36_storm.KittenRobbersFromOuterSpaceBolt.main"));
    List boltParams = (List<String>) JsonPath.read(conf,
            "$.deck36_storm.KittenRobbersFromOuterSpaceBolt.params");
    if (boltParams != null)
        command.addAll(boltParams);

    // Log the final command
    log.info("Command to start bolt for KittenRobbersFromOuterSpace: " + Arrays.toString(command.toArray()));

    // Add constructed external bolt command to topology using MultilangAdapterBolt
    builder.setBolt("badge", new MultilangAdapterTickTupleBolt(command,
            (Integer) JsonPath.read(conf, "$.deck36_storm.KittenRobbersFromOuterSpaceBolt.robber_frequency"),
            "badge"), parallelism_hint).setNumTasks(num_tasks);

    builder.setBolt("rabbitmq_router",
            new Plan9RabbitMQRouterBolt(
                    (String) JsonPath.read(conf,
                            "$.deck36_storm.KittenRobbersFromOuterSpaceBolt.rabbitmq.target_exchange"),
                    "KittenRobbers" // RabbitMQ routing key
            ), parallelism_hint).setNumTasks(num_tasks).shuffleGrouping("badge");

    builder.setBolt("rabbitmq_producer", new Plan9RabbitMQPushBolt(), parallelism_hint).setNumTasks(num_tasks)
            .shuffleGrouping("rabbitmq_router");

    if ("dev".equals(env)) {
        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology(badgeName + System.currentTimeMillis(), conf, builder.createTopology());
        Thread.sleep(2000000);
    }

    if ("prod".equals(env)) {
        StormSubmitter.submitTopology(badgeName + "-" + System.currentTimeMillis(), conf,
                builder.createTopology());
    }

}

From source file:it.iit.genomics.cru.structures.bridges.pdb.PDBWSClient.java

/**
 *
 * @param args//from  www. j  a v  a  2  s .c  om
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    String[] pdbId = { "1NKP", "4HHB", "1K1K" };

    ArrayList<String> pdbIds = new ArrayList<>();

    PDBWSClient client = new PDBWSClient();

    pdbIds.addAll(Arrays.asList(pdbId));

    for (StructureID structureId : client.getDescription(pdbIds).getStructureId()) {

        System.out.println(structureId.getId());

        for (Polymer polymer : structureId.getPolymers()) {

            System.out.println(structureId.getId() + "  Polymer  " + polymer.getType());

            for (Chain chain : polymer.getChains()) {
                System.out.println("   chain  " + chain.getId());
            }
        }
    }
    for (Ligand ligand : client.getLigands(pdbIds)) {

        System.out.println(
                ligand.getStructureId() + "   Ligand  " + ligand.getType() + ", " + ligand.getChemicalId());
    }

}

From source file:Main.java

public static void main(String args[]) {
    ArrayList<Integer> arrlist = new ArrayList<Integer>(5);

    arrlist.add(1);/* w  w w.j  a v  a  2s.c o m*/
    arrlist.add(2);
    arrlist.add(4);

    System.out.println(arrlist);

    ArrayList<Integer> arrlist2 = new ArrayList<Integer>(5);
    arrlist2.add(2);
    arrlist2.add(3);
    arrlist2.add(3);
    arrlist2.add(3);

    System.out.println(arrlist2);

    // inserting all elements
    arrlist.addAll(arrlist2);

    System.out.println(arrlist);

}

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  ww  w .  j  a  v  a 2s.c om*/
    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();
}