/** * A private method that parses each file, counting the frequency of words and keeping track of * the total number of words. * * @param file, String of filename to be parsed * @param counter, data structure to hold counts * @return sum, representing the total number of words in the file */ private static int parseAndCount(String file, DataCounter<String> counter) { int sum = 0; try { FileWordReader reader = new FileWordReader(file); String word = reader.nextWord(); while (word != null) { counter.incCount(word); sum++; word = reader.nextWord(); } } catch (IOException e) { System.err.println("Error processing " + file + " " + e); System.exit(1); } return sum; }