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.rmzone.core.App.java

public static void main(String[] args) {
    // set up mongo
    ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringMongoConfig.class);
    MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");

    // create and save some users
    List<User> users = new ArrayList<User>();
    users.add(new User("1001", "foo", "bar"));
    users.add(new User("1002", "mickey", "mouse"));

    for (User user : users)
        mongoOperation.save("users", user);

    // create and save some documents
    Tire tire = new Tire("Michelin", "Alpine", 1, users.get(0), Calendar.getInstance().getTime(), 14, 12, 3);
    mongoOperation.save("documents", tire);

    Engine engine = new Engine("Model T", "Wow", 1, users.get(0), Calendar.getInstance().getTime());
    engine.setHorsePower(16.4f);/* ww w. j  a  v  a 2 s  . c o m*/
    mongoOperation.save("documents", engine);

    Car car = new Car("Pinto", "don't touch me!", 1, users.get(0), Calendar.getInstance().getTime());
    car.setMake("Ford");
    car.setColor("Blue");
    car.setEngine(engine);

    // sorry not very elegant
    car.setTires(new ArrayList<Tire>());
    for (int i = 0; i < 4; i++)
        car.getTires().add(tire);
    mongoOperation.save("documents", car);

    // dump all the data        
    List<User> listUser = mongoOperation.getCollection("users", User.class);
    System.out.println("Number of users = " + listUser.size());
    for (User user : listUser)
        System.out.println(user.toString());

    List<DocumentMaster> listDocument = mongoOperation.getCollection("documents", DocumentMaster.class);
    System.out.println("Number of documents = " + listDocument.size());
    for (DocumentMaster document1 : listDocument)
        System.out.println(document1.toString());

    // delete everything
    mongoOperation.dropCollection("users");
    mongoOperation.dropCollection("documents");
}

From source file:com.netscape.certsrv.key.AsymKeyGenerationRequest.java

public static void main(String[] args) {
    AsymKeyGenerationRequest request = new AsymKeyGenerationRequest();
    request.setKeyAlgorithm(KeyRequestResource.RSA_ALGORITHM);
    request.setKeySize(1024);/* ww  w. j  av  a  2  s . c o m*/
    request.setClientKeyId("vek12345");
    List<String> usages = new ArrayList<String>();
    usages.add(AsymKeyGenerationRequest.ENCRYPT);
    usages.add(AsymKeyGenerationRequest.DECRYPT);
    request.setUsages(usages);
    request.setRealm("ipa-vault");

    System.out.println(request.toString());
}

From source file:mxnet.ObjectDetection.java

public static void main(String[] args) {
    List<Context> context = new ArrayList<Context>();
    context.add(Context.cpu());
    downloadModelImage();//from ww w  . ja v  a 2  s . c o  m

    List<List<ObjectDetectorOutput>> output = runObjectDetectionSingle(modelPath, imagePath, context);

    Shape inputShape = new Shape(new int[] { 1, 3, 512, 512 });
    Shape outputShape = new Shape(new int[] { 1, 6132, 6 });
    int width = inputShape.get(2);
    int height = inputShape.get(3);
    String outputStr = "\n";

    for (List<ObjectDetectorOutput> ele : output) {
        for (ObjectDetectorOutput i : ele) {
            outputStr += "Class: " + i.getClassName() + "\n";
            outputStr += "Probabilties: " + i.getProbability() + "\n";

            List<Float> coord = Arrays.asList(i.getXMin() * width, i.getXMax() * height, i.getYMin() * width,
                    i.getYMax() * height);
            StringBuilder sb = new StringBuilder();
            for (float c : coord) {
                sb.append(", ").append(c);
            }
            outputStr += "Coord:" + sb.substring(2) + "\n";
        }
    }
    System.out.println(outputStr);
}

From source file:Employee.java

public static void main(String[] args) {
    String[] names = { "A", "B", "C", "D" };

    double[] salaries = { 2.0, 5.0, 6.0, 4.0 };

    List l = new ArrayList();

    for (int i = 0; i < names.length; i++)
        l.add(new Employee(names[i], salaries[i]));

    Collections.sort(l);/* ww  w.  ja v  a 2  s  .c o  m*/

    ListIterator liter = l.listIterator();

    while (liter.hasNext())
        System.out.println(liter.next());

    Collections.sort(l, new Employee.SalaryComparator());

    liter = l.listIterator();

    while (liter.hasNext())
        System.out.println(liter.next());
}

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

public static void main(String[] args) throws Exception {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet("http://targethost/homepage");

    HttpResponse response1 = httpclient.execute(httpGet);

    // The underlying HTTP connection is still held by the response object 
    // to allow the response content to be streamed directly from the network socket. 
    // In order to ensure correct deallocation of system resources 
    // the user MUST either fully consume the response content  or abort request 
    // execution by calling HttpGet#releaseConnection().

    try {/*from  w w w  .  j a  v a 2 s  .  c o m*/
        System.out.println(response1.getStatusLine());
        HttpEntity entity1 = response1.getEntity();
        // do something useful with the response body
        // and ensure it is fully consumed
        EntityUtils.consume(entity1);
    } finally {
        httpGet.releaseConnection();
    }

    HttpPost httpPost = new HttpPost("http://targethost/login");
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("username", "vip"));
    nvps.add(new BasicNameValuePair("password", "secret"));
    httpPost.setEntity(new UrlEncodedFormEntity(nvps));
    HttpResponse response2 = httpclient.execute(httpPost);

    try {
        System.out.println(response2.getStatusLine());
        HttpEntity entity2 = response2.getEntity();
        // do something useful with the response body
        // and ensure it is fully consumed
        EntityUtils.consume(entity2);
    } finally {
        httpPost.releaseConnection();
    }
}

From source file:postenergy.TestHttpClient.java

public static void main(String[] args) {
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("https://www.google.com/accounts/ClientLogin");

    try {/*from ww w  . ja v a 2  s  .com*/

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("Email", "youremail"));
        nameValuePairs.add(new BasicNameValuePair("Passwd", "yourpassword"));
        nameValuePairs.add(new BasicNameValuePair("accountType", "GOOGLE"));
        nameValuePairs.add(new BasicNameValuePair("source", "Google-cURL-Example"));
        nameValuePairs.add(new BasicNameValuePair("service", "ac2dm"));

        post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = client.execute(post);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

        String line = "";
        while ((line = rd.readLine()) != null) {
            System.out.println(line);
            if (line.startsWith("Auth=")) {
                String key = line.substring(5);
                // do something with the key
            }

        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String args[]) {

    List<String> srclst = new ArrayList<String>(5);
    List<String> destlst = new ArrayList<String>(10);

    // populate two lists
    srclst.add("tutorial");
    srclst.add("from");
    srclst.add("java2s.com");

    destlst.add("Java Tutorial");
    destlst.add("From");
    destlst.add("Java2s.com");

    // copy into dest list
    Collections.copy(destlst, srclst);

    System.out.println("Value of source list: " + srclst);
    System.out.println("Value of destination list: " + destlst);
}

From source file:com.ok2c.lightmtp.examples.MailUserAgentExample.java

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

    String text1 = "From: root\r\n" + "To: testuser1\r\n" + "Subject: test message 1\r\n" + "\r\n"
            + "This is a short test message 1\r\n";
    String text2 = "From: root\r\n" + "To: testuser1, testuser2\r\n" + "Subject: test message 2\r\n" + "\r\n"
            + "This is a short test message 2\r\n";
    String text3 = "From: root\r\n" + "To: testuser1, testuser2, testuser3\r\n" + "Subject: test message 3\r\n"
            + "\r\n" + "This is a short test message 3\r\n";

    List<DeliveryRequest> requests = new ArrayList<DeliveryRequest>();
    requests.add(new BasicDeliveryRequest("root", Arrays.asList("testuser1"),
            new ByteArraySource(text1.getBytes("US-ASCII"))));
    requests.add(new BasicDeliveryRequest("root", Arrays.asList("testuser1", "testuser2"),
            new ByteArraySource(text2.getBytes("US-ASCII"))));
    requests.add(new BasicDeliveryRequest("root", Arrays.asList("testuser1", "testuser2", "testuser3"),
            new ByteArraySource(text3.getBytes("US-ASCII"))));

    MailUserAgent mua = new DefaultMailUserAgent(TransportType.SMTP, IOReactorConfig.DEFAULT);
    mua.start();//from w w w  .  java  2 s . c  o m

    try {

        InetSocketAddress address = new InetSocketAddress("localhost", 2525);

        Queue<Future<DeliveryResult>> queue = new LinkedList<Future<DeliveryResult>>();
        for (DeliveryRequest request : requests) {
            queue.add(mua.deliver(new SessionEndpoint(address), 0, request, null));
        }

        while (!queue.isEmpty()) {
            Future<DeliveryResult> future = queue.remove();
            DeliveryResult result = future.get();
            System.out.println("Delivery result: " + result);
        }

    } finally {
        mua.shutdown();
    }
}

From source file:com.programming4food.smssender.Main.java

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

    int maxThreads = 8;
    int minThreads = 2;
    int timeOutMillis = 30000;
    threadPool(maxThreads, minThreads, timeOutMillis);

    port(1234);/*from w w  w.j  ava2s . com*/

    get("/hello", (req, res) -> "Api Iniciada");

    post("/sendMSG", (req, res) -> {

        try {
            String numero = req.queryParams("numero");
            String oficio = req.queryParams("oficio");
            String cliente = req.queryParams("cliente");

            TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("Body",
                    "El numero +" + cliente + " requiere tus servicios como " + oficio));
            params.add(new BasicNameValuePair("To", "+" + numero));
            params.add(new BasicNameValuePair("From", "+12563440285"));

            MessageFactory messageFactory = client.getAccount().getMessageFactory();
            Message message = messageFactory.create(params);
            System.out.println(message.getStatus());
            return "Exito";
        } catch (Exception ex) {
            ex.printStackTrace();
            return "Error";
        }

    }, new JsonTransformer());
    System.out.println("Iniciada");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String DEFAULT_DRIVER = "org.sqlite.JDBC";
    String DEFAULT_URL = "jdbc:sqlite:data/test.db";

    Connection conn = createConnection(DEFAULT_DRIVER, DEFAULT_URL);
    createTable(conn);/*from w w w.  j  a v  a  2s. c o m*/

    List<Person> people = new ArrayList<Person>();
    people.add(new Person("A", "a"));
    people.add(new Person("B", "b"));
    people.add(new Person("C", "c"));
    saveAll(conn, people);

    List<Person> rows = findAll(conn);
    System.out.println(rows);
    close(conn);
}