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:Main.java

public static void main(String[] argv) throws Exception {
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);
    model.addColumn("Col1");
    model.addRow(new Object[] { "r1" });
    model.addRow(new Object[] { "r2" });
    model.addRow(new Object[] { "r3" });

    Vector data = model.getDataVector();
    Vector row = (Vector) data.elementAt(1);
    // Copy the first column
    int mColIndex = 0;
    List colData = new ArrayList(table.getRowCount());
    for (int i = 0; i < table.getRowCount(); i++) {
        row = (Vector) data.elementAt(i);
        colData.add(row.get(mColIndex));
    }/*from w  ww.j  a va2  s. com*/
    JFrame f = new JFrame();
    f.setSize(300, 300);
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:edu.asu.ca.kaushik.algorithms.twostage.TwoStageColoring.java

public static void main(String[] args) throws IOException {
    int t = 0, k1 = 0, k2 = 0, v = 0, times = 0, f = 0, s = 0;

    if (args.length == 7) {
        t = Integer.parseInt(args[0]);
        v = Integer.parseInt(args[1]);
        k1 = Integer.parseInt(args[2]);
        k2 = Integer.parseInt(args[3]);
        times = Integer.parseInt(args[4]);
        f = Integer.parseInt(args[5]);
        s = Integer.parseInt(args[6]);
    } else {//from   ww  w. ja  v  a2  s  .  c  o  m
        System.err.println("Need seven arguments- t, v, kStart, kEnd, times, firstStage and slack percent");
        System.exit(1);
    }

    List<CAGenAlgo> algoList = new ArrayList<CAGenAlgo>();

    algoList.add(new TwoStageColoring(times, f, s));

    OutputFormatter formatter = new TableOutputFormatter("data\\out\\tables\\two-stage",
            "two-stage-coloring-" + times + "-times");

    Runner runner = new Runner(formatter);
    runner.setParam(t, v, k1, k2);
    runner.setAlgos(algoList);
    runner.run();

}

From source file:AllFieldsSnippet.java

public static void main(String[] args) {
    Object obj = new Object();
    //start extract AllFieldsSnippet

    Class cls = obj.getClass();/* ww w. j a v  a 2s  . c  om*/
    List accum = new LinkedList();
    while (cls != null) {
        Field[] f = cls.getDeclaredFields();
        for (int i = 0; i < f.length; i++) {
            accum.add(f[i]);
        }
        cls = cls.getSuperclass();
    }
    Field[] allFields = (Field[]) accum.toArray(new Field[accum.size()]);
    //stop extract AllFieldsSnippet
}

From source file:mxnet.ImageClassification.java

public static void main(String[] args) {
    // Download the model and Image
    downloadModelImage();/*from  w w  w .  j  a  v  a  2s . c o m*/

    // Prepare the model
    List<Context> context = new ArrayList<Context>();
    context.add(Context.cpu());
    List<DataDesc> inputDesc = new ArrayList<>();
    Shape inputShape = new Shape(new int[] { 1, 3, 224, 224 });
    inputDesc.add(new DataDesc("data", inputShape, DType.Float32(), "NCHW"));
    Predictor predictor = new Predictor(modelPath, inputDesc, context, 0);

    // Prepare data
    NDArray nd = Image.imRead(imagePath, 1, true);
    nd = Image.imResize(nd, 224, 224, null);
    nd = NDArray.transpose(nd, new Shape(new int[] { 2, 0, 1 }), null)[0]; // HWC to CHW
    nd = NDArray.expand_dims(nd, 0, null)[0]; // Add N -> NCHW
    nd = nd.asType(DType.Float32()); // Inference with Float32

    // Predict directly
    float[][] result = predictor.predict(new float[][] { nd.toArray() });
    try {
        System.out.println("Predict with Float input");
        System.out.println(printMaximumClass(result[0], modelPath));
    } catch (IOException e) {
        System.err.println(e);
    }

    // predict with NDArray
    List<NDArray> ndList = new ArrayList<>();
    ndList.add(nd);
    List<NDArray> ndResult = predictor.predictWithNDArray(ndList);
    try {
        System.out.println("Predict with NDArray");
        System.out.println(printMaximumClass(ndResult.get(0).toArray(), modelPath));
    } catch (IOException e) {
        System.err.println(e);
    }
}

From source file:org.datacleaner.cluster.http.SimpleMainAppForManualTesting.java

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

    // create a HTTP BASIC enabled HTTP client
    final DefaultHttpClient httpClient = new DefaultHttpClient(new PoolingClientConnectionManager());
    final CredentialsProvider credentialsProvider = httpClient.getCredentialsProvider();
    final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("admin", "admin");
    final List<String> authpref = new ArrayList<String>();
    authpref.add(AuthPolicy.BASIC);
    authpref.add(AuthPolicy.DIGEST);//from w ww.j  av  a2  s .  c o m
    httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
    credentialsProvider.setCredentials(new AuthScope("localhost", 8080), credentials);
    credentialsProvider.setCredentials(new AuthScope("localhost", 9090), credentials);

    // register endpoints
    final List<String> slaveEndpoints = new ArrayList<String>();
    slaveEndpoints.add("http://localhost:8080/DataCleaner-monitor/repository/DC/cluster_slave_endpoint");
    slaveEndpoints.add("http://localhost:9090/DataCleaner-monitor/repository/DC/cluster_slave_endpoint");

    final HttpClusterManager clusterManager = new HttpClusterManager(httpClient, slaveEndpoints);

    final DataCleanerConfiguration configuration = ClusterTestHelper.createConfiguration("manual_test", false);

    // build a job that concats names and inserts the concatenated names
    // into a file
    final AnalysisJobBuilder jobBuilder = new AnalysisJobBuilder(configuration);
    jobBuilder.setDatastore("orderdb");
    jobBuilder.addSourceColumns("CUSTOMERS.CUSTOMERNUMBER", "CUSTOMERS.CUSTOMERNAME",
            "CUSTOMERS.CONTACTFIRSTNAME", "CUSTOMERS.CONTACTLASTNAME");

    AnalyzerComponentBuilder<CompletenessAnalyzer> completeness = jobBuilder
            .addAnalyzer(CompletenessAnalyzer.class);
    completeness.addInputColumns(jobBuilder.getSourceColumns());
    completeness.setConfiguredProperty("Conditions",
            new CompletenessAnalyzer.Condition[] { CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL,
                    CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL,
                    CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL,
                    CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL });

    AnalysisJob job = jobBuilder.toAnalysisJob();
    jobBuilder.close();

    AnalysisResultFuture result = new DistributedAnalysisRunner(configuration, clusterManager).run(job);

    if (result.isErrornous()) {
        throw result.getErrors().get(0);
    }

    final List<AnalyzerResult> results = result.getResults();
    for (AnalyzerResult analyzerResult : results) {
        System.out.println("result:" + analyzerResult);
        if (analyzerResult instanceof CompletenessAnalyzerResult) {
            int invalidRowCount = ((CompletenessAnalyzerResult) analyzerResult).getInvalidRowCount();
            System.out.println("invalid records found: " + invalidRowCount);
        } else {
            System.out.println("class: " + analyzerResult.getClass().getName());
        }
    }
}

From source file:org.eobjects.analyzer.cluster.http.SimpleMainAppForManualTesting.java

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

    // create a HTTP BASIC enabled HTTP client
    final DefaultHttpClient httpClient = new DefaultHttpClient(new PoolingClientConnectionManager());
    final CredentialsProvider credentialsProvider = httpClient.getCredentialsProvider();
    final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("admin", "admin");
    final List<String> authpref = new ArrayList<String>();
    authpref.add(AuthPolicy.BASIC);
    authpref.add(AuthPolicy.DIGEST);/*from   w  w  w .  j  av a2  s.  c  o  m*/
    httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
    credentialsProvider.setCredentials(new AuthScope("localhost", 8080), credentials);
    credentialsProvider.setCredentials(new AuthScope("localhost", 9090), credentials);

    // register endpoints
    final List<String> slaveEndpoints = new ArrayList<String>();
    slaveEndpoints.add("http://localhost:8080/DataCleaner-monitor/repository/DC/cluster_slave_endpoint");
    slaveEndpoints.add("http://localhost:9090/DataCleaner-monitor/repository/DC/cluster_slave_endpoint");

    final HttpClusterManager clusterManager = new HttpClusterManager(httpClient, slaveEndpoints);

    final AnalyzerBeansConfiguration configuration = ClusterTestHelper.createConfiguration("manual_test",
            false);

    // build a job that concats names and inserts the concatenated names
    // into a file
    final AnalysisJobBuilder jobBuilder = new AnalysisJobBuilder(configuration);
    jobBuilder.setDatastore("orderdb");
    jobBuilder.addSourceColumns("CUSTOMERS.CUSTOMERNUMBER", "CUSTOMERS.CUSTOMERNAME",
            "CUSTOMERS.CONTACTFIRSTNAME", "CUSTOMERS.CONTACTLASTNAME");

    AnalyzerJobBuilder<CompletenessAnalyzer> completeness = jobBuilder.addAnalyzer(CompletenessAnalyzer.class);
    completeness.addInputColumns(jobBuilder.getSourceColumns());
    completeness.setConfiguredProperty("Conditions",
            new CompletenessAnalyzer.Condition[] { CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL,
                    CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL,
                    CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL,
                    CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL });

    AnalysisJob job = jobBuilder.toAnalysisJob();
    jobBuilder.close();

    AnalysisResultFuture result = new DistributedAnalysisRunner(configuration, clusterManager).run(job);

    if (result.isErrornous()) {
        throw result.getErrors().get(0);
    }

    final List<AnalyzerResult> results = result.getResults();
    for (AnalyzerResult analyzerResult : results) {
        System.out.println("result:" + analyzerResult);
        if (analyzerResult instanceof CompletenessAnalyzerResult) {
            int invalidRowCount = ((CompletenessAnalyzerResult) analyzerResult).getInvalidRowCount();
            System.out.println("invalid records found: " + invalidRowCount);
        } else {
            System.out.println("class: " + analyzerResult.getClass().getName());
        }
    }
}

From source file:com.turn.ttorrent.client.main.TorrentMain.java

/**
 * Torrent creator./*from   w w w  .  j  a  va 2s  .co  m*/
 *
 * <p>
 * You can use the {@code main()} function of this class to create
 * torrent files. See usage for details.
 * </p>
 */
public static void main(String[] args) throws Exception {
    // BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%-5p: %m%n")));

    OptionParser parser = new OptionParser();
    OptionSpec<Void> helpOption = parser.accepts("help").forHelp();
    OptionSpec<File> inputOption = parser.accepts("input").withRequiredArg().ofType(File.class).required()
            .describedAs("The input file or directory for the torrent.");
    OptionSpec<File> outputOption = parser.accepts("output").withRequiredArg().ofType(File.class).required()
            .describedAs("The output torrent file.");
    OptionSpec<URI> announceOption = parser.accepts("announce").withRequiredArg().ofType(URI.class).required()
            .describedAs("The announce URL for the torrent.");
    parser.nonOptions().ofType(File.class).describedAs("Files to include in the torrent.");

    OptionSet options = parser.parse(args);
    List<?> otherArgs = options.nonOptionArguments();

    // Display help and exit if requested
    if (options.has(helpOption)) {
        System.out.println("Usage: Torrent [<options>] <torrent-file>");
        parser.printHelpOn(System.err);
        System.exit(0);
    }

    List<File> files = new ArrayList<File>();
    for (Object o : otherArgs)
        files.add((File) o);
    Collections.sort(files);

    TorrentCreator creator = new TorrentCreator(options.valueOf(inputOption));
    if (!files.isEmpty())
        creator.setFiles(files);
    creator.setAnnounceList(options.valuesOf(announceOption));
    Torrent torrent = creator.create();

    File file = options.valueOf(outputOption);
    OutputStream fos = FileUtils.openOutputStream(file);
    try {
        torrent.save(fos);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:Main.java

public static void main(String[] argv) {
    List list = new ArrayList();
    int pos = 300;
    int align = TabStop.ALIGN_CENTER;
    int leader = TabStop.LEAD_NONE;
    TabStop tstop = new TabStop(pos, align, leader);
    list.add(tstop);

}

From source file:com.sonatype.nexus.perftest.PerformanceTestAsserter.java

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

    final Nexus nexus = new Nexus();
    ObjectMapper mapper = new XmlMapper();

    mapper.setInjectableValues(new InjectableValues() {
        @Override/* w  w  w .j  a  v a2  s.c  o  m*/
        public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty,
                Object beanInstance) {
            if (Nexus.class.getName().equals(valueId)) {
                return nexus;
            }
            return null;
        }
    });

    File src = new File(args[0]).getCanonicalFile();
    String name = src.getName().substring(0, src.getName().lastIndexOf("."));

    Collection<ClientSwarm> swarms = mapper.readValue(src, PerformanceTest.class).getSwarms();

    List<Metric> metrics = new ArrayList<>();
    for (ClientSwarm swarm : swarms) {
        metrics.add(swarm.getMetric());
    }

    System.out.println("Test " + name + " metrics:" + metrics);
    assertTest(name, metrics);
    System.out.println("Exit");
    System.exit(0);
}

From source file:com.hilatest.httpclient.apacheexample.ClientFormLogin.java

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

    DefaultHttpClient httpclient = new DefaultHttpClient();

    HttpGet httpget = new HttpGet("https://portal.sun.com/portal/dt");

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

    System.out.println("Login form get: " + response.getStatusLine());
    if (entity != null) {
        entity.consumeContent();/* w ww.j  a  v  a2  s.  c  o  m*/
    }
    System.out.println("Initial set of 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());
        }
    }

    HttpPost httpost = new HttpPost("https://portal.sun.com/amserver/UI/Login?" + "org=self_registered_users&"
            + "goto=/portal/dt&" + "gotoOnFail=/portal/dt?error=true");

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("IDToken1", "username"));
    nvps.add(new BasicNameValuePair("IDToken2", "password"));

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

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

    System.out.println("Login form get: " + response.getStatusLine());
    if (entity != null) {
        entity.consumeContent();
    }

    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());
        }
    }

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