0

Overall, I am trying to create basically a search program using inverted indexes, TF-IDF, and other related topics.

I have a TreeMap, wordToPost, which maps a string to a Posting object.

// Map each term to a Posting object
Map<String, Posting> wordToPost = new TreeMap<String, Posting>();

Previously, a string, stemQuery, has been put into the above TreeMap with its corresponding Posting. I retrieve the Posting object for stemQuery and assign it to thisPosting:

// Get the posting object for this word
Posting thisPosting = wordToPost.get(query)

Then I take the thisPosting object and get its internal TreeMap, which is defined as:

// Map the document ID to the number of occurrences in that document
TreeMap<Integer, Integer> docToOccur = new TreeMap<Integer, Integer>();

Getting the TreeMap:

TreeMap trMap = thisPosting.getMap();

Now I would like to iterate through each entry in trMap, so I do the following:

for (Map.Entry<Integer, Integer> entry : trMap.entrySet())
    {
       // Will do misc. operations here
    }

The error I get is on the for loop line. It says required: Entry found: Object There is a little arrow that points to the first parenthesis on trMap.entrySet()

I understand that this is saying trMap.entrySet is evidently returning an Object, instead of the expected Entry, but I'm not sure how to fix this. How do I successfully iterate through this TreeMap?

Morgan4568771
  • 153
  • 2
  • 4
  • 14

0 Answers0