As a learning tool for DB4o and Java I have started to create a Telephone Directory. To do this I create an instance of a TelephoneDirectory which contains a year and a HashMap of entries.
So I add a few entries with addEntry. What I would like to do is search through the telephone directory for a specific name. For this I use QueryByExample (QBE), like so:Code:public class TelephoneDirectory {
private int year;
private HashMap<String, String> hashmap;
public TelephoneDirectory(int year) {
this.year = year;
this.hashmap = new HashMap<String, String>();
}
public int getYear() {
return year;
}
public HashMap getHashmap() {
return hashmap;
}
public void addEntry(String name, String number) {
hashmap.put(number, name);
}
}
The issue that I am having with this is that if a result is found in the hashmap, then I need the key/value pair to be printed. So far the output is:Code:public static void lookupName(String name, int year, ObjectContainer db) {
TelephoneDirectory proto = new TelephoneDirectory(year);
proto.addEntry(name, null);
ObjectSet result=db.queryByExample(proto);
System.out.println("Size:" + result.size());
while(result.hasNext()) {
System.out.println(result.next());
}
}
This is obviously because there is no toString() method. But what do I put in the toString() method as only a subset of hashmap values will be present in the result.Quote:
Size:1 telephonedirectory.TelephoneDirectory@da4b71
Example
And I then query:Code:TelephoneDirectory dir = new TelephoneDirectory(2011);
dir.addEntry("12345", "Adam");
dir.addEntry("67890", "Bob");
dir.addEntry("24680", "Carl");
Expected Result:Code:lookupName("Bob", 2011, db);
I am sure that it is something simple that I am overlooking.Quote:
2011 - 67890: Bob
Thanks in advance.

