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:com.hilatest.httpclient.apacheexample.ClientFormLogin.java

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

    DefaultHttpClient httpclient = new DefaultHttpClient();

    HttpGet httpget = new HttpGet("https://portal.sun.com/portal/dt");

    HttpResponse response = httpclient.execute(httpget);
    HttpEntity entity = response.getEntity();

    System.out.println("Login form get: " + response.getStatusLine());
    if (entity != null) {
        entity.consumeContent();/* w  w w  . ja  va 2  s  .c  o m*/
    }
    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("- " + cookies.get(i).toString());
        }
    }

    HttpPost httpost = new HttpPost("https://portal.sun.com/amserver/UI/Login?" + "org=self_registered_users&"
            + "goto=/portal/dt&" + "gotoOnFail=/portal/dt?error=true");

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("IDToken1", "username"));
    nvps.add(new BasicNameValuePair("IDToken2", "password"));

    httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

    response = httpclient.execute(httpost);
    entity = response.getEntity();

    System.out.println("Login form get: " + response.getStatusLine());
    if (entity != null) {
        entity.consumeContent();
    }

    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("- " + cookies.get(i).toString());
        }
    }

    // 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:glacierpipe.GlacierPipeMain.java

public static void main(String[] args) throws IOException, ParseException {
    CommandLineParser parser = new GnuParser();

    CommandLine cmd = parser.parse(OPTIONS, args);

    if (cmd.hasOption("help")) {
        try (PrintWriter writer = new PrintWriter(System.err)) {
            printHelp(writer);//from w  ww.  ja v a2s .com
        }

        System.exit(0);
    } else if (cmd.hasOption("upload")) {

        // Turn the CommandLine into Properties
        Properties cliProperties = new Properties();
        for (Iterator<?> i = cmd.iterator(); i.hasNext();) {
            Option o = (Option) i.next();

            String opt = o.getLongOpt();
            opt = opt != null ? opt : o.getOpt();

            String value = o.getValue();
            value = value != null ? value : "";

            cliProperties.setProperty(opt, value);
        }

        // Build up a configuration
        ConfigBuilder configBuilder = new ConfigBuilder();

        // Archive name
        List<?> archiveList = cmd.getArgList();
        if (archiveList.size() > 1) {
            throw new ParseException("Too many arguments");
        } else if (archiveList.isEmpty()) {
            throw new ParseException("No archive name provided");
        }

        configBuilder.setArchive(archiveList.get(0).toString());

        // All other arguments on the command line
        configBuilder.setFromProperties(cliProperties);

        // Load any config from the properties file
        Properties fileProperties = new Properties();
        try (InputStream in = new FileInputStream(configBuilder.propertiesFile)) {
            fileProperties.load(in);
        } catch (IOException e) {
            System.err.printf("Warning: unable to read properties file %s; %s%n", configBuilder.propertiesFile,
                    e);
        }

        configBuilder.setFromProperties(fileProperties);

        // ...
        Config config = new Config(configBuilder);

        IOBuffer buffer = new MemoryIOBuffer(config.partSize);

        AmazonGlacierClient client = new AmazonGlacierClient(
                new BasicAWSCredentials(config.accessKey, config.secretKey));
        client.setEndpoint(config.endpoint);

        // Actual upload
        try (InputStream in = new BufferedInputStream(System.in, 4096);
                PrintWriter writer = new PrintWriter(System.err);
                ObservableProperties configMonitor = config.reloadProperties
                        ? new ObservableProperties(config.propertiesFile)
                        : null;
                ProxyingThrottlingStrategy throttlingStrategy = new ProxyingThrottlingStrategy(config);) {
            TerminalGlacierPipeObserver observer = new TerminalGlacierPipeObserver(writer);

            if (configMonitor != null) {
                configMonitor.registerObserver(throttlingStrategy);
            }

            GlacierPipe pipe = new GlacierPipe(buffer, observer, config.maxRetries, throttlingStrategy);
            pipe.pipe(client, config.vault, config.archive, in);
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }

        System.exit(0);
    } else {
        try (PrintWriter writer = new PrintWriter(System.err)) {
            writer.println("No action specified.");
            printHelp(writer);
        }

        System.exit(-1);
    }
}

From source file:Deal.java

public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println("Usage: Deal hands cards");
        return;//from  ww w.  j a  v a  2  s . co  m
    }
    int numHands = Integer.parseInt(args[0]);
    int cardsPerHand = Integer.parseInt(args[1]);
    List<Card> deck = Deck.newDeck();
    Collections.shuffle(deck);
    if (numHands * cardsPerHand > deck.size()) {
        System.out.println("Not enough cards.");
        return;
    }

    for (int i = 0; i < numHands; i++)
        System.out.println(dealHand(deck, cardsPerHand));
}

From source file:com.aerospike.examples.ldt.ttl.LdtExpire.java

public static void main(String[] args) throws AerospikeException {
    try {//from w  w w.j  a  va  2s.  c  o  m
        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.");
        options.addOption("d", "data", false, "Generate data.");

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

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

        as.registerUDF();

        if (cl.hasOption("d")) {
            as.generateData();
        } else {
            as.expire();
        }

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

From source file:com.doculibre.constellio.utils.izpack.UsersXmlFileUtils.java

public static void main(String[] argv) {
    createEmptyUsersFile();/*from   w ww  . j a  v  a 2 s  .  c  o  m*/

    ConstellioUser dataUser = new ConstellioUser("admin", "lol", ConstellioSpringUtils.getDefaultLocale());
    dataUser.setFirstName("System");
    dataUser.setLastName("Administrator");
    dataUser.getRoles().add(Roles.ADMIN);

    addUserTo(dataUser);

    List<ConstellioUser> users = readUsers();

    Assert.assertEquals(1, users.size());

    ConstellioUser user = users.get(0);

    Assert.assertTrue(user.checkPassword("lol"));

    //        Assert.assertEquals(1, user.getRoles());

    Assert.assertTrue(user.isAdmin());
    System.out.println("Succes!" + DEFAULT_USERS_FILE);

}

From source file:net.landora.justintv.JustinTVAPI.java

public static void main(String[] args) throws Exception {
    List<JustinArchive> archives = readArchives("tsmtournaments", 64);
    Map<String, List<JustinArchive>> groups = new HashMap<String, List<JustinArchive>>();
    for (int i = 0; i < archives.size(); i++) {
        JustinArchive archive = archives.get(i);
        List<JustinArchive> group = groups.get(archive.getBroadcastId());
        if (group == null) {
            group = new ArrayList<JustinArchive>(archive.getBroadcastPart());
            groups.put(archive.getBroadcastId(), group);
        }//from  w  ww.  j  a v  a2  s  .co m
        group.add(archive);
    }

    BroadcastSorter sorter = new BroadcastSorter();

    for (List<JustinArchive> group : groups.values()) {
        Collections.sort(group, sorter);

        JustinArchive base = group.get(group.size() - 1);

        StringBuffer cmd = new StringBuffer();
        cmd.append("mkvmerge -o \"");
        cmd.append(base.getBroadcastId());
        cmd.append(" - ");
        cmd.append(base.getTitle());
        cmd.append("\" ");

        for (int i = 0; i < group.size(); i++) {
            JustinArchive archive = group.get(i);
            if (i > 0)
                cmd.append("+ ");

            cmd.append(archive.getId());
            cmd.append(".mkv ");
        }
        System.out.println(cmd);
    }
}

From source file:ReplayTest.java

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

    int cnt = 0;/*w w w  . ja v a  2  s  .co m*/
    String operateTime = "";
    String operateType = "";
    String uuid = "";
    String programId = "";
    List<String> lines = Files.readLines(new File("e:\\test\\sample4.txt"), Charsets.UTF_8);
    System.out.println(lines.size());
    for (String value1 : lines) {
        String[] values = value1.split(SPLIT_T);
        //logArr16?operateDate=2014-04-25 17:59:59 621, operateType=STARTUP, deviceCode=010333501065233, versionId=, mac=10:48:b1:06:4d:23, platformId=00000032AmlogicMDZ-05-201302261821793, ipAddress=60.10.133.10
        if (values.length != 16) {
            continue;
        }
        String logContent = values[15];

        if (logContent == null || logContent.trim().length() <= 0) {
            System.out.println("logContent");
            return;
        }
        String[] contentArr = logContent.split(COMMA_SIGN);//content

        if (contentArr == null || contentArr.length != 3) {
            System.out.println("logContentArr:" + contentArr.length);
            return;
        }

        StringBuffer stringBuffer = new StringBuffer();

        //1.CNTVID??
        stringBuffer.append(StringsUtils.getEncodeingStr(values[3])).append(SPLIT);

        //2.IP?
        if (null == values[7] || EMPTY.equals(values[7])) {
            stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY)).append(SPLIT);
        } else {
            stringBuffer.append(StringsUtils.getEncodeingStr(values[7].trim())).append(SPLIT);
        }

        //3.OperateTtype   ? 1: 2:?
        operateType = StringUtils.substringAfter(contentArr[0].trim(), EQUAL_SIGN);
        if (null == operateType || EMPTY.equals(operateType)) {
            stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY)).append(SPLIT);
        } else if ("on".equals(operateType)) {
            stringBuffer.append(StringsUtils.getEncodeingStr("1")).append(SPLIT);
        } else if ("out".equals(operateType)) {
            stringBuffer.append(StringsUtils.getEncodeingStr("2")).append(SPLIT);
        }

        // 4.operateTime  ?
        operateTime = DateUtil.convertDateToString("yyyyMMdd HHmmss",
                DateUtil.convertStringToDate("yyyy-MM-dd HH:mm:ss SSS", values[10].trim()));
        if (operateTime == null || EMPTY.equals(operateTime)) {
            stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY)).append(SPLIT);
        } else {
            stringBuffer.append(StringsUtils.getEncodeingStr(operateTime)).append(SPLIT);
        }
        //5.url_addr ?
        stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY)).append(SPLIT);

        //6.channel?
        uuid = StringUtils.substringAfter(contentArr[1].trim(), EQUAL_SIGN);
        if (uuid == null || EMPTY.equals(uuid)) {
            stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY)).append(SPLIT);
        } else {
            stringBuffer.append(StringsUtils.getEncodeingStr(uuid)).append(SPLIT);
        }

        //7.programId id
        programId = StringUtils.substringAfter(contentArr[2].trim(), EQUAL_SIGN);
        if (!programId.matches("\\d+")) { //id????
            return;
        } else {
            stringBuffer.append(StringsUtils.getEncodeingStr(programId)).append(SPLIT);
        }

        //8.EPGCode EPG?,?EPGCode?
        stringBuffer.append(StringsUtils.getEncodeingStr("06")).append(SPLIT);

        //9.DataSource??12
        stringBuffer.append(DATA_SOURCE).append(SPLIT);

        //10.Fsource???????
        stringBuffer.append(F_SOURCE).append(SPLIT);

        //11.resolution ?,?
        stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY));

        System.out.println(stringBuffer.toString());
        cnt++;
    }
    System.out.println(":" + cnt);
}

From source file:cn.anthony.util.ClientFormLogin.java

public static void main(String[] args) throws Exception {
    BasicCookieStore cookieStore = new BasicCookieStore();
    CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
    try {/*from www . j a  va2s  . c o  m*/
        HttpGet httpget = new HttpGet("https://someportal/");
        CloseableHttpResponse response1 = httpclient.execute(httpget);
        try {
            HttpEntity entity = response1.getEntity();

            System.out.println("Login form get: " + response1.getStatusLine());
            EntityUtils.consume(entity);

            System.out.println("Initial set of cookies:");
            List<Cookie> cookies = cookieStore.getCookies();
            if (cookies.isEmpty()) {
                System.out.println("None");
            } else {
                for (int i = 0; i < cookies.size(); i++) {
                    System.out.println("- " + cookies.get(i).toString());
                }
            }
        } finally {
            response1.close();
        }

        HttpUriRequest login = RequestBuilder.post().setUri(new URI("https://someportal/"))
                .addParameter("IDToken1", "username").addParameter("IDToken2", "password").build();
        CloseableHttpResponse response2 = httpclient.execute(login);
        try {
            HttpEntity entity = response2.getEntity();

            System.out.println("Login form get: " + response2.getStatusLine());
            EntityUtils.consume(entity);

            System.out.println("Post logon cookies:");
            List<Cookie> cookies = cookieStore.getCookies();
            if (cookies.isEmpty()) {
                System.out.println("None");
            } else {
                for (int i = 0; i < cookies.size(); i++) {
                    System.out.println("- " + cookies.get(i).toString());
                }
            }
        } finally {
            response2.close();
        }
    } finally {
        httpclient.close();
    }
}

From source file:com.lxf.spider.client.ClientFormLogin.java

public static void main(String[] args) throws Exception {
    BasicCookieStore cookieStore = new BasicCookieStore();
    CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
    try {//from  w ww .  ja v  a 2 s . c o  m
        HttpGet httpget = new HttpGet("http://127.0.0.1:8080/pdqx.jc.web");
        CloseableHttpResponse response1 = httpclient.execute(httpget);
        try {
            HttpEntity entity = response1.getEntity();

            System.out.println("Login form get: " + response1.getStatusLine());
            EntityUtils.consume(entity);

            System.out.println("Initial set of cookies:");
            List<Cookie> cookies = cookieStore.getCookies();
            if (cookies.isEmpty()) {
                System.out.println("None");
            } else {
                for (int i = 0; i < cookies.size(); i++) {
                    System.out.println("- " + cookies.get(i).toString());
                }
            }
        } finally {
            response1.close();
        }

        HttpUriRequest login = RequestBuilder.post().setUri(new URI("http://127.0.0.1:8080/pdqx.jc.web"))
                .addParameter("IDToken1", "username").addParameter("IDToken2", "password").build();
        CloseableHttpResponse response2 = httpclient.execute(login);
        try {
            HttpEntity entity = response2.getEntity();

            System.out.println("Login form get: " + response2.getStatusLine());
            EntityUtils.consume(entity);

            System.out.println("Post logon cookies:");
            List<Cookie> cookies = cookieStore.getCookies();
            if (cookies.isEmpty()) {
                System.out.println("None");
            } else {
                for (int i = 0; i < cookies.size(); i++) {
                    System.out.println("- " + cookies.get(i).toString());
                }
            }
        } finally {
            response2.close();
        }
    } finally {
        httpclient.close();
    }
}

From source file:com.des.paperbase.ManageData.java

public static void main(String[] args) throws ParseException, IOException {
    ManageData p = new ManageData("DB");

    //p.Create("value");
    Map<String, Object> value = new HashMap<String, Object>();
    //value.put("lastname", "9999");
    value.put("age", "56");
    Map<String, Object> update = new HashMap<String, Object>();
    update.put("lastname", "333");
    update.put("age", "56");
    p.merge("value", value, update, "AND");
    List<Map<String, Object>> output = p.select("value", null, "OR");
    System.out.println(output.size());
    for (int i = 0; i < output.size(); i++) {
        System.out.println(output.get(i));
    }//from   w  w  w  .jav  a  2  s.  c o  m

}