View Javadoc

1   /*
2    * Copyright (c) 2005, The K-Wf Grid Consortium
3    * Fraunhofer Institute for Computer Architecture and Software Technology
4    * See http://www.kwfgrid.eu and http://www.first.fraunhofer.de for more details.
5    */
6   package net.kwfgrid.gwes.uiproxy;
7   
8   import java.util.*;
9   
10  /**
11     A two dimensional HashMap.
12   */
13  public class HashMapOfMaps extends HashMap {
14      public HashMapOfMaps() {
15  	super();
16      }
17      
18      /**
19         Create a mapping from the specified key to an empty map.
20         If the key already exists this method will do nothing.
21         @return The map the specified key is mapped to.
22      */
23      public synchronized Map createKey(Object key) {
24  	Map map = getMap(key);
25  	if (map==null) {
26  	    map = new HashMap();
27  	    super.put(key, map);
28  	}
29  	return map;
30      }
31  
32      /**
33         Overridden. This method is not allowed for this class and thus does nothing.
34         @return <code>null</code>
35      */
36      public synchronized Object put(Object key, Object value) {
37  	return null;
38      }
39  
40      /**
41         Create a two dimensional mapping for the specified keys and value.
42         @return The value formerly mapped to the specified keys (maybe <code>null</code>).
43      */
44      public synchronized Object put(Object key1, Object key2, Object value) {
45  	Map index2 = createKey(key1);
46  	Object old = index2.get(key2);
47  	index2.put(key2, value);
48  	return old;
49      }
50  
51      /**
52         Get the map the specified key is mapped to.
53         @return The map or <code>null</code> if no mapping for the specified key exists.
54      */
55      public synchronized Map getMap(Object key) {
56  	return (Map)get(key);
57      }
58  
59      /**
60         Get the value for a two dimensional mapping.
61      */
62      public synchronized Object get(Object key1, Object key2) {
63  	Map index2 = getMap(key1);
64  	if (index2!=null) return index2.get(key2);
65  	else return null;
66      }
67  
68      /**
69         Remove a two dimensional mapping.
70         @return The value formerly mapped to the specified keys.
71      */
72      public synchronized Object remove(Object key1, Object key2) {
73  	Map index2 = getMap(key1);
74  	if (index2!=null) return index2.remove(key2);
75  	else return null;
76      }
77  }
78