The goal of this lab is to practice writing generic classes--plus get some practice writing nested classes.
In class we have seen examples of generic linked lists and a generic ArrayList-like class. In this lab we will write a generic class that will be something similar to a HashMap.
We will use a simplified version of this interface in the lab. Your main task in this lab is to implement this interface.
The driver program to test the map will use it to tally the frequencies of words in a file. You may have seen an example like this in Programming I.
On the inside, your class will be a linked list. Think about how you would implement such a think as a linked list, consider how it would need to be different from the linked lists we've already seen, and how the specific operations would be defined.
This map, however, will have a special feature.
Java's HashMap
orders associations in an unpredictable order---
if you iterated through the key set, you would not get the keys in
the same order that you added them, nor would there be any clear
reason for the order that they would be iterated through.
Your map, however, will take a Comparator<K>
object
in its constructor---that is, a comparator with the same parameterized
type as the key type.
This will determine how the associations are ordered
and what order the keys come when using keyIterator()
.
Oh, and resist the temptation to refer to your class as a hash map. The "hash" in "hashmap" refers to a specific way to implement a map (or set). We are not doing hashing in this lab. But we will learn about hashing later in the semester.
Finally, before you start discuss with your partner and decide the basic structure of your classes. How will you implement the map as a linked list? What will your node class look like?