Hi, I'm relatively new to Java but I'm already a big fan of the Jakarta Commons.
I was wondering, is there something like the following already in
Commons, be it Lang or Collections? (I'm thinking
...collections.MapUtils.)
/**
* Creates a new Map containing some of the keys from another Map,
* optionally renamed.
* <p>
* @param orig the map to get keys from
* @param keys the new-key->old-key map
*/
public static HashMap renameKeys (Map orig, Map keys) {
HashMap ret = new HashMap();
for (Object o : keys.entrySet()) {
ret.put(((Entry)o).getKey(), orig.get(((Entry)o).getValue()));
}
return ret;
}
I typically use it when I have a map (often a BeanMap) and I need the
same values, but with other key names (in order to automatically
populate an LDAPEntry or some XML). (I usually use String key names.)
If there's nothing like this already, I'd like to submit this. I'm
open to improving it, of course.
Thangs for your time,
Sunnan
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]