Example usage for java.util List get

List of usage examples for java.util List get

Introduction

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

Prototype

E get(int index);

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:httpclient.client.ClientFormLogin.java

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

    // prepare parameters
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setUserAgent(params, Constants.BROWSER_TYPE);
    HttpProtocolParams.setUseExpectContinue(params, true);
    DefaultHttpClient httpclient = new DefaultHttpClient(params);

    String loginURL = "http://10.1.1.251/login.asp";
    HttpGet httpget = new HttpGet(loginURL);
    HttpResponse response = httpclient.execute(httpget);
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        entity.consumeContent();/*from  www  .j  a v  a 2 s . c  om*/
    }
    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(loginURL);
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("name", "fangdj"));
    nvps.add(new BasicNameValuePair("passwd", "1111"));

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

    response = httpclient.execute(httpost);
    entity = response.getEntity();
    for (Header h : response.getAllHeaders()) {
        System.out.println(h);
    }
    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());
        }
    }

    String mainURL = "http://10.1.1.251/ONWork/Record_save.asp";

    HttpPost mainHttPost = new HttpPost(mainURL);
    List<NameValuePair> mainNvps = new ArrayList<NameValuePair>();
    mainNvps.add(new BasicNameValuePair("EMP_NO", "13028"));
    mainNvps.add(new BasicNameValuePair("pwd", "1111"));
    mainNvps.add(new BasicNameValuePair("cmd2", "Apply"));

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

    response = httpclient.execute(mainHttPost);
    System.out.println(Tools.InputStreamToString(response.getEntity().getContent()));
    // 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:SystemTrayTest.java

public static void main(String[] args) {
    final TrayIcon trayIcon;

    if (!SystemTray.isSupported()) {
        System.err.println("System tray is not supported.");
        return;/*from  w ww . j av a2  s.  co  m*/
    }

    SystemTray tray = SystemTray.getSystemTray();
    Image image = Toolkit.getDefaultToolkit().getImage("cookie.png");

    PopupMenu popup = new PopupMenu();
    MenuItem exitItem = new MenuItem("Exit");
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    popup.add(exitItem);

    trayIcon = new TrayIcon(image, "Your Fortune", popup);

    trayIcon.setImageAutoSize(true);
    trayIcon.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            trayIcon.displayMessage("How do I turn this off?",
                    "Right-click on the fortune cookie and select Exit.", TrayIcon.MessageType.INFO);
        }
    });

    try {
        tray.add(trayIcon);
    } catch (AWTException e) {
        System.err.println("TrayIcon could not be added.");
        return;
    }

    final List<String> fortunes = readFortunes();
    Timer timer = new Timer(10000, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int index = (int) (fortunes.size() * Math.random());
            trayIcon.displayMessage("Your Fortune", fortunes.get(index), TrayIcon.MessageType.INFO);
        }
    });
    timer.start();
}

From source file:jdbc.ClientFormLogin.java

public static void main(String[] args) throws Exception {
    BasicCookieStore cookieStore = new BasicCookieStore();
    CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
    java.net.CookieManager cm = new java.net.CookieManager();
    java.net.CookieHandler.setDefault(cm);

    try {/*from  w  w w .  jav a 2  s . c  om*/
        HttpGet httpget = new HttpGet("http://www.cophieu68.vn/export/excel.php?id=AAA");
        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://www.cophieu68.vn/export/excel.php?id=AAA"))
                .addParameter("username", "hello_nguyenson@live.com").addParameter("tpassword", "19931994")
                .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));
    }/*  w  w w . j a v a2  s  .c  om*/

}

From source file:acmi.l2.clientmod.l2_version_switcher.Main.java

public static void main(String[] args) {
    if (args.length != 3 && args.length != 4) {
        System.out.println("USAGE: l2_version_switcher.jar host game version <--splash> <filter>");
        System.out.println("EXAMPLE: l2_version_switcher.jar " + L2.NCWEST_HOST + " " + L2.NCWEST_GAME
                + " 1 \"system\\*\"");
        System.out.println(//www . j  av a2  s  .c  o  m
                "         l2_version_switcher.jar " + L2.PLAYNC_TEST_HOST + " " + L2.PLAYNC_TEST_GAME + " 48");
        System.exit(0);
    }

    List<String> argsList = new ArrayList<>(Arrays.asList(args));
    String host = argsList.get(0);
    String game = argsList.get(1);
    int version = Integer.parseInt(argsList.get(2));
    Helper helper = new Helper(host, game, version);
    boolean available = false;

    try {
        available = helper.isAvailable();
    } catch (IOException e) {
        System.err.print(e.getClass().getSimpleName());
        if (e.getMessage() != null) {
            System.err.print(": " + e.getMessage());
        }

        System.err.println();
    }

    System.out.println(String.format("Version %d available: %b", version, available));
    if (!available) {
        System.exit(0);
    }

    List<FileInfo> fileInfoList = null;
    try {
        fileInfoList = helper.getFileInfoList();
    } catch (IOException e) {
        System.err.println("Couldn\'t get file info map");
        System.exit(1);
    }

    boolean splash = argsList.remove("--splash");
    if (splash) {
        Optional<FileInfo> splashObj = fileInfoList.stream()
                .filter(fi -> fi.getPath().contains("sp_32b_01.bmp")).findAny();
        if (splashObj.isPresent()) {
            try (InputStream is = new FilterInputStream(
                    Util.getUnzipStream(helper.getDownloadStream(splashObj.get().getPath()))) {
                @Override
                public int read() throws IOException {
                    int b = super.read();
                    if (b >= 0)
                        b ^= 0x36;
                    return b;
                }

                @Override
                public int read(byte[] b, int off, int len) throws IOException {
                    int r = super.read(b, off, len);
                    if (r >= 0) {
                        for (int i = 0; i < r; i++)
                            b[off + i] ^= 0x36;
                    }
                    return r;
                }
            }) {
                new DataInputStream(is).readFully(new byte[28]);
                BufferedImage bi = ImageIO.read(is);

                JFrame frame = new JFrame("Lineage 2 [" + version + "] " + splashObj.get().getPath());
                frame.setContentPane(new JComponent() {
                    {
                        setPreferredSize(new Dimension(bi.getWidth(), bi.getHeight()));
                    }

                    @Override
                    protected void paintComponent(Graphics g) {
                        g.drawImage(bi, 0, 0, null);
                    }
                });
                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            System.out.println("Splash not found");
        }
        return;
    }

    String filter = argsList.size() > 3 ? separatorsToSystem(argsList.get(3)) : null;

    File l2Folder = new File(System.getProperty("user.dir"));
    List<FileInfo> toUpdate = fileInfoList.parallelStream().filter(fi -> {
        String filePath = separatorsToSystem(fi.getPath());

        if (filter != null && !wildcardMatch(filePath, filter, IOCase.INSENSITIVE))
            return false;
        File file = new File(l2Folder, filePath);

        try {
            if (file.exists() && file.length() == fi.getSize() && Util.hashEquals(file, fi.getHash())) {
                System.out.println(filePath + ": OK");
                return false;
            }
        } catch (IOException e) {
            System.out.println(filePath + ": couldn't check hash: " + e);
            return true;
        }

        System.out.println(filePath + ": need update");
        return true;
    }).collect(Collectors.toList());

    List<String> errors = Collections.synchronizedList(new ArrayList<>());
    ExecutorService executor = Executors.newFixedThreadPool(16);
    CompletableFuture[] tasks = toUpdate.stream().map(fi -> CompletableFuture.runAsync(() -> {
        String filePath = separatorsToSystem(fi.getPath());
        File file = new File(l2Folder, filePath);

        File folder = file.getParentFile();
        if (!folder.exists()) {
            if (!folder.mkdirs()) {
                errors.add(filePath + ": couldn't create parent dir");
                return;
            }
        }

        try (InputStream input = Util
                .getUnzipStream(new BufferedInputStream(helper.getDownloadStream(fi.getPath())));
                OutputStream output = new BufferedOutputStream(new FileOutputStream(file))) {
            byte[] buffer = new byte[Math.min(fi.getSize(), 1 << 24)];
            int pos = 0;
            int r;
            while ((r = input.read(buffer, pos, buffer.length - pos)) >= 0) {
                pos += r;
                if (pos == buffer.length) {
                    output.write(buffer, 0, pos);
                    pos = 0;
                }
            }
            if (pos != 0) {
                output.write(buffer, 0, pos);
            }
            System.out.println(filePath + ": OK");
        } catch (IOException e) {
            String msg = filePath + ": FAIL: " + e.getClass().getSimpleName();
            if (e.getMessage() != null) {
                msg += ": " + e.getMessage();
            }
            errors.add(msg);
        }
    }, executor)).toArray(CompletableFuture[]::new);
    CompletableFuture.allOf(tasks).thenRun(() -> {
        for (String err : errors)
            System.err.println(err);
        executor.shutdown();
    });
}

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new ArrayList<>();
    list.add("Java");
    list.add("Oracle");
    list.add("CSS");
    list.add("XML");

    System.out.println("List: " + list);

    int count = list.size();
    System.out.println("Size of  List: " + count);

    // Print each element with its index
    for (int i = 0; i < count; i++) {
        String element = list.get(i);
        System.out.println("Index=" + i + ", Element=" + element);
    }//w  ww  . jav a2  s.  c  o m

    List<String> subList = list.subList(1, 3);
    System.out.println(subList);

    // Remove "CSS" from the list 
    list.remove("CSS"); // Same as list.remove(2);
    System.out.println(list);
}

From source file:Main.java

public static void main(String[] args) {
    Predicate<Student> isPaidEnough = e -> e.gpa > 1;
    Predicate<Student> isExperiencedEnough = e -> e.id < 10;

    List<Student> students = Arrays.asList(new Student(1, 3, "John"), new Student(2, 4, "Jane"),
            new Student(3, 3, "Jack"));

    System.out.println(findStudents(students, isPaidEnough));
    System.out.println(findStudents(students, isExperiencedEnough));
    System.out.println(findStudents(students, isExperiencedEnough.negate()));

    Student somebody = students.get(0);
    System.out.println(findStudents(students, Predicate.<Student>isEqual(somebody)));
}

From source file:it.crs4.features.MergeImgSets.java

public static void main(String[] args) throws Exception {
    Options opts = new Options();
    CommandLine cmd = null;//www.  j  ava2s  . c  om
    try {
        cmd = parseCmdLine(opts, args);
    } catch (ParseException e) {
        System.err.println("ERROR: " + e.getMessage());
        System.exit(1);
    }
    String[] posArgs = cmd.getArgs();
    if (posArgs.length < 2) {
        HelpFormatter fmt = new HelpFormatter();
        fmt.printHelp("java MergeImgSets IMG_SET_LIST OUT_FN", opts);
        System.exit(2);
    }
    String setsFn = posArgs[0];
    String outFn = posArgs[1];
    int replication = 1;
    if (cmd.hasOption("replication")) {
        replication = Integer.parseInt(cmd.getOptionValue("replication"));
    }

    List<List<String>> filesets = getFilesets(setsFn);
    int sizeZ = filesets.size();
    if (0 == sizeZ) {
        System.out.println("File set list is empty, nothing to do.");
        System.exit(0);
    }
    int sizeC = filesets.get(0).size();
    for (List<String> fs : filesets) {
        if (fs.size() != sizeC) {
            System.err.println("File sets must have equal size");
            System.exit(1);
        }
    }
    write(filesets, outFn, replication);
}

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]);
    }/* ww  w.java  2  s . c  o m*/
}

From source file:AmazonKinesisSample.java

public static void main(String[] args) throws Exception {
    init();/*w w w.  jav  a 2 s  .co  m*/

    final String myStreamName = "myFirstStream";
    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);

    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++) {
        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);
}