<commit_before>package jse8_impatient.chapter2;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tlanders on 11/22/2014.
 */
public class Exercise1 {
    public static void main(String [] args) throws Exception {
        System.out.println("Exercise8");

        // runners using enhanced for loop
        String[] names = { "Peter", "Paul", "Mary" };
        List<Runnable> runners = new ArrayList<>();
        for(String name : names) {
            runners.add(() -> System.out.println("1: " + name));
        }

        for(Runnable r : runners) {
            new Thread(r).start();
        }

        Thread.sleep(1000); // let these threads finish

        // runners using standard for loop. have to use assignment inside for loop (i.e. not names2[i]) to
        // make compiler happy.
        String[] names2 = { "Peter", "Paul", "Mary" };
        List<Runnable> runners2 = new ArrayList<>();
        for(int i = 0; i < names2.length; i++) {
            String n = names2[i];
            runners2.add(() -> System.out.println("2: " + n));
        }

        for(Runnable r : runners2) {
            new Thread(r).start();
        }
    }
}<commit_msg>added parallel stream method<commit_after>package jse8_impatient.chapter2;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by tlanders on 11/22/2014.
 */
public class Exercise1 {
    public static void main(String [] args) throws Exception {
        System.out.println("Exercise1");

        if (args.length < 1) {
            System.out.println("USAGE: java Exercise1 INPUT_FILE");
            System.exit(1);
        }

        String contents = new String(Files.readAllBytes(
                Paths.get(args[0])), StandardCharsets.UTF_8); // Read file into string
        List<String> words = Arrays.asList(contents.split("[\\P{L}]+"));
        // Split into words; nonletters are delimiters

        long count = 0;
        for (String w : words) {
            System.out.println("  w=" + w);

            if (w.length() > 12) count++;
        }

        System.out.println("Exercise1, for loop count=" + count);

        // same as above but with parallel stream
        count = words.parallelStream().filter(w -> w.length() > 12).count();

        System.out.println("Exercise1, parallel stream count=" + count);


    }
}
{'fraction_non_alphanumeric': 0.13994288045695635, 'fraction_numerical': 0.02039983680130559, 'mean_word_length': 2.27369826435247, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7380460', 'n_tokens_mistral': 771, 'n_tokens_neox': 709, 'n_words': 192}