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) {

    List list = new ArrayList();
    int pos = 200;
    int align = TabStop.ALIGN_RIGHT;
    int leader = TabStop.LEAD_NONE;
    TabStop tstop = new TabStop(pos, align, leader);
    list.add(tstop);

}

From source file:com.mtea.macrotea_httpclient_study.ClientFormLogin.java

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

    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {// w w w .  ja  v  a 2s  .com
        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());
        //??
        EntityUtils.consume(entity);

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

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

    } finally {
        //??httpclient???
        httpclient.getConnectionManager().shutdown();
    }
}

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

    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));
    }/*  w  w w  .  ja  v  a2  s.  co m*/

    // Append a new column with copied data
    model.addColumn("Col3", colData.toArray());

    JFrame f = new JFrame();
    f.setSize(300, 300);
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:com.dlmu.heipacker.crawler.client.ClientFormLogin.java

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

    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {//from ww w. j a  va 2s .  c  o m
        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());
        EntityUtils.consume(entity);

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

    } 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:org.freewheelschedule.freewheel.common.util.DatabasePopulator.java

@Transactional
public static void main(String[] args) {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-CommonUtil.xml");
    JobDao jobDao = (JobDao) ctx.getBean("jobDao");
    MachineDao machineDao = (MachineDao) ctx.getBean("machineDao");
    TriggerDao triggerDao = (TriggerDao) ctx.getBean("triggerDao");

    Machine machine = new Machine();
    machine.setName("localhost");
    machine.setPort(12145L);/*from   w  ww. j  a va 2 s .c o m*/
    machineDao.create(machine);

    RepeatingTrigger trigger = new RepeatingTrigger();
    trigger.setTriggerInterval(50000L);
    triggerDao.create(trigger);

    CommandJob job = new CommandJob();
    List<Trigger> triggers = new ArrayList<Trigger>();
    triggers.add(trigger);

    job.setName("Test Job");
    job.setCommand("java -version");
    job.setStderr("stderr.log");
    job.setStdout("stdout.log");
    job.setAppendStderr(true);
    job.setExecutingServer(machine);
    job.setTriggers(triggers);

    jobDao.create(job);

    trigger.setJob(job);
    triggerDao.create(trigger);

    TimedTrigger timedTrigger = new TimedTrigger();
    LocalTime triggerTime = new LocalTime();
    timedTrigger.setTriggerTime(triggerTime.plusMinutes(5));
    timedTrigger.setDaysOfWeek(127);
    triggerDao.create(timedTrigger);

    List<Trigger> timedTriggers = new ArrayList<Trigger>();
    timedTriggers.add(timedTrigger);

    CommandJob job2 = new CommandJob();

    job2.setName("Test Job2");
    job2.setCommand("java -version");
    job2.setStderr("stderr.log");
    job2.setStdout("stdout.log");
    job2.setAppendStderr(true);
    job2.setExecutingServer(machine);
    job2.setTriggers(timedTriggers);
    jobDao.create(job2);

    timedTrigger.setJob(job2);
    triggerDao.create(timedTrigger);

    Job readJob = jobDao.readByName("Test Job");
    log.info("Record read: " + readJob);

    //        readJob = jobDao.readById(9999L);
    //        log.info("Record read: " + readJob);
    //
    List<Job> jobs = jobDao.read();
    for (Job job1 : jobs) {
        log.info("All jobs read: " + job1);
    }
}

From source file:Main.java

public static void main(String[] argv) {
    // Create a text pane
    JTextPane textPane = new JTextPane();

    List list = new ArrayList();
    int pos = 400;
    int align = TabStop.ALIGN_DECIMAL;
    int leader = TabStop.LEAD_NONE;
    TabStop tstop = new TabStop(pos, align, leader);
    list.add(tstop);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<Runnable>(48);
    ThreadPoolExecutor testExecutor = new ThreadPoolExecutor(6, 10, 1, TimeUnit.SECONDS, blockingQueue);
    List<Future<String>> futures = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        Future<String> testFuture = testExecutor.submit(new MyCallable(i));
        futures.add(testFuture);
    }//from  ww w. j  a v  a2 s  . c o m
    for (Future<String> testFuture : futures) {
        System.out.println("Output Returned is : " + testFuture.get());
    }
}

From source file:com.ebay.spine.Launcher.java

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

    // not using the default parsing for the hub. Creating a simple one from the default.
    GridHubConfiguration config = new GridHubConfiguration();

    // adding the VNC capable servlet.
    List<String> servlets = new ArrayList<String>();
    servlets.add("web.ConsoleVNC");
    config.setServlets(servlets);/*from   w  ww. j a v a  2s  . c  o m*/

    // capabilities are dynamic for VMs.
    config.setThrowOnCapabilityNotPresent(false);

    // forcing the host from command line param as the hub gets confused by all the VMWare network interfaces.
    for (int i = 0; i < args.length; i++) {
        if (args[i].startsWith("hubhost=")) {
            config.setHost(args[i].replace("hubhost=", ""));
        }
    }

    Hub h = new Hub(config);
    h.start();

    // and the nodes.

    // load the node templates.
    Map<String, JSONObject> templatesByNameMap = getTemplates("eugrid.json");

    // get the template to use for each VM
    Map<String, String> vmsMapping = getVMtoTemplateMapping("nodes.properties");

    // register each node using its template.
    for (String id : vmsMapping.keySet()) {
        String templateName = vmsMapping.get(id);
        JSONObject request = templatesByNameMap.get(templateName);
        request.getJSONObject("configuration").put("vm", id);

        BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST",
                "http://" + hub + "/grid/register/");
        r.setEntity(new StringEntity(request.toString()));
        DefaultHttpClient client = new DefaultHttpClient();
        URL hubURL = new URL("http://" + hub);
        HttpHost host = new HttpHost(hubURL.getHost(), hubURL.getPort());
        HttpResponse response = client.execute(host, r);
    }

}

From source file:com.google.play.developerapi.samples.UploadApkWithListing.java

public static void main(String[] args) {
    try {/*from  w w  w . ja  va 2s. c o m*/
        Preconditions.checkArgument(!Strings.isNullOrEmpty(ApplicationConfig.PACKAGE_NAME),
                "ApplicationConfig.PACKAGE_NAME cannot be null or empty!");

        // Create the API service.
        AndroidPublisher service = AndroidPublisherHelper.init(ApplicationConfig.APPLICATION_NAME,
                ApplicationConfig.SERVICE_ACCOUNT_EMAIL);
        final Edits edits = service.edits();

        // Create a new edit to make changes.
        Insert editRequest = edits.insert(ApplicationConfig.PACKAGE_NAME, null /** no content */
        );
        AppEdit edit = editRequest.execute();
        final String editId = edit.getId();
        log.info(String.format("Created edit with id: %s", editId));

        // Upload new apk to developer console
        final String apkPath = UploadApkWithListing.class.getResource(ApplicationConfig.APK_FILE_PATH).toURI()
                .getPath();
        final AbstractInputStreamContent apkFile = new FileContent(AndroidPublisherHelper.MIME_TYPE_APK,
                new File(apkPath));
        Upload uploadRequest = edits.apks().upload(ApplicationConfig.PACKAGE_NAME, editId, apkFile);
        Apk apk = uploadRequest.execute();
        log.info(String.format("Version code %d has been uploaded", apk.getVersionCode()));

        // Assign apk to beta track.
        List<Integer> apkVersionCodes = new ArrayList<>();
        apkVersionCodes.add(apk.getVersionCode());
        Update updateTrackRequest = edits.tracks().update(ApplicationConfig.PACKAGE_NAME, editId, TRACK_BETA,
                new Track().setVersionCodes(apkVersionCodes));
        Track updatedTrack = updateTrackRequest.execute();
        log.info(String.format("Track %s has been updated.", updatedTrack.getTrack()));

        // Update recent changes field in apk listing.
        final ApkListing newApkListing = new ApkListing();
        newApkListing.setRecentChanges(APK_LISTING_RECENT_CHANGES_TEXT);

        Apklistings.Update updateRecentChangesRequest = edits.apklistings().update(
                ApplicationConfig.PACKAGE_NAME, editId, apk.getVersionCode(), Locale.US.toString(),
                newApkListing);
        updateRecentChangesRequest.execute();
        log.info("Recent changes has been updated.");

        // Commit changes for edit.
        Commit commitRequest = edits.commit(ApplicationConfig.PACKAGE_NAME, editId);
        AppEdit appEdit = commitRequest.execute();
        log.info(String.format("App edit with id %s has been comitted", appEdit.getId()));

    } catch (IOException | URISyntaxException | GeneralSecurityException ex) {
        log.error("Exception was thrown while uploading apk and updating recent changes", ex);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String WRITE_OBJECT_SQL = "BEGIN " + "  INSERT INTO java_objects(object_id, object_name, object_value) "
            + "  VALUES (?, ?, empty_blob()) " + "  RETURN object_value INTO ?; " + "END;";
    String READ_OBJECT_SQL = "SELECT object_value FROM java_objects WHERE object_id = ?";

    Connection conn = getOracleConnection();
    conn.setAutoCommit(false);//from www  . j ava2 s  . co  m
    List<Object> list = new ArrayList<Object>();
    list.add("This is a short string.");
    list.add(new Integer(1234));
    list.add(new java.util.Date());

    // write object to Oracle
    long id = 0001;
    String className = list.getClass().getName();
    CallableStatement cstmt = conn.prepareCall(WRITE_OBJECT_SQL);

    cstmt.setLong(1, id);
    cstmt.setString(2, className);

    cstmt.registerOutParameter(3, java.sql.Types.BLOB);

    cstmt.executeUpdate();
    BLOB blob = (BLOB) cstmt.getBlob(3);
    OutputStream os = blob.getBinaryOutputStream();
    ObjectOutputStream oop = new ObjectOutputStream(os);
    oop.writeObject(list);
    oop.flush();
    oop.close();
    os.close();

    // Read object from oracle
    PreparedStatement pstmt = conn.prepareStatement(READ_OBJECT_SQL);
    pstmt.setLong(1, id);
    ResultSet rs = pstmt.executeQuery();
    rs.next();
    InputStream is = rs.getBlob(1).getBinaryStream();
    ObjectInputStream oip = new ObjectInputStream(is);
    Object object = oip.readObject();
    className = object.getClass().getName();
    oip.close();
    is.close();
    rs.close();
    pstmt.close();
    conn.commit();

    // de-serialize list a java object from a given objectID
    List listFromDatabase = (List) object;
    System.out.println("[After De-Serialization] list=" + listFromDatabase);
    conn.close();
}