Ejemplo n.º 1
0
 Long occurrencesCount(Document document, String searchedWord) {
   long count = 0;
   for (String line : document.getLines()) {
     for (String word : wordsIn(line)) {
       if (searchedWord.equals(word)) {
         count = count + 1;
       }
     }
   }
   return count;
 }
Ejemplo n.º 2
0
 static Folder fromDirectory(File dir) throws IOException {
   List<Document> documents = new LinkedList<>();
   List<Folder> subFolders = new LinkedList<>();
   for (File entry : dir.listFiles()) {
     if (entry.isDirectory()) {
       subFolders.add(Folder.fromDirectory(entry));
     } else {
       documents.add(Document.fromFile(entry));
     }
   }
   return new Folder(subFolders, documents);
 }