code: private static HashSet<String> searchDirectoryForPattern(File dir,String A, String B) 
          throws Exception {
          
          File[] files = dir.listFiles();
  
          HashSet<String> pattern_set = new HashSet<String>();
  
          for (int i = 0; i < files.length; i++) {
              File f = files[i];
              if (f.isDirectory()) {
                  pattern_set.addAll(searchDirectoryForPattern(f, A, B));
              } else if (f.getName().endsWith(".txt")) {
                  Scanner sc = new Scanner(f);
                  while (sc.hasNext()) {
                      if (A.equals(sc.next())) {
                          String pattern = "";
                          int count = 0;
                          while (count <= MAX_INTER && sc.hasNext()) { 
                              String curr = sc.next();
                              if (count >= MIN_INTER && B.equals(curr)) {
                                  //add the String onto a Set of Strings containing the patterns
                                  //System.err.println("adding pattern: " + pattern);
                                  pattern_set.add(pattern);
                                  break;
                                  /*
                                  for (int j = 0; j < count; j++) {
                                      System.err.print(pattern[j] + " ");
                                  }
                                      System.err.print("\n");
                                  */
                              } else {
                                  if (count > 0) {
                                      pattern += " ";
                                  }
                                  pattern += curr;
                                  count++;
                              }
                          }
                      }
                  }
              }
          }
          return pattern_set;
      }
docs: recursive method that finds interleving patterns between A and B in all files
  within a given directory