Example usage for java.util ArrayList ArrayList

List of usage examples for java.util ArrayList ArrayList

Introduction

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

Prototype

public ArrayList(Collection<? extends E> c) 

Source Link

Document

Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.

Usage

From source file:common.ReverseWordsCount.java

public static void main(String[] args) throws IOException {
    List<String> readLines = FileUtils.readLines(new File("G:\\\\LTNMT\\LTNMT\\sougou\\sougou2500.txt"));
    Map<String, Integer> words = new HashMap<>();

    for (String line : readLines) {
        String[] split = line.split(" ");
        for (String wprd : split) {
            Integer get = words.get(wprd);
            if (get == null) {
                words.put(wprd, 1);//from w  w w .  j  ava  2 s .c o m
            } else {
                words.put(wprd, get + 1);
            }
        }
    }
    Set<Map.Entry<String, Integer>> entrySet = words.entrySet();
    List<Map.Entry<String, Integer>> reverseLists = new ArrayList<>(entrySet);
    Collections.sort(reverseLists, new Comparator<Map.Entry<String, Integer>>() {
        @Override
        public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
            return o2.getValue().compareTo(o1.getValue());
        }
    });
    PrintStream ps = new PrintStream("c:/reverseWords.txt");
    for (Map.Entry<String, Integer> teEntry : reverseLists) {
        ps.println(teEntry.getKey() + " " + teEntry.getValue());
    }
    ps.close();
}

From source file:Name.java

public static void main(String[] args) {
    Name name = new Name("A", "C");
    Name name1 = new Name("A", "B");
    Name name2 = new Name("C", "F");
    Name name3 = new Name("D", "A");
    Name name4 = new Name("Ca", "D");
    Name name5 = new Name("Cc", "Z");
    Name name6 = new Name("Cc", "W");

    Name nameArray[] = { name, name1, name2, name3, name4, name5, name6 };
    List<Name> names = new ArrayList<Name>(Arrays.asList(nameArray));

    Collections.sort(names);//from w w  w  .jav  a2  s  . com

    for (Name n : names) {
        System.out.println(n.getFirstName() + " " + n.getLastName());
    }
}

From source file:postenergy.TestHttpClient.java

public static void main(String[] args) {
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("https://www.google.com/accounts/ClientLogin");

    try {/*w  ww  .  java2s .  c om*/

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("Email", "youremail"));
        nameValuePairs.add(new BasicNameValuePair("Passwd", "yourpassword"));
        nameValuePairs.add(new BasicNameValuePair("accountType", "GOOGLE"));
        nameValuePairs.add(new BasicNameValuePair("source", "Google-cURL-Example"));
        nameValuePairs.add(new BasicNameValuePair("service", "ac2dm"));

        post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = client.execute(post);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

        String line = "";
        while ((line = rd.readLine()) != null) {
            System.out.println(line);
            if (line.startsWith("Auth=")) {
                String key = line.substring(5);
                // do something with the key
            }

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

From source file:com.senseidb.search.node.inmemory.InMemoryIndexPerfEval.java

public static void main(String[] args) throws Exception {
    final InMemorySenseiService memorySenseiService = InMemorySenseiService.valueOf(
            new File(InMemoryIndexPerfEval.class.getClassLoader().getResource("test-conf/node1/").toURI()));

    final List<JSONObject> docs = new ArrayList<JSONObject>(15000);
    LineIterator lineIterator = FileUtils.lineIterator(
            new File(InMemoryIndexPerfEval.class.getClassLoader().getResource("data/test_data.json").toURI()));
    int i = 0;//  w w w  .  j  a  v a  2 s  .com
    while (lineIterator.hasNext() && i < 100) {
        String car = lineIterator.next();
        if (car != null && car.contains("{"))
            docs.add(new JSONObject(car));
        i++;
    }
    Thread[] threads = new Thread[10];
    for (int k = 0; k < threads.length; k++) {
        threads[k] = new Thread(new Runnable() {
            public void run() {
                long time = System.currentTimeMillis();
                //System.out.println("Start thread");
                for (int j = 0; j < 1000; j++) {
                    //System.out.println("Send request");
                    memorySenseiService.doQuery(getRequest(), docs);
                }
                System.out.println("time = " + (System.currentTimeMillis() - time));
            }
        });
        threads[k].start();
    }
    Thread.sleep(500000);
}

From source file:ch.rasc.wampspring.demo.client.CallClientSockJs.java

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

    List<Transport> transports = new ArrayList<>(2);
    transports.add(new WebSocketTransport(new StandardWebSocketClient()));
    transports.add(new RestTemplateXhrTransport());
    WebSocketClient webSocketClient = new SockJsClient(transports);

    JsonFactory jsonFactory = new MappingJsonFactory(new ObjectMapper());

    CountDownLatch latch = new CountDownLatch(10_000);
    TestTextWebSocketHandler handler = new TestTextWebSocketHandler(jsonFactory, latch);

    Long[] start = new Long[1];
    ListenableFuture<WebSocketSession> future = webSocketClient.doHandshake(handler,
            "ws://localhost:8080/wampOverSockJS");
    future.addCallback(wss -> {/* w  w w.ja v  a 2  s .co  m*/
        start[0] = System.currentTimeMillis();
        for (int i = 0; i < 10_000; i++) {

            CallMessage callMessage = new CallMessage(UUID.randomUUID().toString(), "testService.sum", i,
                    i + 1);
            try {
                wss.sendMessage(new TextMessage(callMessage.toJson(jsonFactory)));
            } catch (Exception e) {
                System.out.println("ERROR SENDING CALLMESSAGE" + e);
                latch.countDown();
            }
        }

    }, t -> {
        System.out.println("DO HANDSHAKE ERROR: " + t);
        System.exit(1);
    });

    if (!latch.await(3, TimeUnit.MINUTES)) {
        System.out.println("SOMETHING WENT WRONG");
    }

    System.out.println((System.currentTimeMillis() - start[0]) / 1000 + " seconds");
    System.out.println("SUCCESS: " + handler.getSuccess());
    System.out.println("ERROR  : " + handler.getError());
}

From source file:com.dianping.wed.cache.redis.util.TestDataUtil.java

public static void main(String[] args) {
    // ????// www .jav  a2  s  .c om

    //&method=incr&parameterTypes=com.dianping.wed.cache.redis.dto.WeddingRedisKeyDTO&parameters={"category":"justtest","params":["1","2"]}
    List<String> opList = new ArrayList<String>(opAndKey.keySet());
    for (int i = 0; i < 1000; i++) {
        int index = RandomUtils.nextInt(opList.size());
        String op = opList.get(index);
        String key = opAndKey.get(op);
        StringBuilder result = new StringBuilder();
        int params = buildTestUrl(result, op, key);

        String fileName = "/Users/Bob/Desktop/data/data-" + params + ".csv";
        try {
            //kuka.txt
            //kuka.txt
            FileWriter writer = new FileWriter(fileName, true);
            writer.write(result.toString());
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    System.out.println("done");
}

From source file:org.brnvrn.Main.java

public static void main(String[] args) {

    Document doc = null; // the HTML tool page
    Document docObsolete = null;/*from www.java  2 s. co m*/
    try {
        //Document doc = Jsoup.connect("http://taskwarrior.org/tools/").get();
        ClassLoader classloader = Thread.currentThread().getContextClassLoader();
        InputStream input = classloader.getResourceAsStream("Taskwarrior-Tools.html");
        doc = Jsoup.parse(input, "UTF-8", "http://taskwarrior.org/");
        input = classloader.getResourceAsStream("Taskwarrior-Tools-Obsolete.html");
        docObsolete = Jsoup.parse(input, "UTF-8", "http://taskwarrior.org/");
    } catch (IOException e) {
        e.printStackTrace();
    }

    List<Tool> tools = new ArrayList<Tool>(100);
    ObjectMapper objectMapper = parseDocument(tools, doc, false);
    objectMapper = parseDocument(tools, docObsolete, true);

    try {
        objectMapper.writeValue(new FileOutputStream("data-tools.json"), tools);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:cc.kave.commons.pointsto.evaluation.runners.ProjectStoreRunner.java

public static void main(String[] args) throws IOException {
    Path storeDir = Paths.get(args[0]);
    try (ProjectUsageStore store = new ProjectUsageStore(storeDir)) {
        List<ICoReTypeName> types = new ArrayList<>(store.getAllTypes());
        types.sort(new TypeNameComparator());

        System.out.println(//w  w  w  . j a  v  a2 s .  c o m
                types.stream().filter(t -> t.getIdentifier().contains("KaVE.")).collect(Collectors.toList()));
        //         if (args.length == 1 || args[1].equals("countFilteredUsages")) {
        //            countFilteredUsages(types, store);
        //         } else if (args[1].equals("countRecvCallSites")) {
        //            countRecvCallSites(types, store);
        //         }
        // methodPropabilities(types, store);
    }

}

From source file:edu.umn.msi.tropix.proteomics.tools.DTAToMzXML.java

public static void main(final String[] args) throws Exception {
    if (args.length < 1) {
        usage();//w  w w .  ja  v  a  2  s.  c  o  m
        System.exit(0);
    }
    Collection<File> files = null;

    if (args[0].equals("-files")) {
        if (args.length < 2) {
            out.println("No files specified.");
            usage();
            exit(-1);
        } else {
            files = new ArrayList<File>(args.length - 1);
            for (int i = 1; i < args.length; i++) {
                files.add(new File(args[i]));
            }
        }
    } else if (args[0].equals("-directory")) {
        File directory;
        if (args.length < 2) {
            directory = new File(System.getProperty("user.dir"));
        } else {
            directory = new File(args[2]);
        }
        files = FileUtilsFactory.getInstance().listFiles(directory, new String[] { "dta" }, false);
    } else {
        usage();
        exit(-1);
    }

    final InMemoryDTAListImpl dtaList = new InMemoryDTAListImpl();
    File firstFile = null;
    if (files.size() == 0) {
        out.println("No files found.");
        exit(-1);
    } else {
        firstFile = files.iterator().next();
    }
    for (final File file : files) {
        dtaList.add(FileUtils.readFileToByteArray(file), file.getName());
    }

    final DTAToMzXMLConverter dtaToMzXMLConverter = new DTAToMzXMLConverterImpl();
    final MzXML mzxml = dtaToMzXMLConverter.dtaToMzXML(dtaList, null);
    final String mzxmlName = firstFile.getName().substring(0, firstFile.getName().indexOf(".")) + ".mzXML";
    new MzXMLUtility().serialize(mzxml, mzxmlName);
}

From source file:info.bitoo.utils.BiToorrentRemaker.java

public static void main(String[] args) throws IOException, TOTorrentException {
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;//w  w w . jav a 2 s.c o  m
    try {
        cmd = parser.parse(createCommandLineOptions(), args);
    } catch (ParseException e) {
        System.err.println("Parsing failed.  Reason: " + e.getMessage());
    }

    StringTokenizer stLocations = new StringTokenizer(cmd.getOptionValue("l"), "|");
    List locations = new ArrayList(stLocations.countTokens());

    while (stLocations.hasMoreTokens()) {
        URL locationURL = new URL((String) stLocations.nextToken());
        locations.add(locationURL.toString());
    }

    String torrentFileName = cmd.getOptionValue("t");

    File torrentFile = new File(torrentFileName);

    TOTorrentDeserialiseImpl torrent = new TOTorrentDeserialiseImpl(torrentFile);

    torrent.setAdditionalListProperty("alternative locations", locations);

    torrent.serialiseToBEncodedFile(torrentFile);

}