java - Loading map with keys that are not present, else load default -


here example method:

public void loadstuff(map<string, object> somemap) {   map<string, object> mymap = new hashmap<string, object>();    //i load defaults here first   mymap.put("one", someobject);   mymap.put("two", someobject);   mymap.put("three", someobject);    //now put entire somemap keys present in somemap overridden in mymap , others remain default.   mymap.putall(somemap); } 

now, there better way of doing these redundant puts number of defaults in scenario lot.

consider creating initial map defaults in, , use:

// alternatively, use clone() map<string, object> mymap = new hashmap<string, object>(defaults); mymap.putall(somemap); 

aside else means can load "default map" properties file or whatever.

if don't fact put each value twice, write loop check each key - i'd use above code. it's simple , should work fine.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -