title: HashMap for Huffman Tree
body: <p>I have an assignment dealing with Huffman trees. My professor mentioned that we should use a HashMap but didn't explain anything about them. I've looked things up about them but I am running into problems with them in my code. These are the error messages that I am getting. </p>
  
  <pre><code>n00832607.java:542: error: incompatible types
  for(Map.Entry e : charCounts.entrySet())
                                      ^
  required: Entry
  found:    Object
  n00832607.java:610: error: incompatible types
  for(Map.Entry entry : codeTable.entrySet())
                                         ^
  required: Entry
  found:    Object
  </code></pre>
  
  <p>So I can tell that it wants it to return an Entry but I am not exactly sure how to approach this. Am I supposed to be casting it as something?</p>
  
  <p>This is my code.</p>
  
  <pre><code>//Beging Huffman Class
  class Huffman{
  
  Tree tree;
  
  TreeMap codeTable;
  
  
  protected HashMap calculateFrequency(String message)
  {
  
  int messageLength = message.length();
  char ch;
  int count;
  HashMap charCounts = new HashMap();
  
  for(int i = 0; i&lt; messageLength; i++)
  {
  
  ch = message.charAt(i); 
  
  if(charCounts.containsKey(ch))
  {
  count = (int) charCounts.get(ch);
  ++count;
  charCounts.put(ch, count);   
  }
  
  else
  {
  charCounts.put(ch, 1);
  }
  }
  //end for
  return charCounts;
  }
  //end calculateFrequency
  
  protected void createHuffmanTree(String message)
  {
  HashMap charCounts = calculateFrequency(message);
  PriorityQueue trees = new PriorityQueue();
  Tree temp;
  
  for(Map.Entry e : charCounts.entrySet())
    {
  
    temp = new Tree((char)e.getKey(), (int)e.getValue());
    trees.add(temp);
  
    }
  
  
  while(trees.size() &gt; 1)
    {
    temp = new Tree((Tree)trees.remove(), (Tree)trees.remove());
    trees.add(temp);   
    }
  tree = (Tree)trees.remove();      
  
  }
  //end createHuffmanTree
  
  //Begin displayCodeTable
  public void displayCodeTable()
  {
  
  System.out.println("Character Code");
  
  for(Map.Entry entry : codeTable.entrySet())
    {
    char key = (char)entry.getKey();
    System.out.println(key + "" + entry.getValue());
    }
  }
  //End displayCodeTable 
  </code></pre>