Lab: Map Implementation on Queue
Objective
In this lab you will practice implementing and testing a kernel
component, Map2 implemented on Queue.
Setup
To get started, import the project for this lab, MapOnQueue, from the
MapOnQueue.zip file available at this link. If you
don't remember how to do this, see the Setup
instructions
in an earlier lab.
Method
-
Take a look at the
srcandtestfolders in your new project. Open theMap2.javafile in thesrcfolder and explore it. In particular, take a look at the private members (the representation) at the top of the class and the convention and correspondence in the Javadoc comment for the class. Remember that the correspondence clause is a mathematical statement that describes how a client should interpret the variables in the data representation (denoted by$thisfollowed by a dot and the name of the instance variable) as an abstract value of aMapvariable (writtenthis). The convention clause is a mathematical statement that describes properties the implementer claims are satisfied by the data representation at the end of every method call, including the constructor(s); it therefore mentions only the data representation,$this, and not the abstract value as seen by the client,this. (Note that the notation$thisnever appears in Java code, but only in Javadoc comments like this that describe aspects of the data representation!) -
Paste the code you wrote for the homework into the body of the private method
moveToFront, and complete the body of the kernel methods (add,remove,removeAny,value,hasKey, andsize) inMap2in thesrcfolder.If you need to construct a
Pairobject in your code, just use the only available implementation of theMap.Pairinterface calledMapSecondary.SimplePair<K, V>. Inside theMap2class, you will be able to declare and initialize aPairvariable with a statement like this:Pair<K, V> p = new SimplePair<>(key, value);where key and value are some variables of type
KandV, respectively. -
Paste the test cases you designed for the homework at the end of the
MapTestclass in thetestfolder. -
Run
Map2Testin thetestfolder to test your implementation ofMap2. Fix any bugs that you discover and/or add extra test cases, if you realize that you are missing some important cases.
Additional Activities
- Take a look at the
Standardmethods (newInstance,clear, andtransferFrom) inMap2. We will discuss the details of these implementations later in the semester, but for now, design test cases to test these methods and add the test cases to your test fixture,MapTest.