commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sunnan <>
Subject Suggestion for MapUtils
Date Mon, 14 May 2007 13:59:52 GMT
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

 * 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,

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message