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:org.apache.flink.streaming.tests.Elasticsearch6SinkExample.java

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

    final ParameterTool parameterTool = ParameterTool.fromArgs(args);

    if (parameterTool.getNumberOfParameters() < 3) {
        System.out.println(/*from   ww  w.j  av  a  2 s  .co  m*/
                "Missing parameters!\n" + "Usage: --numRecords <numRecords> --index <index> --type <type>");
        return;
    }

    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.getConfig().disableSysoutLogging();
    env.enableCheckpointing(5000);

    DataStream<Tuple2<String, String>> source = env.generateSequence(0, parameterTool.getInt("numRecords") - 1)
            .flatMap(new FlatMapFunction<Long, Tuple2<String, String>>() {
                @Override
                public void flatMap(Long value, Collector<Tuple2<String, String>> out) {
                    final String key = String.valueOf(value);
                    final String message = "message #" + value;
                    out.collect(Tuple2.of(key, message + "update #1"));
                    out.collect(Tuple2.of(key, message + "update #2"));
                }
            });

    List<HttpHost> httpHosts = new ArrayList<>();
    httpHosts.add(new HttpHost("127.0.0.1", 9200, "http"));

    ElasticsearchSink.Builder<Tuple2<String, String>> esSinkBuilder = new ElasticsearchSink.Builder<>(httpHosts,
            (Tuple2<String, String> element, RuntimeContext ctx, RequestIndexer indexer) -> {
                indexer.add(createIndexRequest(element.f1, parameterTool));
                indexer.add(createUpdateRequest(element, parameterTool));
            });

    // this instructs the sink to emit after every element, otherwise they would be buffered
    esSinkBuilder.setBulkFlushMaxActions(1);

    source.addSink(esSinkBuilder.build());

    env.execute("Elasticsearch 6.x end to end sink test example");
}

From source file:com.http.QuickStart.java

public static void main(String[] args) throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    try {/*from  w w  w.  j  a v  a  2  s. co  m*/
        HttpGet httpGet = new HttpGet("http://localhost:8081/cring/jsp/user/index.jsp");
        CloseableHttpResponse 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 CloseableHttpResponse#close().

        try {
            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 {
            response1.close();
        }

        HttpPost httpPost = new HttpPost("http://localhost:8081/cring/jsp/user/userLogin.do?method=login");
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("username", "057185581120"));
        nvps.add(new BasicNameValuePair("password", "111111"));
        httpPost.setEntity(new UrlEncodedFormEntity(nvps));
        CloseableHttpResponse 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 {
            response2.close();
        }
    } finally {
        httpclient.close();
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    List mylist = new ArrayList();
    FileInputStream in = new FileInputStream(args[0]);
    Certificate c = cf.generateCertificate(in);
    mylist.add(c);

    CertPath cp = cf.generateCertPath(mylist);

    Certificate trust = cf.generateCertificate(in);
    TrustAnchor anchor = new TrustAnchor((X509Certificate) trust, null);
    PKIXParameters params = new PKIXParameters(Collections.singleton(anchor));
    params.setRevocationEnabled(false);/*from  www  .  j  a  v  a 2  s  .co  m*/
    CertPathValidator cpv = CertPathValidator.getInstance("PKIX");
    PKIXCertPathValidatorResult result = (PKIXCertPathValidatorResult) cpv.validate(cp, params);
    System.out.println(result);
}

From source file:Main.java

public static void main(String args[]) {
    // create two array list objects       
    List<String> arrlistsrc = new ArrayList<String>();
    List<String> arrlisttarget = new ArrayList<String>();

    // populate two lists
    arrlistsrc.add("A");
    arrlistsrc.add("from java2s.com");
    arrlistsrc.add("C");
    arrlistsrc.add("D");
    arrlistsrc.add("E");

    arrlisttarget.add("C");
    arrlisttarget.add("D");
    arrlisttarget.add("E");

    // check starting position of the last occurrence
    int index = Collections.lastIndexOfSubList(arrlistsrc, arrlisttarget);

    System.out.println("Starting position is: " + index);
}

From source file:Main.java

public static void main(String args[]) {
    // create two array list objects       
    List<String> arrlistsrc = new ArrayList<String>();
    List<String> arrlisttarget = new ArrayList<String>();

    // populate two lists
    arrlistsrc.add("A");
    arrlistsrc.add("from java2s.com");
    arrlistsrc.add("C");
    arrlistsrc.add("D");
    arrlistsrc.add("E");

    arrlisttarget.add("C");
    arrlisttarget.add("D");
    arrlisttarget.add("E");

    // check target list in source list
    int index = Collections.indexOfSubList(arrlistsrc, arrlisttarget);

    System.out.println("Target list starts at index: " + index);
}

From source file:com.cloverframework.core.QuickStart.java

public static void main(String[] args) throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    try {/*from  ww w  .j a v a  2s.c  o  m*/
        HttpGet httpGet = new HttpGet("http://www.sina.com.cn/");
        CloseableHttpResponse 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 call CloseableHttpResponse#close() from a finally clause.
        // Please note that if response content is not fully consumed the underlying
        // connection cannot be safely re-used and will be shut down and discarded
        // by the connection manager.
        try {
            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 {
            response1.close();
        }

        HttpPost httpPost = new HttpPost("http://www.sina.com.cn/login");
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("username", "vip"));
        nvps.add(new BasicNameValuePair("password", "secret"));
        httpPost.setEntity(new UrlEncodedFormEntity(nvps));
        CloseableHttpResponse 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 {
            response2.close();
        }
    } finally {
        httpclient.close();
    }
}

From source file:com.test.httpClient.QuickStart.java

public static void main(String[] args) throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    try {//  w  w  w  .  j  av  a2  s . co  m
        HttpGet httpGet = new HttpGet("http://www.baidu.com");
        CloseableHttpResponse 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 call CloseableHttpResponse#close() from a finally clause.
        // Please note that if response content is not fully consumed the underlying
        // connection cannot be safely re-used and will be shut down and discarded
        // by the connection manager.
        try {
            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 {
            response1.close();
        }

        HttpPost httpPost = new HttpPost("http://www.baidu.com");
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("username", "vip"));
        nvps.add(new BasicNameValuePair("password", "secret"));
        httpPost.setEntity(new UrlEncodedFormEntity(nvps));
        CloseableHttpResponse 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 {
            response2.close();
        }
    } finally {
        httpclient.close();
    }
}

From source file:demo.test.tutorial_learn.QuickStart.java

public static void main(String[] args) throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    try {//ww  w.  java  2s .  c om
        HttpGet httpGet = new HttpGet("http://httpbin.org/get");
        CloseableHttpResponse 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 call CloseableHttpResponse#close() from a finally clause.
        // Please note that if response content is not fully consumed the underlying
        // connection cannot be safely re-used and will be shut down and discarded
        // by the connection manager.
        try {
            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 {
            response1.close();
        }

        HttpPost httpPost = new HttpPost("http://httpbin.org/post");
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("username", "vip"));
        nvps.add(new BasicNameValuePair("password", "secret"));
        httpPost.setEntity(new UrlEncodedFormEntity(nvps));
        CloseableHttpResponse 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 {
            response2.close();
        }
    } finally {
        httpclient.close();
    }
}

From source file:ke.co.tawi.babblesms.server.utils.randomgenerate.IncomingLogGenerator.java

/**
 * @param args// ww w .jav a  2 s .  co m
 */
public static void main(String[] args) {
    System.out.println("Have started IncomingSMSGenerator.");
    File outFile = new File("/tmp/logs/incomingSMS.csv");
    RandomDataGenerator randomDataImpl = new RandomDataGenerator();

    String randomStrFile = "/tmp/random.txt";

    List<String> randomStrings = new ArrayList<>();
    int randStrLength = 0;

    long startDate = 1412380800; // Unix time in seconds for Oct 4 2014
    long stopDate = 1420070340; // Unix time for in seconds Dec 31 2014

    SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 2011-06-01 00:16:45" 

    List<String> shortcodeUuids = new ArrayList<>();
    shortcodeUuids.add("094def52-bc18-4a9e-9b84-c34cc6476c75");
    shortcodeUuids.add("e9570c5d-0cc4-41e5-81df-b0674e9dda1e");
    shortcodeUuids.add("a118c8ea-f831-4288-986d-35e22c91fc4d");
    shortcodeUuids.add("a2688d72-291b-470c-8926-31a903f5ed0c");
    shortcodeUuids.add("9bef62f6-e682-4efd-98e9-ca41fa4ef993");

    int shortcodeCount = shortcodeUuids.size() - 1;

    try {
        randomStrings = FileUtils.readLines(new File(randomStrFile));
        randStrLength = randomStrings.size();

        for (int j = 0; j < 30000; j++) {
            FileUtils.write(outFile,
                    // shortcodeUuids.get(randomDataImpl.nextInt(0, shortcodeCount)) + "|"   // Destination 
                    UUID.randomUUID().toString() + "|" // Unique Code
                            + randomDataImpl.nextLong(new Long("254700000000").longValue(),
                                    new Long("254734999999").longValue())
                            + "|" // Origin
                            + shortcodeUuids.get(randomDataImpl.nextInt(0, shortcodeCount)) + "|"
                            + randomStrings.get(randomDataImpl.nextInt(0, randStrLength - 1)) + "|" // Message
                            + "N|" // deleted
                            + dateFormatter.format(
                                    new Date(randomDataImpl.nextLong(startDate, stopDate) * 1000))
                            + "\n", // smsTime                  
                    true); // Append to file                              
        }

    } catch (IOException e) {
        System.err.println("IOException in main.");
        e.printStackTrace();
    }

    System.out.println("Have finished IncomingSMSGenerator.");
}

From source file:MainClass.java

public static void main(String args[]) {
    List list = new ArrayList(Arrays.asList("a", "b", "c"));
    Iterator i = list.iterator();
    while (i.hasNext()) {
        System.out.println(i.next());
        list.add("Add");
    }/*w  ww  .j  a  v  a  2  s .  co m*/
}