Example usage for java.util List add

List of usage examples for java.util List add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Appends the specified element to the end of this list (optional operation).

Usage

From source file:com.bpd.jfreechart.Chart.java

/**
 * Test program that will display a JFreeChart showing interpolated data points.
 * /*from w  w  w .java  2 s  . c  o  m*/
 * @param args <b>"1"</b> to display Series 1. <b>"2"</b> to display Series 2. <b>"0"</b> to
 * display both series.
 */
public static void main(String... args) {
    if (args.length != 1) {
        System.err.println("Usage: java Chart [0|1|2]\n\n  -- 0: Display Series 1.");
        System.err.println("  -- 1: Display Series 2.\n  -- 2: Display both series.");
        return;
    }

    String option = args[0];
    if (!"0".equals(option) && !"1".equals(option) && !"2".equals(option)) {
        System.err.println("Invalid argument: " + option);
        return;
    }

    List<Point<Number, Number>> list1 = new ArrayList<Point<Number, Number>>();
    list1.add(new Point<Number, Number>(100, 100));
    list1.add(new Point<Number, Number>(200, 200));
    list1.add(new Point<Number, Number>(300, 400));
    list1.add(new Point<Number, Number>(400, 200));
    list1.add(new Point<Number, Number>(500, 100));

    List<Point<Number, Number>> list2 = new ArrayList<Point<Number, Number>>();
    list2.add(new Point<Number, Number>(50, 100.0));
    list2.add(new Point<Number, Number>(150, 200.0));
    list2.add(new Point<Number, Number>(250, 400.0));
    list2.add(new Point<Number, Number>(350, 600.0));
    list2.add(new Point<Number, Number>(450, 400.0));
    list2.add(new Point<Number, Number>(550, 200.0));

    List<List<Point<Number, Number>>> lists = new ArrayList<List<Point<Number, Number>>>();
    List<Point<Number, Number>> extrapolatedList1 = new ArrayList<Point<Number, Number>>();
    List<Point<Number, Number>> extrapolatedList2 = new ArrayList<Point<Number, Number>>();
    if ("1".equals(option)) {
        lists.add(list1);
        extrapolatedList1 = Interpolator.interpolate(list1, lists);
    } else if ("2".equals(option)) {
        lists.add(list2);
        extrapolatedList2 = Interpolator.interpolate(list2, lists);
    } else if ("0".equals(option)) {
        lists.add(list1);
        lists.add(list2);
        extrapolatedList1 = Interpolator.interpolate(list1, lists);
        extrapolatedList2 = Interpolator.interpolate(list2, lists);
    }

    TimeSeries series1 = new TimeSeries("Series 1", FixedMillisecond.class);
    for (Point<Number, Number> dataPoint : extrapolatedList1) {
        if ("1".equals(option) || "0".equals(option)) {
            series1.add(new FixedMillisecond(dataPoint.getX().longValue()), dataPoint.getY());
        }
        System.err.println(dataPoint.getX() + "\t" + dataPoint.getY());
    }

    System.err.println();

    TimeSeries series2 = new TimeSeries("Series 2", FixedMillisecond.class);
    for (Point<Number, Number> dataPoint : extrapolatedList2) {
        if ("2".equals(option) || "0".equals(option)) {
            series2.add(new FixedMillisecond(dataPoint.getX().longValue()), dataPoint.getY());
        }
        System.err.println(dataPoint.getX() + "\t" + dataPoint.getY());
    }

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    if ("1".equals(option)) {
        dataset.addSeries(series1);
    } else if ("2".equals(option)) {
        dataset.addSeries(series2);
    } else if ("0".equals(option)) {
        dataset.addSeries(series1);
        dataset.addSeries(series2);
    }

    JFreeChart chart = ChartFactory.createXYLineChart("Test", null, null, dataset, PlotOrientation.VERTICAL,
            false, true, false);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesShapesVisible(1, true);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));

    JFrame frame = new JFrame();
    frame.getContentPane().add(chartPanel);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:com.impetus.ankush.agent.service.ServiceMonitor.java

public static void main(String[] args) {
    ServiceMonitor sm = new ServiceMonitor();
    ComponentService cs = new ComponentService("abcd", "abcdtype");
    List<Parameter> ps = new ArrayList<Parameter>();
    ps.add(new Parameter());

    sm.collectServiceStatus();//from   ww w. j  a va 2  s  . com
}

From source file:com.atlauncher.Bootstrap.java

public static void main(String[] args) {
    String json = null;/*from ww  w.  j a  v  a  2  s .  c  om*/

    if (!Files.isDirectory(PATH)) {
        try {
            Files.createDirectories(PATH);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    try {
        json = IOUtils.toString(URI.create("http://download.nodecdn.net/containers/atl/v4/app.json"));
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }

    Application application = GSON.fromJson(json, Application.class);

    Dependency currentDependency = null;

    if (Files.exists(PATH.resolve("nwjs.json"))) {
        try {
            currentDependency = GSON.fromJson(FileUtils.readFileToString(PATH.resolve("nwjs.json").toFile()),
                    Dependency.class);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    for (Dependency dependency : application.getDependencies()) {
        if (dependency.shouldInstall() && !dependency.matches(currentDependency)) {
            if (Files.isDirectory(PATH.resolve("nwjs/"))) {
                try {
                    FileUtils.deleteDirectory(PATH.resolve("nwjs/").toFile());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            try {
                File zipFile = PATH.resolve("nwjs/temp.zip").toFile();
                FileUtils.copyURLToFile(dependency.getUrl(), zipFile);
                Utils.unzip(zipFile, PATH.resolve("nwjs/").toFile());
                FileUtils.forceDelete(zipFile);

                currentDependency = dependency;

                FileUtils.writeStringToFile(PATH.resolve("nwjs.json").toFile(), GSON.toJson(dependency));

                break;
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }

    App currentApp = null;

    if (Files.exists(PATH.resolve("app.json"))) {
        try {
            currentApp = GSON.fromJson(FileUtils.readFileToString(PATH.resolve("app.json").toFile()),
                    App.class);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    if (!application.getApp().matches(currentApp)
            || (currentApp != null && !Files.exists(PATH.resolve(currentApp.getFilename())))) {
        if (currentApp != null && Files.exists(PATH.resolve(currentApp.getFilename()))) {
            try {
                FileUtils.forceDelete(PATH.resolve(currentApp.getFilename()).toFile());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        try {
            FileUtils.copyURLToFile(application.getApp().getUrl(),
                    PATH.resolve(application.getApp().getFilename()).toFile());

            currentApp = application.getApp();

            FileUtils.writeStringToFile(PATH.resolve("app.json").toFile(), GSON.toJson(application.getApp()));
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    if (currentDependency == null || currentApp == null) {
        System.exit(1);
    }

    List<String> arguments = new ArrayList<>();
    arguments.add(PATH.resolve("nwjs/").toAbsolutePath() + currentDependency.getStartup());
    arguments.add(currentApp.getFilename());
    ProcessBuilder processBuilder = new ProcessBuilder(arguments);
    processBuilder.directory(PATH.toFile());
    try {
        processBuilder.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:edu.harvard.med.screensaver.io.screens.ScreenCreator.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws ParseException {
    final CommandLineApplication app = new CommandLineApplication(args);

    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("first name")
            .withLongOpt("lead-screener-first-name").create("lf"));
    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("last name")
            .withLongOpt("lead-screener-last-name").create("ll"));
    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("email")
            .withLongOpt("lead-screener-email").create("le"));

    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("first name")
            .withLongOpt("lab-head-first-name").create("hf"));
    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("last name")
            .withLongOpt("lab-head-last-name").create("hl"));
    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("email")
            .withLongOpt("lab-head-email").create("he"));

    List<String> desc = new ArrayList<String>();
    for (ScreenType t : EnumSet.allOf(ScreenType.class))
        desc.add(t.name());
    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("screen type")
            .withLongOpt("screen-type").withDescription(StringUtils.makeListString(desc, ", ")).create("st"));
    app.addCommandLineOption(/*from w  w w  .j a  va 2 s  .com*/
            OptionBuilder.hasArg().isRequired().withArgName("summary").withLongOpt("summary").create("s"));
    app.addCommandLineOption(
            OptionBuilder.hasArg().isRequired().withArgName("title").withLongOpt("title").create("t"));
    app.addCommandLineOption(
            OptionBuilder.hasArg().withArgName("protocol").withLongOpt("protocol").create("p"));
    app.addCommandLineOption(
            OptionBuilder.hasArg().isRequired().withArgName("#").withLongOpt("facilityId").create("i"));
    app.addCommandLineOption(OptionBuilder.hasArg(false).withLongOpt("replace")
            .withDescription("replace an existing Screen with the same facilityId").create("r"));

    app.processOptions(/* acceptDatabaseOptions= */false, /* acceptAdminUserOptions= */true);

    try {
        execute(app);
    } catch (Exception e) {
        log.error("Failed to create the screen", e);
        System.exit(1);
    }

}

From source file:com.ds.test.ClientFormLogin.java

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

    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {//  www  .j a  va  2s .  co m
        HttpGet httpget = new HttpGet("http://www.iteye.com/login");

        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();

        System.out.println("Login form get: " + response.getStatusLine());

        System.out.println("cookies:");
        List<Cookie> cookies = httpclient.getCookieStore().getCookies();
        if (cookies.isEmpty()) {
            System.out.println("None");
        } else {
            for (int i = 0; i < cookies.size(); i++) {
                System.out.println(cookies.get(i).toString());
            }
        }

        /* HeaderIterator hi = response.headerIterator();
         while(hi.hasNext()){
            System.out.println(hi.next());
         }
                 
         EntityUtils.consume(entity);
         */

        String token = parseHtml(EntityUtils.toString(entity));

        httpget.releaseConnection();

        System.out.println("********************************************************");

        HttpPost httpost = new HttpPost("http://www.iteye.com/login");

        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("name", ""));
        nvps.add(new BasicNameValuePair("password", ""));
        nvps.add(new BasicNameValuePair("authenticity_token", token));

        httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));

        response = httpclient.execute(httpost);
        entity = response.getEntity();

        System.out.println("Login form get: " + response.getStatusLine());
        EntityUtils.consume(entity);

        System.out.println("Post logon cookies:");
        cookies = httpclient.getCookieStore().getCookies();
        if (cookies.isEmpty()) {
            System.out.println("None");
        } else {
            for (int i = 0; i < cookies.size(); i++) {
                System.out.println(cookies.get(i).toString());
            }
        }

        System.out.println("********************************************************");

        HttpGet httpget2 = new HttpGet("http://www.iteye.com/login");

        HttpResponse response2 = httpclient.execute(httpget2);
        HttpEntity entity2 = response2.getEntity();

        System.out.println("Login form get: " + response2.getStatusLine());

        print(response2);

    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:com.khartec.waltz.jobs.sample.ServerGenerator.java

public static void main(String[] args) {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    ServerInformationDao serverDao = ctx.getBean(ServerInformationDao.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    dsl.delete(SERVER_INFORMATION).where(SERVER_INFORMATION.PROVENANCE.eq("RANDOM_GENERATOR")).execute();

    List<ServerInformation> servers = ListUtilities.newArrayList();

    IntStream//from  www  .  j a  v  a  2s .  com
            .range(0,
                    10_000)
            .forEach(
                    i -> servers
                            .add(ImmutableServerInformation.builder().hostname(mkHostName(i))
                                    .environment(randomPick(SampleData.environments))
                                    .location(randomPick(SampleData.locations))
                                    .operatingSystem(randomPick(SampleData.operatingSystems))
                                    .operatingSystemVersion(randomPick(SampleData.operatingSystemVersions))
                                    .country(
                                            "UK")
                                    .assetCode(
                                            "wltz-0" + rnd.nextInt(4000))
                                    .hardwareEndOfLifeDate(rnd.nextInt(10) > 5
                                            ? Date.valueOf(
                                                    LocalDate.now().plusMonths(rnd.nextInt(12 * 6) - (12 * 3)))
                                            : null)
                                    .operatingSystemEndOfLifeDate(rnd.nextInt(10) > 5
                                            ? Date.valueOf(
                                                    LocalDate.now().plusMonths(rnd.nextInt(12 * 6) - (12 * 3)))
                                            : null)
                                    .virtual(rnd.nextInt(10) > 7).provenance("RANDOM_GENERATOR").build()));

    // servers.forEach(System.out::println);
    serverDao.bulkSave(servers);

}

From source file:com.github.stagirs.lingvo.build.SyntaxStatisticsBuilder.java

public static void main(String[] args) throws Exception {
    TObjectIntHashMap<String> map = new TObjectIntHashMap<String>();
    for (String line : FileUtils.readLines(new File("annot.opcorpora.no_ambig.plain"), "utf-8")) {
        List<String> types = types(Annotation.parse(line));
        if (types.isEmpty()) {
            continue;
        }/*from ww w.j a v  a 2  s .  c o  m*/
        map.adjustOrPutValue(types.get(0), 1, 1);
        map.adjustOrPutValue(" " + types.get(0), 1, 1);
        for (int i = 1; i < types.size(); i++) {
            map.adjustOrPutValue(types.get(i), 1, 1);
            map.adjustOrPutValue(types.get(i - 1) + " " + types.get(i), 1, 1);
        }
        map.adjustOrPutValue(types.get(types.size() - 1) + " ", 1, 1);
    }
    final List<String> result = new ArrayList<String>();
    map.forEachEntry(new TObjectIntProcedure<String>() {
        @Override
        public boolean execute(String key, int count) {
            result.add(key + "\t" + count);
            return true;
        }
    });
    FileUtils.writeLines(new File("src/main/resources/SyntaxStatistics"), "utf-8", result);
}

From source file:com.bpd.jfreechart.StackedAreaChartDemo.java

/**
 * Test program that will display a JFreeChart showing interpolated data points.
 * /*from w  w w.java  2  s .c o m*/
 * @param args <b>"1"</b> to display Series 1. <b>"2"</b> to display Series 2. <b>"0"</b> to
 * display both series.
 */
public static void main(String... args) {
    // Check arguments.
    if (args.length != 1) {
        System.err.println("Usage: java Chart [0|1|2]\n\n  -- 0: Display Series 1.");
        System.err.println("  -- 1: Display Series 2.\n  -- 2: Display both series.");
        return;
    }

    String option = args[0];
    if (!"0".equals(option) && !"1".equals(option) && !"2".equals(option)) {
        System.err.println("Invalid argument: " + option);
        return;
    }

    // Create some sample data.
    List<Point<Number, Number>> list1 = new ArrayList<Point<Number, Number>>();
    list1.add(new Point<Number, Number>(50, 100.0));
    list1.add(new Point<Number, Number>(150, 100));
    list1.add(new Point<Number, Number>(250, 200));
    list1.add(new Point<Number, Number>(350, 400));
    list1.add(new Point<Number, Number>(450, 200));
    list1.add(new Point<Number, Number>(550, 100));

    List<Point<Number, Number>> list2 = new ArrayList<Point<Number, Number>>();
    list2.add(new Point<Number, Number>(50, 100.0));
    list2.add(new Point<Number, Number>(150, 200.0));
    list2.add(new Point<Number, Number>(250, 400.0));
    list2.add(new Point<Number, Number>(350, 600.0));
    list2.add(new Point<Number, Number>(450, 400.0));
    list2.add(new Point<Number, Number>(550, 200.0));

    // Add data to time series.
    TimeSeries series1 = new TimeSeries("Series 1", FixedMillisecond.class);
    for (Point<Number, Number> dataPoint : list1) {
        if ("1".equals(option) || "0".equals(option)) {
            series1.add(new FixedMillisecond(dataPoint.getX().longValue()), dataPoint.getY());
        }
        series1.setDescription("Series 1");
    }

    TimeSeries series2 = new TimeSeries("Series 2", FixedMillisecond.class);
    for (Point<Number, Number> dataPoint : list2) {
        if ("2".equals(option) || "0".equals(option)) {
            series2.add(new FixedMillisecond(dataPoint.getX().longValue()), dataPoint.getY());
        }
        series2.setDescription("Series 2");
    }

    TimeSeriesCollection collection = new TimeSeriesCollection();
    if ("1".equals(option)) {
        collection.addSeries(series1);
    } else if ("2".equals(option)) {
        collection.addSeries(series2);
    } else if ("0".equals(option)) {
        collection.addSeries(series1);
        collection.addSeries(series2);
    }

    TimeTableXYDataset dataset = new TimeTableXYDataset();
    @SuppressWarnings("unchecked")
    List<TimeSeries> timeSeriesList = collection.getSeries();
    for (TimeSeries t : timeSeriesList) {
        for (int index = 0; index < t.getItemCount(); index++) {
            TimeSeriesDataItem dataItem = (TimeSeriesDataItem) t.getItems().get(index);
            dataset.add(t.getTimePeriod(index), dataItem.getValue().doubleValue(), t.getDescription());
        }
    }

    // Create and display chart.
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(null, null, null, dataset,
            PlotOrientation.VERTICAL, false, true, false);

    customizeChart(chart);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));

    JFrame frame = new JFrame();
    frame.getContentPane().add(chartPanel);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:de.tudarmstadt.ukp.csniper.resbuild.stuff.FilterPipe.java

public static void main(String[] args) throws IOException {
    List<String> files = new ArrayList<String>();
    int i = 0;/*from ww w . ja  va 2s .c  om*/
    for (File file : FileUtils.listFiles(new File(base), new String[] { "csv" }, true)) {
        String text = FileUtils.readFileToString(file, "UTF-8");
        files.add(StringUtils.substringBeforeLast(file.getName(), ".") + ".xml");
        if (StringUtils.containsAny(text, "")) {
            files.remove(StringUtils.substringBeforeLast(file.getName(), ".") + ".xml");
        }
        i++;
        if (i % 100 == 0) {
            System.out.println("ok:" + i);
        }
    }

    FileUtils.writeLines(new File("D:\\hadoop\\output\\BNC_new\\exclusions.txt"), "UTF-8", files);
}

From source file:dk.alexandra.fresco.framework.configuration.ConfigurationGenerator.java

public static void main(String args[]) {
    if (args.length == 0) {
        usage();//from www .  j  a v a  2s  . c  o  m
    }

    if (args.length % 2 != 0) {
        System.out.println("Incorrect number of arguments: " + Arrays.asList(args) + ".");
        System.out.println();
        usage();
    }

    List<Pair<String, Integer>> hosts = new LinkedList<Pair<String, Integer>>();
    int inx = 0;
    try {

        for (; inx < args.length; inx = inx + 2) {
            hosts.add(new Pair<String, Integer>(args[inx], new Integer(args[inx + 1])));
        }
    } catch (NumberFormatException ex) {
        System.out.println("Invalid argument for port: \"" + args[inx + 1] + "\".");
        System.exit(1);
    }

    inx = 1;
    try {
        for (; inx < hosts.size() + 1; inx++) {
            String filename = "party-" + inx + ".ini";
            OutputStream out = new FileOutputStream(filename);
            new ConfigurationGenerator().generate(inx, out, hosts);
            out.close();
            System.out.println("Created configuration file: " + filename + ".");
        }
    } catch (Exception ex) {
        System.out.println("Could not write to file: party-" + inx + ".ini.");
        System.exit(1);
    }

}