Java Reference
In-Depth Information
// looks for a registered object in objectList and
// returns its label identifier
public static String getObjectRef(Object obj) {
Iterator iterator # objectList.entrySet().iterator();
Map.Entry entry # null ;
while (iterator.hasNext()) {
entry # (Map.Entry) iterator.next();
if (entry.getValue().equals(obj))
return (String) entry.getKey();
}
return null ;
}
// this method is used to display the list of registered
// operations
public static String[] getEntryList() {
String list[] # new String[entryList.size()];
Entry entry;
for ( int i # 0; i < entryList.size(); i !! ) {
entry # (Entry) entryList.get(i);
list[i] # entry.toString();
}
return list;
}
}
18.4.4
Test
The test case described in Section 18.3.3 is implemented by three classes:
class Tower , class Hanoi and class Game . Class Tower represents the simplest
recoverable objects of the applications, i.e. the three pegs with the stacked
discs. It implements methods pull() and push() that remove and add a single
disc from and to the peg respectively and the methods defined in interface
Trackable .
package hanoi;
import recap.*;
import java.io.*;
public class Tower implements Trackable {
public static int DIM # 10; // the total number of disks
int queue[] # new int[DIM];
// the set of discs stacked on the peg
int first # 0;
// the first free position on the peg.
DrawingArea drawingArea # null ;
// the reference to the GUI
public void init( int numBlocks) {
if (numBlocks > DIM)
numBlocks # DIM;
 
Search WWH ::




Custom Search