Sunday, November 23, 2008

Map

Odd thought which I don't know quite where it should go. 

I've been thinking about the map interface in Java a fair bit recently and the thing that does shock me is there is no publicly available implementation of map backed by a database or possibly file. OK this would only be for and largely hetrogenious simple classes (Int,String,Float, and groups there of - so no complex binary trees).  But the code would look like this 

Map myPhonemap = new MySQLMap( 'DatabasesName','user','password' , append); 

myPhonemap.put("bob",555343330); 
myPhonemap.put("Alpha",40232302);

Integer bobnumber = myPhonemap.get("bob");
// print all phone numbers
for( Integer who: mymap) 
System.out.println(Integer);  

Objects put into the address book would be 'weak' that is the objects would be weakly held and if all other references disappear then they would be garbage collected. Equally when an object is returned it is created a new (but could be cached but that might be confusing).

Needs large amout of reflection could but would work. Could also create a database backed vector. 

No comments: