01: /*
02: * Created on 7 Aug 2006
03: */
04: package uk.org.ponder.arrayutil;
05:
06: import java.util.ArrayList;
07: import java.util.HashMap;
08: import java.util.List;
09: import java.util.Map;
10:
11: /** Utilities for working with java.util.Map instances **/
12:
13: public class MapUtil {
14: /** I have finally had *enough* of writing this code! */
15: public static void putMultiMap(Map target, Object key, Object value) {
16: List oldlist = (List) target.get(key);
17: if (oldlist == null) {
18: oldlist = new ArrayList();
19: target.put(key, oldlist);
20: }
21: oldlist.add(value);
22: }
23:
24: /** Construct a Map consisting of the single supplied key/value pair */
25: public static Map make(Object key, Object value) {
26: Map togo = new HashMap();
27: togo.put(key, value);
28: return togo;
29: }
30:
31: /** Construct a Map holding the two supplied key/value pairs */
32: public static Map make(Object key1, Object value1, Object key2,
33: Object value2) {
34: Map togo = new HashMap();
35: togo.put(key1, value1);
36: togo.put(key2, value2);
37: return togo;
38: }
39: }
|