01: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.services.persondir.support.merger;
07:
08: import java.util.Iterator;
09: import java.util.Map;
10:
11: /**
12: * Merger which implements accumulation of Map entries such that entries once
13: * established are individually immutable.
14: * @author andrew.petro@yale.edu
15: * @version $Revision: 35128 $ $Date: 2004-12-13 16:27:49 -0700 (Mon, 13 Dec 2004) $
16: */
17: public class NoncollidingAttributeAdder implements IAttributeMerger {
18:
19: /**
20: * For entries in toConsider the keys of which are not keys in toModify,
21: * adds the entry to toModify and returns toModify.
22: * @param toModify - base Map the entries of which are considered here
23: * to be immutable.
24: * @param toConsider - Map to merge into toModify for all noncolliding keys.
25: * @return toModify with entries the intersection of our method arguments,
26: * with preference given to toModify's existing entries for all key collisions.
27: */
28: public Map mergeAttributes(Map toModify, Map toConsider) {
29: if (toModify == null)
30: throw new IllegalArgumentException(
31: "toModify argument illegally null.");
32: if (toConsider == null)
33: throw new IllegalArgumentException(
34: "toConsider argument illegally null.");
35:
36: for (Iterator iter = toConsider.keySet().iterator(); iter
37: .hasNext();) {
38: String key = (String) iter.next();
39: if (!toModify.containsKey(key))
40: toModify.put(key, toConsider.get(key));
41: }
42:
43: return toModify;
44: }
45:
46: }
|