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) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(Vehicals.class);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    Vehicals vehicals = new Vehicals();

    List<Car> cars = new ArrayList<Car>();
    Car c = new Car();
    c.setName("Mercedes");
    cars.add(c);

    c = new Car();
    c.setName("BMW");
    cars.add(c);//from  w w w.  ja v a  2 s  . c  om
    vehicals.setCar(cars);
    m.marshal(vehicals, System.out);
}

From source file:com.kinesis.datavis.writer.BidRequestStreamWriter.java

/**
 * Start a number of threads and send randomly generated {@link }s to a Kinesis Stream until the
 * program is terminated./* w  w  w. ja v  a 2s.co m*/
 *
 * @param args Expecting 3 arguments: A numeric value indicating the number of threads to use to send
 *             data to Kinesis and the name of the stream to send records to, and the AWS region in which these resources
 *             exist or should be created.
 * @throws InterruptedException If this application is interrupted while sending records to Kinesis.
 */
public static void main(String[] args) throws InterruptedException {
    int numberOfThreads = Integer.parseInt(args[0]);

    AppProperties appProps = new AppProperties("bidrq", args[1]);

    String streamName = appProps.streamName();

    Region region = AppUtils.parseRegion(appProps.getRegion());

    AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain();

    ClientConfiguration clientConfig = AppUtils.configureUserAgentForSample(new ClientConfiguration());

    AmazonKinesis kinesis = new AmazonKinesisClient(credentialsProvider, clientConfig);
    kinesis.setRegion(region);

    // The more resources we declare the higher write IOPS we need on our DynamoDB table.
    // We write a record for each resource every interval.
    // If interval = 500ms, resource count = 7 we need: (1000/500 * 7) = 14 write IOPS minimum.
    List<String> resources = new ArrayList<>();
    resources.add("300x200");
    resources.add("500x200");
    resources.add("400x600");
    resources.add("800x600");

    List<String> bidRequestIds = new ArrayList<>();
    //        bidRequestIds.add(UUID.randomUUID().toString());
    //        bidRequestIds.add(UUID.randomUUID().toString());
    //        bidRequestIds.add(UUID.randomUUID().toString());
    //        bidRequestIds.add("11111111111");
    //        bidRequestIds.add("22222222222");
    //        bannerIds.add("33333333333");
    //        bidRequestIds.add("44444444444");
    bidRequestIds.add("92b9b9d9-2d6d-454a-b80a-d6a318aca9ec");

    BidRequestFactory bdFactory = new BidRequestFactory(bidRequestIds, resources);

    // Creates a stream to write to with 2 shards if it doesn't exist
    StreamUtils streamUtils = new StreamUtils(kinesis);
    streamUtils.createStreamIfNotExists(streamName, 2);

    LOG.info(String.format("%s stream is ready for use", streamName));

    final BidRequestPutter putter = new BidRequestPutter(bdFactory, kinesis, streamName);

    GeneralStreamWriter streamWriter = new GeneralStreamWriter(numberOfThreads, putter);

    streamWriter.doWrite();

}

From source file:com.bobby.peng.learning.java.stream.StreamMap.java

public static void main(String[] args) {
    //        List<Integer> list = StreamMap.newRandomList();
    ///*from w  w  w  . j  av  a  2s.  c  o m*/
    //        List<Integer> list2 = list.stream().map(i->i*5).collect(Collectors.toList());
    //
    //        StreamMap.printOut(list2);
    //
    //        list = list.subList(0,11);
    //        StreamMap.printOut(list);
    //
    //        String value = "INSERT INTO tech_subao_00.subao_renew_list (id, extra_info, gmt_created, gmt_modified, is_deleted, creator, modifier, remark, status, unqiue_flag, list_biz_id, province_name, province_code, city_name, city_code, license_no, engine_no, frame_no, factory_plate_model, first_register_date, applicant_name, owner_name, owner_certificate_type, owner_id_no, owner_mobile, contact_phone1, contact_phone2, bi_end_date, ci_end_date, vehicle_id, list_allocation_time, booking_start_date, booking_end_date, user_id, renew_batch_id, renew_biz_name, source, organization_id) VALUES (%d, null, '2018-08-07 02:50:36', '2018-08-07 02:50:37', 'N', '', 'system', null, 10, '000000%d', '1', '', '110000', '', '110100', '12312313', '12313', '31231', '111', '2018-05-12', '123', '123', 1, '310111111111111111', '13311111111', '13311111111', '13311111111', '2019-08-07 05:24:56', '2019-08-07 05:25:03', 1, null, null, null, null, %d, 'batch1', 50, 1);";
    //
    //        int id = 3;
    //        for(int i=3;i<100;i++) {
    //            for(int j=0;j<2;j++) {
    //                System.out.println(String.format(value,id,id,i));
    //                id++;
    //            }
    //        }

    List<Integer> test = new ArrayList<>();
    for (int i = 0; i < 1000; i++) {
        test.add(i);
    }

    test.parallelStream().map(i -> {
        System.out.println(i);
        return i;
    }).collect(Collectors.toList());

    System.out.println("===================================");

    test.stream().map(i -> {
        System.out.println(i);
        return i;
    }).collect(Collectors.toList());

}

From source file:com.sm.store.TestRemotePopulate.java

public static void main(String[] args) {
    String[] opts = new String[] { "-store", "-url", "-times" };
    String[] defaults = new String[] { "campaignsperday", "las1-ssusd001.sm-us.sm.local:7240", "10" };
    String[] paras = getOpts(args, opts, defaults);
    String store = paras[0];//w  ww. ja v  a  2  s. co  m
    String url = paras[1];
    int times = Integer.valueOf(paras[2]);
    HessianSerializer serializer = new HessianSerializer();

    RemotePersistence client = new NTRemoteClientImpl(url, null, store);
    for (int i = 0; i < times; i++) {
        try {
            //Key key = Key.createKey("cmp"+i);
            //Campaign campaign = new Campaign(1, 1, i, false, false, "test"+i, null, null, null, null, null);
            //logger.info(campaign);
            //byte[] campaignBytes = serializer.toBytes(campaign);
            // Value val = new RemoteValue(campaignBytes, 0, (short) 0);

            Key key = Key.createKey("usr" + i);
            List<String> campaignIds = new ArrayList<String>();
            campaignIds.add("cmp" + i);
            ////campaignIds.add("cmp"+i+i);
            //byte[] campaignIdsBytes = serializer.toBytes(campaignIds);
            Value val = new RemoteValue(campaignIds, 0, (short) 0);
            //
            //                   Key key = Key.createKey("cmp"+i+"."+20130116);
            //                   Delivery delivery = new Delivery(i, i+1, i*2, (i*2)+1, i*3, (i*3)+1, i*4, (i*4)+1, i*5, (i*5)+1);
            //                   byte[] deliveryBytes = serializer.toBytes(delivery);
            //                  Value val = new RemoteValue(deliveryBytes, 0, (short) 0);
            //                   client.put( key, val);
            //
            //                   key = Key.createKey("cmp"+i+"."+20130117);
            //                   delivery = new Delivery(i, i+2, i*2, (i*2)+2, i*3, (i*3)+2, i*4, (i*4)+2, i*5, (i*5)+2);
            //                   deliveryBytes = serializer.toBytes(delivery);
            //                  val = new RemoteValue(deliveryBytes, 0, (short) 0);

            client.put(key, val);

            Value value = client.get(key);
            logger.info("campaign value data: " + (List<String>) value.getData());
            logger.info(value == null ? "null" : value.getData().toString());

        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }

    }
    client.close();

}

From source file:net.liuxuan.temp.mathtest.java

public static void main(String[] args) {

    final CurveFitter fitter = new CurveFitter(new LevenbergMarquardtOptimizer());
    fitter.addObservedPoint(-1.00, 2.021170021833143);
    fitter.addObservedPoint(-0.99, 2.221135431136975);
    fitter.addObservedPoint(-0.98, 2.09985277659314);
    fitter.addObservedPoint(-0.97, 2.0211192647627025);
    // ... Lots of lines omitted ...
    fitter.addObservedPoint(0.99, -2.4345814727089854);

    // The degree of the polynomial is deduced from the length of the array containing
    // the initial guess for the coefficients of the polynomial.
    final double[] init = { 12.9, -3.4, 2.1 }; // 12.9 - 3.4 x + 2.1 x^2

    // Compute optimal coefficients.
    final double[] best = fitter.fit(new PolynomialFunction.Parametric(), init);

    // Construct the polynomial that best fits the data.
    final PolynomialFunction fitted = new PolynomialFunction(best);
    System.out.println(fitted.value(-0.995));
    ;//from   w  w w.  j a  va  2s. c om
    System.out.println(fitted.value(0.995));
    ;
    System.out.println(fitted.toString());
    ;
    System.out.println("=============================================================");
    PolynomialCurveFitter pcf = PolynomialCurveFitter.create(3);
    WeightedObservedPoints s;
    List<WeightedObservedPoint> points = new ArrayList<WeightedObservedPoint>();
    points.add(new WeightedObservedPoint(1, -1.00, 2.021170021833143));
    points.add(new WeightedObservedPoint(1, -0.99, 2.221135431136975));
    points.add(new WeightedObservedPoint(1, -0.98, 2.09985277659314));
    points.add(new WeightedObservedPoint(1, -0.97, 2.0211192647627025));
    points.add(new WeightedObservedPoint(1, 0.99, 2.4345814727089854));
    double a[] = pcf.fit(points);
    for (int i = 0; i < a.length; i++) {
        double d = a[i];
        System.out.println(d);
    }
    System.out.println(compute(a, -0.995));
    System.out.println(compute(a, 0.99));
    System.out.println(compute(a, 0.995));

}

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

public static void main(String[] args) {
    try {/*w  w  w  .  ja  v a2s  . co  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 to your listing.
        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 = BasicUploadApk.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 alpha track.
        List<Integer> apkVersionCodes = new ArrayList<>();
        apkVersionCodes.add(apk.getVersionCode());
        Update updateTrackRequest = edits.tracks().update(ApplicationConfig.PACKAGE_NAME, editId, TRACK_ALPHA,
                new Track().setVersionCodes(apkVersionCodes));
        Track updatedTrack = updateTrackRequest.execute();
        log.info(String.format("Track %s has been updated.", updatedTrack.getTrack()));

        // 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("Excpetion was thrown while uploading apk to alpha track", ex);
    }
}

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

    CertStoreParameters cparam = new CollectionCertStoreParameters(mylist);
    CertStore cs = CertStore.getInstance("Collection", cparam);
    X509CertSelector selec = new X509CertSelector();
    selec.setIssuer("CN=YourName,OU=Network Center," + "O=University,L=ZB,ST=Toronto,C=CN");
    Set clct = (Set) cs.getCertificates(selec);
    Object o[] = clct.toArray();/*from   w  w w .  j av  a2s. c o m*/
    for (int i = 0; i < o.length; i++) {
        X509Certificate ct = (X509Certificate) o[i];
        System.out.println("Certificate " + i + " ");
        System.out.println(ct.getSubjectDN());

    }
}

From source file:eu.europeana.datamigration.ese2edm.LogCleaner.java

public static void main(String[] args) {
    try {/*  ww w .jav  a 2 s.  co  m*/
        List<String> lines = FileUtils.readLines(new File("/home/gmamakis/test.log"));
        List<String> newLines = new ArrayList<String>();
        for (String line : lines) {
            if (!line.startsWith("Apr")) {
                newLines.add(line);
            }
        }
        FileUtils.writeLines(new File("/home/gmamakis/rdfslabel.log"), newLines);
    } catch (IOException ex) {
        Logger.getLogger(LogCleaner.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:core.plugin.mybatis.PageInterceptor.java

public static void main(String[] args) {
    List<String> tests = new ArrayList<String>();
    tests.add("select count(*) from abc \n\t\t where\n abc");
    tests.add("SELECT COUNT(*) from abc");
    tests.add(" select count (*) from abc");
    tests.add(" select count( *) from abc");
    tests.add("select count( * ),id from abc");
    tests.add("select * from abc");
    tests.add("select abc,test,fdas from abc");
    tests.add("select count(adb) from abc");
    tests.add("select count(0) from abc");
    tests.add("select min(count(*)) from abc");
    tests.add("update min(count(*)) from abc");
    tests.add("delete min(count(*)) from abc");
    Pattern p1 = Pattern.compile(SQL_SELECT_REGEX, Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
    Pattern p2 = Pattern.compile(SQL_COUNT_REGEX, Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
    for (String str : tests) {
        Matcher m1 = p1.matcher(str);
        Matcher m2 = p2.matcher(str);
        System.out.println("?: " + str);
        System.out.println(" select?? " + m1.matches());
        System.out.println(" count?? " + m2.matches());
        System.out.println();/*from   w  w w  .  j  a  v a 2 s. co  m*/
    }
}

From source file:edu.teilar.jcrop.service.ApplicationTest2.java

public static void main(String[] args) {

    RestTemplate restTemplate = new RestTemplate();
    // model to return  
    Map<String, Object> model = new HashMap<String, Object>();

    // set up json mapper
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    ObjectMapper mapper = new ObjectMapper();
    converter.setObjectMapper(mapper);/*from  w  ww.ja va  2s . c  o m*/
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(converter);
    restTemplate.setMessageConverters(messageConverters);

    String uri = "http://localhost:8080/jcrop-service/rest/learningobjects/{kobj}";

    KObject kobj = restTemplate.getForObject(uri, KObject.class, "complex1");

    System.out.println("Learning Object: " + kobj.getName());
    System.out.println("Target Concept: " + kobj.getTargetEducationalObjective().getName());

    ArrayList<Node> traverseArrayList = new ArrayList<Node>();

    traverseKObject(kobj, traverseArrayList);
    System.out.println("sss" + traverseArrayList);
}