Example usage for java.util List size

List of usage examples for java.util List size

Introduction

In this page you can find the example usage for java.util List size.

Prototype

int size();

Source Link

Document

Returns the number of elements in this list.

Usage

From source file:eu.planets_project.pp.plato.services.characterisation.xcl.Comparator.java

public static void main(String[] args) {
    Comparator comp = new Comparator();
    try {/*from  w  w w. j av  a  2  s.  c  o  m*/
        InputStream in = new FileInputStream(
                "d:/workspace/plato/data/pp5/polarbear1.tiff.xcdl-vs-polarbear1.tiff.xcdl.cpr");
        ComparatorUtils compUtils = new ComparatorUtils();
        List<CompareResult> result = compUtils
                .parseResponse("d:/workspace/plato/data/pp5/polarbear1.tiff.xcdl-vs-polarbear1.tiff.xcdl.cpr");
        System.out.print("num of comps: " + result.size());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (PlatoServiceException e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    List<Integer> numbers = new ArrayList<Integer>();

    for (Integer i : Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7))
        numbers.add(i);// w  ww . jav  a2 s. c o  m
    printList(numbers); // 0,1,2,3,4,5,6,7

    // replaces each element with twice its value
    for (int index = 0; index < numbers.size(); index++) {
        numbers.set(index, numbers.get(index) * 2);
    }
    printList(numbers);

    // does nothing because list is not being changed
    for (Integer number : numbers) {
        number++;
    }
    printList(numbers);

    // same as above -- just different syntax
    for (Iterator<Integer> iter = numbers.iterator(); iter.hasNext();) {
        Integer number = iter.next();
        number++;
    }
    printList(numbers);

    for (ListIterator<Integer> iter = numbers.listIterator(); iter.hasNext();) {
        Integer number = iter.next();
        iter.add(number + 1);
    }
    printList(numbers);

    for (Iterator<Integer> iter = numbers.iterator(); iter.hasNext();) {
        Integer number = iter.next();
        if (number % 2 == 0) // if number is even
            iter.remove(); // remove it from the collection
    }
    printList(numbers); // 1,3,5,7,9,11,13,15

    // ListIterator<?> has a "set" method to replace elements
    for (ListIterator<Integer> iter = numbers.listIterator(); iter.hasNext();) {
        Integer number = iter.next();
        iter.set(number / 2); // divide each element by 2
    }
    printList(numbers); // 0,1,2,3,4,5,6,7

    // Use Java 8 Lambda
    List<Integer> list = numbers;
    list.stream().forEach(elem -> System.out.println("element " + elem));

}

From source file:AmazonKinesisCreate.java

public static void main(String[] args) throws Exception {
    init();/*www.  j ava  2s .co m*/

    final String myStreamName = "philsteststream";
    final Integer myStreamSize = 1;

    // Create a stream. The number of shards determines the provisioned throughput.

    CreateStreamRequest createStreamRequest = new CreateStreamRequest();
    createStreamRequest.setStreamName(myStreamName);
    createStreamRequest.setShardCount(myStreamSize);

    // pt
    kinesisClient.createStream(createStreamRequest);

    // The stream is now being created.
    LOG.info("Creating Stream : " + myStreamName);
    waitForStreamToBecomeAvailable(myStreamName);

    // list all of my streams
    ListStreamsRequest listStreamsRequest = new ListStreamsRequest();
    listStreamsRequest.setLimit(10);
    ListStreamsResult listStreamsResult = kinesisClient.listStreams(listStreamsRequest);
    List<String> streamNames = listStreamsResult.getStreamNames();
    while (listStreamsResult.isHasMoreStreams()) {
        if (streamNames.size() > 0) {
            listStreamsRequest.setExclusiveStartStreamName(streamNames.get(streamNames.size() - 1));
        }

        listStreamsResult = kinesisClient.listStreams(listStreamsRequest);
        streamNames.addAll(listStreamsResult.getStreamNames());

    }
    LOG.info("Printing my list of streams : ");

    // print all of my streams.
    if (!streamNames.isEmpty()) {
        System.out.println("List of my streams: ");
    }
    for (int i = 0; i < streamNames.size(); i++) {
        System.out.println(streamNames.get(i));
    }

    LOG.info("Putting records in stream : " + myStreamName);
    // Write 10 records to the stream
    for (int j = 0; j < 10; j++) {

        try {
            PutRecordRequest putRecordRequest = new PutRecordRequest();
            putRecordRequest.setStreamName(myStreamName);
            putRecordRequest.setData(ByteBuffer.wrap(String.format("testData-%d", j).getBytes()));
            putRecordRequest.setPartitionKey(String.format("partitionKey-%d", j));
            PutRecordResult putRecordResult = kinesisClient.putRecord(putRecordRequest);
            System.out.println("Successfully putrecord, partition key : " + putRecordRequest.getPartitionKey()
                    + ", ShardID : " + putRecordResult.getShardId());
            Thread.sleep(1000);

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

    }

    // Delete the stream.

    /*
    LOG.info("Deleting stream : " + myStreamName);
    DeleteStreamRequest deleteStreamRequest = new DeleteStreamRequest();
    deleteStreamRequest.setStreamName(myStreamName);
            
    kinesisClient.deleteStream(deleteStreamRequest);
    // The stream is now being deleted.
    LOG.info("Stream is now being deleted : " + myStreamName);
            
    LOG.info("Streaming completed" + myStreamName);
    */

}

From source file:com.da.img.ClientFormLogin.java

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

    DefaultHttpClient httpclient = new DefaultHttpClient();

    try {//from   w w  w  .j  ava2 s .  c o m
        HttpGet httpget = new HttpGet("http://www.soraven.info/index.php");

        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        //System.out.println( EntityUtils.toString(entity));
        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("-1 " + cookies.get(i).toString());
            }
        }

        HttpPost httpost = new HttpPost("http://www.soraven.info/common/include/login.php");
        Header header1 = new BasicHeader("Accept",
                "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,application/msword, */*");
        Header header2 = new BasicHeader("Referer", "http://www.soraven.info/index.php");
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("p_userid", "bimohani"));
        nvps.add(new BasicNameValuePair("p_passwd", "cw8904"));
        nvps.add(new BasicNameValuePair("x", "12"));
        nvps.add(new BasicNameValuePair("y", "20"));
        httpost.setHeader(header1);
        httpost.setHeader(header2);
        httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));

        //Thread.sleep(2000);
        response = httpclient.execute(httpost);
        entity = response.getEntity();

        System.out.println("Login form get: " + response.getStatusLine());

        System.out.println(EntityUtils.toString(entity));
        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("-2 " + 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:AmazonKinesisDelete.java

public static void main(String[] args) throws Exception {
    init();/*ww  w .  j a  va 2 s . c o  m*/

    //final String myStreamName = "anotestBstream";
    //final Integer myStreamSize = 1;

    // Create a stream. The number of shards determines the provisioned throughput.

    //        CreateStreamRequest createStreamRequest = new CreateStreamRequest();
    //        createStreamRequest.setStreamName(myStreamName);
    //        createStreamRequest.setShardCount(myStreamSize);

    // pt
    //       kinesisClient.createStream(createStreamRequest);

    // The stream is now being created.
    //       LOG.info("Creating Stream : " + myStreamName);
    //       waitForStreamToBecomeAvailable(myStreamName);

    // list all of my streams
    ListStreamsRequest listStreamsRequest = new ListStreamsRequest();
    listStreamsRequest.setLimit(10);
    ListStreamsResult listStreamsResult = kinesisClient.listStreams(listStreamsRequest);
    List<String> streamNames = listStreamsResult.getStreamNames();
    while (listStreamsResult.isHasMoreStreams()) {
        if (streamNames.size() > 0) {
            listStreamsRequest.setExclusiveStartStreamName(streamNames.get(streamNames.size() - 1));
        }

        listStreamsResult = kinesisClient.listStreams(listStreamsRequest);
        streamNames.addAll(listStreamsResult.getStreamNames());

    }
    LOG.info("Printing my list of streams : ");

    // print all of my streams.
    if (!streamNames.isEmpty()) {
        System.out.println("List of my streams: ");
    }

    for (int i = 0; i < streamNames.size(); i++) {
        System.out.println(streamNames.get(i));
        String actStreamName = streamNames.get(i);

        DeleteStreamRequest deleteStreamRequest = new DeleteStreamRequest();
        //deleteStreamRequest.setStreamName(myStreamName);
        deleteStreamRequest.setStreamName(actStreamName);

        kinesisClient.deleteStream(deleteStreamRequest);
        // The stream is now being deleted.
        LOG.info("Stream is now being deleted : " + actStreamName);
    }

    /*      
          LOG.info("Putting records in stream : " + myStreamName);
          // Write 10 records to the stream
          for (int j = 0; j < 10; j++) {
    PutRecordRequest putRecordRequest = new PutRecordRequest();
    putRecordRequest.setStreamName(myStreamName);
    putRecordRequest.setData(ByteBuffer.wrap(String.format("testData-%d", j).getBytes()));
    putRecordRequest.setPartitionKey(String.format("partitionKey-%d", j));
    PutRecordResult putRecordResult = kinesisClient.putRecord(putRecordRequest);
    System.out.println("Successfully putrecord, partition key : " + putRecordRequest.getPartitionKey()
            + ", ShardID : " + putRecordResult.getShardId());
          }
    */

    // Delete the stream.

    /*      LOG.info("Deleting stream : " + myStreamName);
          DeleteStreamRequest deleteStreamRequest = new DeleteStreamRequest();
          deleteStreamRequest.setStreamName(myStreamName);
            
          kinesisClient.deleteStream(deleteStreamRequest);
          // The stream is now being deleted.
          LOG.info("Stream is now being deleted : " + myStreamName);
                  
          LOG.info("Streaming completed" + myStreamName);
    */

}

From source file:com.joymove.service.impl.JOYUserServiceImpl.java

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

    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:test.xml");
    Map<String, Object> likeCondition = new HashMap<String, Object>();
    JOYUser user = new JOYUser();
    DateFormat formatWithTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    user.registerTime = formatWithTime.parse("2013-04-29 15:08:41");

    JOYUserDao dao = (JOYUserDao) context.getBean("JOYUserDao");
    likeCondition.putAll(user.toMap());/* w w w  .  j  a v a 2 s  .  co  m*/
    likeCondition.put("filter", user);
    List<Map<String, Object>> mapList = dao.getPagedRecordList(likeCondition);
    for (int i = 0; i < mapList.size(); i++) {
        JOYUser userObj = new JOYUser();
        user.fromMap(mapList.get(i));
        System.out.println(user);
    }

    /*
            
            
    JOYPayHistoryService service = (JOYPayHistoryService)context.getBean("JOYPayHistoryService");
    JOYPayHistory payHistoryNew = new JOYPayHistory();
    payHistoryNew.balance = 0.2;
    payHistoryNew.type = 2;
    service.deleteByProperties(payHistoryNew);
            
            
    /*
    JOYUserService service = (JOYUserService)context.getBean("JOYUserService");
    JOYUser user = new JOYUser();
    user.mobileNo = "18500217642";
    List<Map<String,Object>> mapList = service.getExtendInfoPagedList(" select u.*, m.driverLicenseNumber  from JOY_Users u left join JOY_DriverLicense m on u.mobileNo = m.mobileNo ",user);
            
            
    //   JOYUser user2 = new JOYUser();
    Map<String,Object> t = mapList.get(0);
    Iterator i =t.entrySet().iterator();
    JSONObject tt = new JSONObject();
    while(i.hasNext()) {
            
       Map.Entry<String,Object> haha = (Map.Entry<String,Object>)i.next();
        if(String.valueOf(haha.getValue()).equals("null")) {
    logger.trace(haha.getKey()+" is null");
       }
    }
            
    /*
    user2.username = "?";
    user.mobileNo="18500217642";
    service.updateRecord(user2,user);
    user = service.getNeededRecord(user);
      logger.trace(user);
            
    /*
    JOYOrderService service = (JOYOrderService) context.getBean("JOYOrderService");
    JOYOrder order = new JOYOrder();
    order = service.getNeededRecord(order);
    JOYOrder order2 = new JOYOrder();
    order2.startTime = order.startTime;
    order = new JOYOrder();
    order.startTime = new Date(System.currentTimeMillis());
    service.updateRecord(order,order2);
       /*
    JOYNReserveOrderService  service  = (JOYNReserveOrderService)context.getBean("JOYNReserveOrderService");
    JOYReserveOrder order = new JOYReserveOrder();
    //service.insertRecord(order);
    JOYReserveOrder order2 = new JOYReserveOrder();
    order2.mobileNo = "18500217642";
    order2.startTime = new Date(System.currentTimeMillis());
      service.insertRecord(order2);
    order2.startTime = null;
    order = service.getNeededRecord(order2);
     order.startTime = new Date(System.currentTimeMillis());
    service.updateRecord(order,order2);
      order2.startTime = order.startTime;
    order2.mobileNo = null;
    order = service.getNeededRecord(order2);
    logger.trace(order);
    /*
    order.delFlag = 1;
    order.startTime = new Date(System.currentTimeMillis()+30);
    service.updateRecord(order,order2);
            
    order2.mobileNo = null;
    order2.startTime = order.startTime;
    order = service.getNeededRecord(order2);
    logger.trace(order);
    //service.deleteByProperties(order);
            
            
    /*
    JOYIdAuthInfoService service  = (JOYIdAuthInfoService)context.getBean("JOYIdAuthInfoService");
    JOYIdAuthInfo dl = new JOYIdAuthInfo();
    dl.idAuthInfo = "nihao".getBytes();
    dl.idAuthInfo_back = "Hello world".getBytes();
    JOYIdAuthInfo dl2 = new JOYIdAuthInfo();
    dl2.mobileNo = "15577586649";
    service.updateRecord(dl,dl2);
            
            
    service.getNeededList(dl2,null,null);
            
            
            
    List<JOYIdAuthInfo> dList = service.getNeededList(dl,null,null);
    logger.trace(dList.get(0));
            
    for(int i=0;i<dList.get(0).idAuthInfo.length;i++)
    System.out.format("%c",dList.get(0).idAuthInfo[i]);
    /*
    JOYUser user = new JOYUser();
    JOYUser user1 = new JOYUser();
    user.mobileNo = ("18500217642");
    List<JOYUser> userList =  service.getNeededList(user,0,10);
      logger.trace("sdfdsdsf :"+userList.size());
    JOYUser u = userList.get(0);
    logger.trace(u);
     */
}

From source file:esg.gateway.client.ESGAccessLogClient.java

public static void main(String[] args) {
    String serviceHost = null;// w w w.j av  a  2  s  .c  om
    long startTime = 0;
    long endTime = Long.MAX_VALUE;

    try {
        serviceHost = args[0];
        startTime = Long.parseLong(args[1]);
        endTime = Long.parseLong(args[2]);
    } catch (Throwable t) {
        log.error(t.getMessage());
    }

    try {
        ESGAccessLogClient client = new ESGAccessLogClient();
        if (client.setEndpoint(serviceHost).ping()) {
            List<String[]> results = null;
            results = client.fetchAccessLogData(startTime, endTime);

            System.out.println("---results:[" + (results.size() - 1) + "]---");
            for (String[] record : results) {
                StringBuilder sb = new StringBuilder();
                for (String column : record) {
                    sb.append("[" + column + "] ");
                }
                System.out.println(sb.toString());
            }
        }
        System.out.println("-----------------");
    } catch (Throwable t) {
        log.error(t);
        t.printStackTrace();
    }
}

From source file:net.sf.zekr.engine.bookmark.ui.BookmarkUtils.java

public static void main(String[] args) {
    BookmarkSet bms = config.getBookmark();
    List<Object[]> l = findReferences(bms, new QuranLocation(12, 13));
    for (int i = 0; i < l.size(); i++) {
        Object[] entry = l.get(i);
        System.out.println(entry[0] + ": " + entry[1]);
    }// w ww.  ja va 2  s .  c o  m
}

From source file:Main.java

public static void main(String args[]) {

    List<String[]> left = new ArrayList<String[]>();
    left.add(new String[] { "one", "two" });

    List<String[]> right = new ArrayList<String[]>();
    right.add(new String[] { "one", "two" });

    java.util.Iterator<String[]> leftIterator = left.iterator();
    java.util.Iterator<String[]> rightIterator = right.iterator();
    if (left.size() != right.size()) {
        System.out.println("not equal");
    }/*  w  w w .  jav  a  2s .  c om*/
    while (leftIterator.hasNext()) {
        if (Arrays.equals(leftIterator.next(), rightIterator.next()))
            continue;
        else {
            System.out.print("not equal");
            break;
        }
    }
}

From source file:ffx.xray.TimerTest.java

public static void main(String args[]) {
    // Parameters collection from original Timer script
    String pdbname = System.getProperty("pdbFile", "1N7S.pdb");
    String mtzname = System.getProperty("mtzFile", null);
    String cifname = System.getProperty("cifFile", null);
    final boolean ciOnly = false;
    final String info = "SNARE complex";
    final double r = 19.412671496011;
    final double rfree = 21.555930987573;
    final double sigmaA = 0.9336853524690557;
    final double sigmaW = 0.13192537249786418;

    boolean ci = System.getProperty("ffx.ci", "false").equalsIgnoreCase("true");
    if (!ci && ciOnly) {
        crystalStats = null;/*w w  w  .  j a  va 2  s .c o  m*/
        return;
    }

    int index = pdbname.lastIndexOf(".");
    String name = pdbname.substring(0, index);

    // load the structure
    MolecularAssembly molecularAssembly;
    File structure, mtzFile, cifFile;
    structure = new File(pdbname);
    PotentialsFileOpener opener = new PotentialsFileOpener(structure);
    opener.run();
    molecularAssembly = opener.getAssembly();
    mtzFile = new File(mtzname);
    cifFile = new File(cifname);

    // load any properties associated with it
    CompositeConfiguration properties = Keyword.loadProperties(structure);

    // read in Fo/sigFo/FreeR
    MTZFilter mtzFilter = new MTZFilter();
    CIFFilter cifFilter = new CIFFilter();
    Crystal crystal = Crystal.checkProperties(properties);
    Resolution resolution = Resolution.checkProperties(properties);
    if (crystal == null || resolution == null) {
        if (mtzname != null) {
            reflectionList = mtzFilter.getReflectionList(mtzFile);
        } else {
            reflectionList = cifFilter.getReflectionList(cifFile);
        }
    } else {
        reflectionList = new ReflectionList(crystal, resolution);
    }

    refinementData = new DiffractionRefinementData(properties, reflectionList);
    if (mtzname != null) {
        //            assertTrue(info + " mtz file should be read in without errors",
        //                    mtzFilter.readFile(mtzFile, reflectionList, refinementData,
        //                            properties));
    } else {
        //            assertTrue(info + " cif file should be read in without errors",
        //                    cifFilter.readFile(cifFile, reflectionList, refinementData,
        //                            properties));
    }

    ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();

    // associate molecular assembly with the structure, set up forcefield
    molecularAssembly.setForceField(forceField);
    PDBFilter pdbFile = new PDBFilter(structure, molecularAssembly, forceField, properties);
    pdbFile.readFile();
    pdbFile.applyAtomProperties();
    molecularAssembly.finalize(true, forceField);
    ForceFieldEnergy energy = new ForceFieldEnergy(molecularAssembly, pdbFile.getCoordRestraints());

    List<Atom> atomList = molecularAssembly.getAtomList();
    Atom atomArray[] = atomList.toArray(new Atom[atomList.size()]);

    // set up FFT and run it
    parallelTeam = new ParallelTeam();
    CrystalReciprocalSpace crs = new CrystalReciprocalSpace(reflectionList, atomArray, parallelTeam,
            parallelTeam, false);
    crs.computeDensity(refinementData.fc);
    refinementData.setCrystalReciprocalSpace_fc(crs);
    crs = new CrystalReciprocalSpace(reflectionList, atomArray, parallelTeam, parallelTeam, true);
    crs.computeDensity(refinementData.fs);
    refinementData.setCrystalReciprocalSpace_fs(crs);

    ScaleBulkMinimize scaleBulkMinimize = new ScaleBulkMinimize(reflectionList, refinementData, crs,
            parallelTeam);
    scaleBulkMinimize.minimize(6, 1.0e-4);

    SigmaAMinimize sigmaAMinimize = new SigmaAMinimize(reflectionList, refinementData, parallelTeam);
    sigmaAMinimize.minimize(7, 2.0e-2);

    SplineMinimize splineMinimize = new SplineMinimize(reflectionList, refinementData, refinementData.spline,
            SplineEnergy.Type.FOFC);
    splineMinimize.minimize(7, 1e-5);

    crystalStats = new CrystalStats(reflectionList, refinementData);

    scaleBulkMinimize = new ScaleBulkMinimize(reflectionList, refinementData, refinementData.crs_fs,
            parallelTeam);
    ScaleBulkEnergy scaleBulkEnergy = scaleBulkMinimize.getScaleBulkEnergy();
    int n = scaleBulkMinimize.getNumberOfVariables();
    double x[] = new double[n];
    double g[] = new double[n];
    scaleBulkMinimize.getCoordinates(x);
    scaleBulkEnergy.energyAndGradient(x, g);

    double delta = 1.0e-4;
    double tolerance = 1.0e-4;

    logger.info(String.format("SCATTER TEST"));
    for (int i = 0; i < 30; i++) {
        long time = -System.nanoTime();
        scaleBulkEnergy.energyAndGradient(x, g);
        time += System.nanoTime();
        logger.info(String.format(" Time %12.8f", time * 1.0e-9));
    }
}