
import java.io.File;
import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


/**
 * @author Joseph Cumbo (jwc6999)
 */
public class Project {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        if (args.length < 2) {
            System.out.println("Not enough arguments. Correct usage: Project [file,...] [word,...]");
            return;
        }
        String[] fileNames = args[0].split(",");
        String[] words = args[1].split(",");
        File[] files = new File[fileNames.length];
        for (int i = 0; i < fileNames.length; i++) {
            File file = new File(fileNames[i]);
            if (!file.exists()) {
                System.err.println("The file '" + fileNames[i] + "' does not exist.");
                return;
            }
            files[i] = file;
        }

    }

    public static class WordSearch {

        private final File[] files;
        private final String[] words;
        private final ExecutorService readPool = Executors.newCachedThreadPool();
        private final ExecutorService searchPool = Executors.newCachedThreadPool();

        /**
         * Creates a new WordSearch object. A defensive copy is made for the
         * input parameters.
         *
         * @param files the list of files to search from.
         * @param words the list of words to search in the files for.
         */
        public WordSearch(File[] files, String[] words) {
            this.files = Arrays.copyOf(files, files.length);
            this.words = Arrays.copyOf(words, words.length);
        }

        public void run() {

        }
    }

}

@@ -31,19 +31,131 @@
 ava.
-util.Arrays
+io.IOException;%0Aimport java.nio.charset.Charset;%0Aimport java.nio.file.Files;%0Aimport java.util.Arrays;%0Aimport java.util.List
 ;%0Aim
@@ -1014,24 +1014,85 @@
 ;%0A        %7D%0A
+        WordSearch wordSearch = new WordSearch(files, words);
 %0A    %7D%0A%0A    
@@ -1425,70 +1425,8 @@
 ect.
- A defensive copy is made for the%0A         * input parameters.
 %0A   
@@ -1792,16 +1792,1711 @@
 run() %7B%0A
+            for (int i = 0; i %3C files.length; i++) %7B%0A                FileReadTask readTask = new FileReadTask(files%5Bi%5D, words);%0A                readPool.submit(readTask);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static class FileReadTask implements Runnable %7B%0A%0A        /**%0A         * Each thread will make a defensive copy of the word list to prevent%0A         * threads from modifying the data.%0A         */%0A        private final File file;%0A        private final String%5B%5D words;%0A%0A        public FileReadTask(File file, String%5B%5D words) %7B%0A            this.file = file;%0A            this.words = Arrays.copyOf(words, words.length);%0A        %7D%0A%0A        @Override%0A        public void run() %7B%0A            try %7B%0A                List%3CString%3E lines = Files.readAllLines(file.toPath(), Charset.defaultCharset());%0A            %7D catch (IOException ex) %7B%0A                System.err.println(%22An error occured while reading the file '%22 + file.getName() + %22'.%22);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static class FileSearchTask implements Runnable %7B%0A%0A        private final String fileName;%0A        private final String word;%0A        private final String lword;%0A        private final List%3CString%3E lines;%0A%0A        public FileSearchTask(String fileName, String word, List%3CString%3E lines) %7B%0A            this.fileName = fileName;%0A            this.word = word;%0A            this.lword = word.toLowerCase();%0A            this.lines = lines;%0A        %7D%0A%0A        @Override%0A        public void run() %7B%0A            for (String line : lines) %7B%0A                if (line.toLowerCase().contains(lword)) %7B%0A                    System.out.println(word + %22 %22 + fileName);%0A                    return;%0A                %7D%0A            %7D
 %0A       
@@ -3504,11 +3504,10 @@
 %7D%0A    %7D%0A
-%0A
 %7D%0A

Create a read and search task runnable