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:Main.java

public static void main(String[] argv) throws Exception {
    List list1 = new ArrayList();
    List list2 = new ArrayList();

    list1.addAll(list2);//  w  w  w  . ja  v  a2s. co  m

    list1.removeAll(list2);

    list1.retainAll(list2);

    list1.clear();

    int newSize = 2;
    list1.subList(newSize, list1.size()).clear();
}

From source file:com.aerospike.examples.BatchUpdateTTL.java

public static void main(String[] args) throws AerospikeException {
    try {/* w w  w .  j  a  va  2  s . com*/
        Options options = new Options();
        options.addOption("h", "host", true, "Server hostname (default: 127.0.0.1)");
        options.addOption("p", "port", true, "Server port (default: 3000)");
        options.addOption("n", "namespace", true, "Namespace (default: test)");
        options.addOption("s", "set", true, "Set (default: demo)");
        options.addOption("u", "usage", false, "Print usage.");

        CommandLineParser parser = new PosixParser();
        CommandLine cl = parser.parse(options, args, false);

        String host = cl.getOptionValue("h", "127.0.0.1");
        String portString = cl.getOptionValue("p", "3000");
        int port = Integer.parseInt(portString);
        String namespace = cl.getOptionValue("n", "test");
        String set = cl.getOptionValue("s", "demo");
        log.debug("Host: " + host);
        log.debug("Port: " + port);
        log.debug("Namespace: " + namespace);
        log.debug("Set: " + set);

        @SuppressWarnings("unchecked")
        List<String> cmds = cl.getArgList();
        if (cmds.size() == 0 && cl.hasOption("u")) {
            logUsage(options);
            return;
        }

        BatchUpdateTTL as = new BatchUpdateTTL(host, port, namespace, set);

        as.work();

    } catch (Exception e) {
        log.error("Critical error", e);
    }
}

From source file:br.eb.ime.labprog3.tam.GeradorGrafoDijkstra.java

public static void main(String args[]) {
    String fileNameTrechos = "rotas.xml";
    String fileNameAeroportos = "aeroportos.xml";

    File aeroportos = new File(fileNameAeroportos);
    File trechos = new File(fileNameTrechos);

    Resource resource = null;/*www. j  a  v  a2 s . c  om*/
    TrechoDAO daoTrecho = null;
    AeroportoDAO daoAeroporto = null;

    daoTrecho = new TrechoDAO(trechos);

    daoAeroporto = new AeroportoDAO(aeroportos);

    int indexOrigem = 4;
    int indexDestino = 23;

    List<Aeroporto> listaDeAeroportos = daoAeroporto.listarAeroportos();
    List<Trecho> listarTrechos = daoTrecho.listarTrechos();
    GeradorGrafoDijkstra geradorDeGrafo = new GeradorGrafoDijkstra(daoAeroporto.listarAeroportos(),
            daoTrecho.listarTrechos());
    List<Aeroporto> listaDeAeroportosDestino = geradorDeGrafo.geraMenorCaminho(indexOrigem, indexDestino);
    System.out.println(listaDeAeroportosDestino.size());
    System.out.println("Origem: " + listaDeAeroportos.get(indexOrigem - 1).getId() + " : "
            + listaDeAeroportos.get(indexOrigem - 1).getNome());
    System.out.println("Destino: " + listaDeAeroportos.get(indexDestino - 1).getId() + " : "
            + listaDeAeroportos.get(indexDestino - 1).getNome());
    for (Aeroporto aeroporto : listaDeAeroportosDestino) {
        System.out.println(aeroporto.getId() + " : " + aeroporto.getNome());
    }

}

From source file:Main.java

public static void main(String[] args) {
    Person p = new Person("A");
    Animal a = new Animal("B");
    Thing t = new Thing("C");
    String text = "hello";
    Integer number = 1000;// ww  w.j  av a2 s  .c o  m

    List<Object> list = new ArrayList<Object>();
    list.add(p);
    list.add(a);
    list.add(t);
    list.add(text);
    list.add(number);

    for (int i = 0; i < list.size(); i++) {
        Object o = list.get(i);
        if (o instanceof Person) {
            System.out.println("My name is " + ((Person) o).getName());
        } else if (o instanceof Animal) {
            System.out.println("I live in " + ((Animal) o).getHabitat());
        } else if (o instanceof Thing) {
            System.out.println("My color is " + ((Thing) o).getColor());
        } else if (o instanceof String) {
            System.out.println("My text is " + o.toString());
        } else if (o instanceof Integer) {
            System.out.println("My value is " + ((Integer) o));
        }
    }
}

From source file:com.impetus.kvapps.runner.AppRunner.java

/**
 * main runner method//from  w  w  w . ja  va2  s.  c o  m
 * @param args takes excel data file as input argument args[0].
 */
public static void main(String[] args) {

    // Override CQL version while instantiating entity manager factory.

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("twissandra,twingo,twirdbms");
    EntityManager em = emf.createEntityManager();

    try {

        //populate user set from excel sheet.
        Set<User> users = UserBroker.brokeUserList(args[0]);

        for (Iterator<User> iterator = users.iterator(); iterator.hasNext();) {
            User user = (User) iterator.next();

            // on Persist
            ExecutorService.onPersist(em, user);

            // on find by id.
            ExecutorService.findByKey(em, "BigDataUser");

            List<User> fetchedUsers = ExecutorService.onQueryByEmail(em, user);

            if (fetchedUsers != null && fetchedUsers.size() > 0) {
                logger.info(user.toString());
            }

            logger.info("");
            System.out.println("#######################Querying##########################################");
            logger.info("");
            logger.info("");

        }

        // Execute wild search query.
        String query = "Select u from User u";
        logger.info(query);
        ExecutorService.findByQuery(em, query);

        // // Execute native CQL. Fetch tweets for given user.
        logger.info("");
        System.out.println("#######################Querying##########################################");
        logger.info("");
        logger.info("");

        query = "Select * from tweets where user_id='RDBMSUser'";
        logger.info(query);
        ExecutorService.findByNativeQuery(em, query);
    } finally {
        onDestroyDBResources(emf, em);
    }
}

From source file:com.stratio.decision.executables.DataFlowFromCsvMain.java

public static void main(String[] args) throws IOException, NumberFormatException, InterruptedException {
    if (args.length < 4) {
        log.info(//from   ww  w.  j av  a  2s . c om
                "Usage: \n param 1 - path to file \n param 2 - stream name to send the data \n param 3 - time in ms to wait to send each data \n param 4 - broker list");
    } else {
        Producer<String, String> producer = new Producer<String, String>(createProducerConfig(args[3]));
        Gson gson = new Gson();

        Reader in = new FileReader(args[0]);
        CSVParser parser = CSVFormat.DEFAULT.parse(in);

        List<String> columnNames = new ArrayList<>();
        for (CSVRecord csvRecord : parser.getRecords()) {

            if (columnNames.size() == 0) {
                Iterator<String> iterator = csvRecord.iterator();
                while (iterator.hasNext()) {
                    columnNames.add(iterator.next());
                }
            } else {
                StratioStreamingMessage message = new StratioStreamingMessage();

                message.setOperation(STREAM_OPERATIONS.MANIPULATION.INSERT.toLowerCase());
                message.setStreamName(args[1]);
                message.setTimestamp(System.currentTimeMillis());
                message.setSession_id(String.valueOf(System.currentTimeMillis()));
                message.setRequest_id(String.valueOf(System.currentTimeMillis()));
                message.setRequest("dummy request");

                List<ColumnNameTypeValue> sensorData = new ArrayList<>();
                for (int i = 0; i < columnNames.size(); i++) {

                    // Workaround
                    Object value = null;
                    try {
                        value = Double.valueOf(csvRecord.get(i));
                    } catch (NumberFormatException e) {
                        value = csvRecord.get(i);
                    }
                    sensorData.add(new ColumnNameTypeValue(columnNames.get(i), null, value));
                }

                message.setColumns(sensorData);

                String json = gson.toJson(message);
                log.info("Sending data: {}", json);
                producer.send(new KeyedMessage<String, String>(InternalTopic.TOPIC_DATA.getTopicName(),
                        STREAM_OPERATIONS.MANIPULATION.INSERT, json));

                log.info("Sleeping {} ms...", args[2]);
                Thread.sleep(Long.valueOf(args[2]));
            }
        }
        log.info("Program completed.");
    }
}

From source file:com.mmone.gpdati.allotment.record.AllotmentRecordsListBuilder.java

public static void main(String[] args) {

    AllotmentLineProvvider afr = new AllotmentFileReader(
            "D:/tmp_desktop/scrigno-gpdati/FILE_DISPO__20160802.txt");
    AllotmentRecordsListBuilder arlb = new AllotmentRecordsListBuilder(afr);

    try {/*from   w w  w.  j a va  2  s .  co  m*/
        List<AllotmentRecord> records = arlb.getGroupedRecords();
        System.out.println("Records in list " + records.size());

        if (true)
            for (AllotmentRecord record : records) {
                System.out.println("---- " + record.getCompleteKey());
            }

        //MapUtils.debugPrint(System.out , "MAP", arlb.getMappedRecords());
        //MapUtils.debugPrint(System.out , "MAP", reg);
    } catch (Exception ex) {
        SoapUI.log.info(ex.getMessage());
        Logger.getLogger(AllotmentRecordsListBuilder.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:EmpComparator.java

public static void main(String args[]) {
    String names[] = { "Bart", "Hugo", "Lisa", "Marge", "Homer", "Maggie", "Roy" };

    // Convert to list
    List list = new ArrayList(Arrays.asList(names));

    // Ensure list sorted
    Collections.sort(list);/*w  ww  . j  a va2  s .c o m*/
    System.out.println("Sorted list: [length: " + list.size() + "]");
    System.out.println(list);

    // Search for element in list
    int index = Collections.binarySearch(list, "Maggie");
    System.out.println("Found Maggie @ " + index);

    // Search for element not in list
    index = Collections.binarySearch(list, "Jimbo Jones");
    System.out.println("Didn't find Jimbo Jones @ " + index);

    // Insert
    int newIndex = -index - 1;
    list.add(newIndex, "Jimbo Jones");
    System.out.println("With Jimbo Jones added: [length: " + list.size() + "]");
    System.out.println(list);

    // Min should be Bart
    System.out.println(Collections.min(list));
    // Max should be Roy
    System.out.println(Collections.max(list));

    Comparator comp = Collections.reverseOrder();

    // Reversed Min should be Roy
    System.out.println(Collections.min(list, comp));
    // Reversed Max should be Bart
    System.out.println(Collections.max(list, comp));
}

From source file:MainClass.java

public static void main(String[] a) {
    List list = Arrays.asList(new String[] { "A", "B", "C", "D" });

    Object[] objArray = list.toArray();

    for (Object obj : objArray) {
        System.out.println(obj);//  ww w  .j  a  va 2 s.  c  o  m
    }

    String[] strArray = (String[]) list.toArray(new String[list.size()]);

    for (String string : strArray) {
        System.out.println(string);
    }
}

From source file:com.linkedin.pinot.perf.MultiValueReaderWriterBenchmark.java

public static void main(String[] args) throws Exception {
    List<String> lines = IOUtils.readLines(new FileReader(new File(args[0])));
    int totalDocs = lines.size();
    int max = Integer.MIN_VALUE;
    int maxNumberOfMultiValues = Integer.MIN_VALUE;
    int totalNumValues = 0;
    int data[][] = new int[totalDocs][];
    for (int i = 0; i < lines.size(); i++) {
        String line = lines.get(i);
        String[] split = line.split(",");
        totalNumValues = totalNumValues + split.length;
        if (split.length > maxNumberOfMultiValues) {
            maxNumberOfMultiValues = split.length;
        }//  w w  w.  jav  a  2  s.c om
        data[i] = new int[split.length];
        for (int j = 0; j < split.length; j++) {
            String token = split[j];
            int val = Integer.parseInt(token);
            data[i][j] = val;
            if (val > max) {
                max = val;
            }
        }
    }
    int maxBitsNeeded = (int) Math.ceil(Math.log(max) / Math.log(2));
    int size = 2048;
    int[] offsets = new int[size];
    int bitMapSize = 0;
    File outputFile = new File("output.mv.fwd");

    FixedBitSkipListSCMVWriter fixedBitSkipListSCMVWriter = new FixedBitSkipListSCMVWriter(outputFile,
            totalDocs, totalNumValues, maxBitsNeeded);

    for (int i = 0; i < totalDocs; i++) {
        fixedBitSkipListSCMVWriter.setIntArray(i, data[i]);
        if (i % size == size - 1) {
            MutableRoaringBitmap rr1 = MutableRoaringBitmap.bitmapOf(offsets);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(bos);
            rr1.serialize(dos);
            dos.close();
            //System.out.println("Chunk " + i / size + " bitmap size:" + bos.size());
            bitMapSize += bos.size();
        } else if (i == totalDocs - 1) {
            MutableRoaringBitmap rr1 = MutableRoaringBitmap.bitmapOf(Arrays.copyOf(offsets, i % size));
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(bos);
            rr1.serialize(dos);
            dos.close();
            //System.out.println("Chunk " + i / size + " bitmap size:" + bos.size());
            bitMapSize += bos.size();
        }
    }
    fixedBitSkipListSCMVWriter.close();
    System.out.println("Output file size:" + outputFile.length());
    System.out.println("totalNumberOfDoc\t\t\t:" + totalDocs);
    System.out.println("totalNumberOfValues\t\t\t:" + totalNumValues);
    System.out.println("chunk size\t\t\t\t:" + size);
    System.out.println("Num chunks\t\t\t\t:" + totalDocs / size);
    int numChunks = totalDocs / size + 1;
    int totalBits = (totalNumValues * maxBitsNeeded);
    int dataSizeinBytes = (totalBits + 7) / 8;

    System.out.println("Raw data size with fixed bit encoding\t:" + dataSizeinBytes);
    System.out.println("\nPer encoding size");
    System.out.println();
    System.out.println("size (offset + length)\t\t\t:" + ((totalDocs * (4 + 4)) + dataSizeinBytes));
    System.out.println();
    System.out.println("size (offset only)\t\t\t:" + ((totalDocs * (4)) + dataSizeinBytes));
    System.out.println();
    System.out.println("bitMapSize\t\t\t\t:" + bitMapSize);
    System.out.println("size (with bitmap)\t\t\t:" + (bitMapSize + (numChunks * 4) + dataSizeinBytes));

    System.out.println();
    System.out.println("Custom Bitset\t\t\t\t:" + (totalNumValues + 7) / 8);
    System.out.println("size (with custom bitset)\t\t\t:"
            + (((totalNumValues + 7) / 8) + (numChunks * 4) + dataSizeinBytes));

}