package com.github.timp.anagram;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
 * Display all anagrams of a string.
 */
public class Anagrammer {

  private Dictionary dictionary;

  public Anagrammer() throws IOException {
    dictionary = new Dictionary();
  }

  /**
   * @param args one or more space separated strings
   * @return the capitalised results
   * @throws IOException if the file does not exist or there is a problem reading it
   */
  public ArrayList<String> run(String[] args) throws IOException {
    // Populate our dictionary from file
    dictionary = new Dictionary();


    // Filter out impossible words from dictionary
    LetterBag letters = new LetterBag();
    for (String word : args) {
      letters.add(word);
    }
    HashSet<String> possibles = new HashSet<>();
    for (String key : dictionary.keys()) {
      if (letters.contains(key)) {
        possibles.add(key);
      }
    }

    Set<String> searches = new HashSet<>();
    AnagramKeyTree resultTree = new AnagramKeyTree();
   for (String p : possibles) {
      ArrayList<String> keys = new ArrayList<>();
      Query q = new Query(resultTree, searches, keys, p, possibles, letters);
      q.producesResults();
    }

    return dictionary.output(resultTree);
  }


  /**
   * @param args one or more space separated strings
   */
  public static void main(String[] args) throws IOException {
    ArrayList<String> answers = new Anagrammer().run(args);
      for (String line : answers) {
        System.out.println(line);
      }
  }

}

@@ -277,24 +277,65 @@
 Exception %7B%0A
+    // Populate our dictionary from file%0A
     dictiona
@@ -362,16 +362,18 @@
 );%0A  %7D%0A%0A
+%0A%0A
   /**%0A  
@@ -626,82 +626,372 @@
     
-// Populate our dictionary from file%0A    dictionary = new Dictionary();%0A%0A%0A
+String result = %22%22;%0A    for (String item : args) %7B%0A      result += item;%0A    %7D%0A    return run(result);%0A  %7D%0A  /**%0A   * @param words one or more space separated strings%0A   * @return the capitalised results%0A   * @throws IOException if the file does not exist or there is a problem reading it%0A   */%0A  public ArrayList%3CString%3E run(String words) throws IOException %7B%0A%0A  
     
@@ -1082,41 +1082,8 @@
 ();%0A
-    for (String word : args) %7B%0A  
     
@@ -1098,25 +1098,20 @@
 add(word
+s
 );%0A
-    %7D%0A
     Hash
@@ -1373,16 +1373,17 @@
 e();%0A   
+ 
 for (Str
@@ -1554,24 +1554,25 @@
 sResults();%0A
+ 
     %7D%0A%0A    r

Refactor to take a string