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[] args) {
    List<Integer> list = new ArrayList<>();
    long expectedSum = 0;
    for (int i = 0; i < 10000; i++) {
        int random = 1 + (int) (Math.random() * ((100 - 1) + 1));
        list.add(random);
        expectedSum += random;/*from ww w.j a  v a  2 s  .c  o  m*/
    }
    System.out.println("expected sum: " + expectedSum);
    ForkJoinPool forkJoinPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors());
    RecursiveSum recursiveSum = new RecursiveSum(list, 0, list.size());
    long recSum = forkJoinPool.invoke(recursiveSum);
    System.out.println("recursive-sum: " + recSum);
}

From source file:httpclient.client.ClientFormLogin.java

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

    // prepare parameters
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setUserAgent(params, Constants.BROWSER_TYPE);
    HttpProtocolParams.setUseExpectContinue(params, true);
    DefaultHttpClient httpclient = new DefaultHttpClient(params);

    String loginURL = "http://10.1.1.251/login.asp";
    HttpGet httpget = new HttpGet(loginURL);
    HttpResponse response = httpclient.execute(httpget);
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        entity.consumeContent();//from w ww.j a va2  s .c om
    }
    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(loginURL);
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("name", "fangdj"));
    nvps.add(new BasicNameValuePair("passwd", "1111"));

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

    response = httpclient.execute(httpost);
    entity = response.getEntity();
    for (Header h : response.getAllHeaders()) {
        System.out.println(h);
    }
    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());
        }
    }

    String mainURL = "http://10.1.1.251/ONWork/Record_save.asp";

    HttpPost mainHttPost = new HttpPost(mainURL);
    List<NameValuePair> mainNvps = new ArrayList<NameValuePair>();
    mainNvps.add(new BasicNameValuePair("EMP_NO", "13028"));
    mainNvps.add(new BasicNameValuePair("pwd", "1111"));
    mainNvps.add(new BasicNameValuePair("cmd2", "Apply"));

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

    response = httpclient.execute(mainHttPost);
    System.out.println(Tools.InputStreamToString(response.getEntity().getContent()));
    // 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.sm.store.server.grizzly.RemoteScan4ReplicaServer.java

public static void main(String[] args) {
    String[] opts = new String[] { "-configPath", "-start" };
    String[] defaults = new String[] { "./config", "true" };
    String[] paras = getOpts(args, opts, defaults);

    String configPath = paras[0];
    if (configPath.length() == 0) {
        logger.error("missing config path");
        throw new RuntimeException("missing -configPath");
    }/*from  w w w.  j a  v a  2 s .  com*/
    //make sure path is in proper format
    configPath = getPath(configPath);
    boolean start = Boolean.valueOf(paras[1]);
    logger.info("read stores.xml from " + configPath);
    BuildRemoteConfig bsc = new BuildRemoteConfig(configPath + "/stores.xml");
    GZScan4RemoteServer cs = new GZScan4RemoteServer(bsc.build());
    logger.info("hookup jvm shutdown process");
    cs.hookShutdown();
    if (start) {
        logger.info("server is starting " + cs.toString());
        cs.startServer();
    } else
        logger.warn("server is staged and wait to be started");
    List list = new ArrayList();
    //add jmx metric
    List<String> stores = cs.getAllStoreNames();
    for (String store : stores) {
        list.add(cs.getRemoteStore(store));
    }
    // add additional name into list for Scan4RemoteServer
    list.add(cs);
    stores.add("Scan4RemoteServer");
    JmxService jms = new JmxService(list, stores);
}

From source file:com.sm.store.server.netty.RemoteScan4ReplicaServer.java

public static void main(String[] args) {
    String[] opts = new String[] { "-configPath", "-start" };
    String[] defaults = new String[] { "./config", "true" };
    String[] paras = getOpts(args, opts, defaults);

    String configPath = paras[0];
    if (configPath.length() == 0) {
        logger.error("missing config path");
        throw new RuntimeException("missing -configPath");
    }/*  ww w .java  2s . c  o  m*/
    //make sure path is in proper format
    configPath = getPath(configPath);
    boolean start = Boolean.valueOf(paras[1]);
    logger.info("read stores.xml from " + configPath);
    BuildRemoteConfig bsc = new BuildRemoteConfig(configPath + "/stores.xml");
    Scan4RemoteServer cs = new Scan4RemoteServer(bsc.build());
    logger.info("hookup jvm shutdown process");
    cs.hookShutdown();
    if (start) {
        logger.info("server is starting " + cs.toString());
        cs.startServer();
    } else
        logger.warn("server is staged and wait to be started");
    List list = new ArrayList();
    //add jmx metric
    List<String> stores = cs.getAllStoreNames();
    for (String store : stores) {
        list.add(cs.getRemoteStore(store));
    }
    // add additional name into list for Scan4RemoteServer
    list.add(cs);
    stores.add("Scan4RemoteServer");
    JmxService jms = new JmxService(list, stores);
}

From source file:Main.java

public static void main(String... args) {
    final int MAX_VAL = 99999;
    List<Integer> linkedList = new LinkedList<Integer>();
    List<Integer> arrayList = new ArrayList<Integer>();
    for (int i = 0; i < MAX_VAL; i++) {
        linkedList.add(i);
        arrayList.add(i);//  www  .java 2  s. c o m
    }
    long time = System.nanoTime();

    for (int i = 0; i < MAX_VAL; i++) {
        linkedList.add(MAX_VAL / 2, i);
    }
    System.out.println("LinkedList add:" + (System.nanoTime() - time));

    time = System.nanoTime();
    for (int i = 0; i < MAX_VAL; i++) {
        arrayList.add(MAX_VAL / 2, i);
    }
    System.out.println("ArrayList add:" + (System.nanoTime() - time));

    // Reset the lists
    linkedList = new LinkedList<Integer>();
    arrayList = new ArrayList<Integer>();
    for (int i = 0; i < MAX_VAL; i++) {
        linkedList.add(i);
        arrayList.add(i);
    }

    time = System.nanoTime();
    ListIterator<Integer> li = linkedList.listIterator(MAX_VAL / 2);
    for (int i = 0; i < MAX_VAL; i++) {
        li.add(i);
    }
    System.out.println("LinkedList iterator add:" + (System.nanoTime() - time));

    time = System.nanoTime();
    ListIterator<Integer> ali = arrayList.listIterator(MAX_VAL / 2);
    for (int i = 0; i < MAX_VAL; i++) {
        ali.add(i);
    }
    System.out.println("ArrayList iterator add:" + (System.nanoTime() - time));
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    List mylist = new ArrayList();
    for (int i = 0; i < args.length; i++) {
        FileInputStream in = new FileInputStream(args[i]);
        Certificate c = cf.generateCertificate(in);
        mylist.add(c);
    }//w  w  w .j  av a2s  .  com
    CertPath cp = cf.generateCertPath(mylist);
    List cplist = cp.getCertificates();
    Object[] o = cplist.toArray();
    for (int i = 0; i < o.length; i++) {
        X509Certificate c = (X509Certificate) o[i];
        System.out.println(c.getSubjectDN());
        byte[] pbk = c.getPublicKey().getEncoded();
        for (int j = 0; j < pbk.length; j++) {
            System.out.print(pbk[j] + ",");
        }
        System.out.println("\nIssued by " + c.getIssuerDN());
    }
}

From source file:edu.cmu.lti.oaqa.bio.index.medline.annotated.query.SimpleQueryApp.java

public static void main(String[] args) {
    Options options = new Options();

    options.addOption("u", null, true, "Solr URI");
    options.addOption("n", null, true, "Max # of results");

    CommandLineParser parser = new org.apache.commons.cli.GnuParser();

    try {/* w w w  . j  ava 2  s .c om*/
        CommandLine cmd = parser.parse(options, args);
        String solrURI = null;

        solrURI = cmd.getOptionValue("u");
        if (solrURI == null) {
            Usage("Specify Solr URI");
        }

        SolrServerWrapper solr = new SolrServerWrapper(solrURI);

        int numRet = 10;

        if (cmd.hasOption("n")) {
            numRet = Integer.parseInt(cmd.getOptionValue("n"));
        }

        List<String> fieldList = new ArrayList<String>();
        fieldList.add(UtilConstMedline.ID_FIELD);
        fieldList.add(UtilConstMedline.SCORE_FIELD);
        fieldList.add(UtilConstMedline.ARTICLE_TITLE_FIELD);
        fieldList.add(UtilConstMedline.ENTITIES_DESC_FIELD);
        fieldList.add(UtilConstMedline.ABSTRACT_TEXT_FIELD);

        BufferedReader sysInReader = new BufferedReader(new InputStreamReader(System.in));
        Joiner commaJoiner = Joiner.on(',');

        while (true) {
            System.out.println("Input query: ");
            String query = sysInReader.readLine();
            if (null == query)
                break;

            QueryTransformer qt = new QueryTransformer(query);

            String tranQuery = qt.getQuery();

            System.out.println("Translated query:");
            System.out.println(tranQuery);
            System.out.println("=========================");

            SolrDocumentList res = solr.runQuery(tranQuery, fieldList, numRet);

            System.out.println("Found " + res.getNumFound() + " entries");

            for (SolrDocument doc : res) {
                String id = (String) doc.getFieldValue(UtilConstMedline.ID_FIELD);
                float score = (Float) doc.getFieldValue(UtilConstMedline.SCORE_FIELD);
                String title = (String) doc.getFieldValue(UtilConstMedline.ARTICLE_TITLE_FIELD);
                String titleAbstract = (String) doc.getFieldValue(UtilConstMedline.ABSTRACT_TEXT_FIELD);

                System.out.println(score + " PMID=" + id + " " + titleAbstract);

                String entityDesc = (String) doc.getFieldValue(UtilConstMedline.ENTITIES_DESC_FIELD);
                System.out.println("Entities:");
                for (EntityEntry e : EntityEntry.parseEntityDesc(entityDesc)) {
                    System.out.println(String.format("[%d %d] concept=%s concept_ids=%s", e.mStart, e.mEnd,
                            e.mConcept, commaJoiner.join(e.mConceptIds)));
                }
            }
        }

        solr.close();

    } catch (ParseException e) {
        Usage("Cannot parse arguments");
    } catch (Exception e) {
        System.err.println("Terminating due to an exception: " + e);
        System.exit(1);
    }
}

From source file:com.dianping.maven.plugin.tools.wms.WorkspaceManagementServiceImpl.java

public static void main(String[] args) throws Exception {
    WorkspaceManagementServiceImpl wms = new WorkspaceManagementServiceImpl();
    wms.setRepositoryManager(new RepositoryManager() {

        @Override//from  ww w  .  j  a  va 2  s . c o m
        public Repository find(String project) {
            if ("shop-web".equals(project)) {
                return new SvnRepository("http://192.168.8.45:81/svn/dianping/dianping/shop/trunk/shop-web/",
                        "-", "-", -1l);
            } else if ("user-web".equals(project)) {
                return new SvnRepository("http://192.168.8.45:81/svn/dianping/dianping/user/trunk/user-web/",
                        "-", "-", -1l);
            } else {
                return null;
            }
        }
    });
    WorkspaceContext context = new WorkspaceContext();
    List<String> projects = new ArrayList<String>();
    projects.add("shop-web");
    // projects.add("user-web");
    context.setProjects(projects);
    context.setBaseDir(new File("/Users/leoleung/test"));
    wms.create(context, System.out);
}

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

/**
 * @param args//from w w w .  j a  v  a 2 s  . com
 * @throws IOException 
 */
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 {
        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 TwoStageOnlineGreedy(times, f, s));

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

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

From source file:me.smoe.adar.pool.commonpool.CommonPool.java

public static void main(String[] args) throws NoSuchElementException, IllegalStateException, Exception {
    GenericObjectPool<Book> objectPool = new GenericObjectPool<Book>(new BookPoolFactory(),
            buildPoolConfig(5, 10, 2));/*w w  w.ja v a  2 s .  co  m*/
    prestartCorePool(objectPool);

    List<Book> books = new LinkedList<Book>();
    for (int i = 0; i < 10; i++) {
        books.add(objectPool.borrowObject());
    }

    for (Book book : books) {
        objectPool.returnObject(book);
    }
}