You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Sunnan <su...@handgranat.org> on 2007/05/14 15:59:52 UTC

Suggestion for MapUtils

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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org