I\'ve been using a lot Perl hashes due to super flexibility and convenient. for instance, in Perl I can do the following:
$hash{AREA_CODE}->{PHONE}->{S
You can easily subclass your hash to add a method that'll autovivify for you.
From: $hash{AREA_CODE}->{PHONE}->{STREET_ADDR}
To: hash.vivifyingGet(areaCode).put(phone, streetAddr).
Assuming I've created the hash with:
/**
* A two-level autovivifying hashmap of X and Y to Z. Provides
* a new method #vivifyingGet(X) which creates the next level of hash.
*/
Map> hash =
new HashMap>() {
/**
* Convenience method to get or create the next level of hash.
* @param key the first level key
* @return the next level map
*/
public Map vivifyingGet(Phone key) {
if (containsKey(key)) {
return get(key);
} else {
Map = hash = new HashMap();
put(key, hash);
return hash;
}
}
};