KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > utils > VersionMap


1 /* *****************************************************************************
2  * SWFMap.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.utils;
11 import java.util.*;
12
13 /**
14  * A Map to retrieve and store an object based on some key. For example, could
15  * be used to store different versions of the same SWF bytecode. Not
16  * thread-safe.
17  */

18 public class VersionMap {
19
20     Map mMap = new HashMap();
21
22     /**
23      * Put a value based on version and key.
24      */

25     public void put(Object JavaDoc version, Object JavaDoc key, Object JavaDoc value) {
26         Map m = (Map)mMap.get(key);
27         if (m == null) {
28             m = new HashMap();
29             mMap.put(key, m);
30         }
31         m.put(version, value);
32     }
33
34     /**
35      * Get value based on version and key.
36      */

37     public Object JavaDoc get(Object JavaDoc version, Object JavaDoc key) {
38         Map m = (Map)mMap.get(key);
39         if (m == null) return null;
40         return m.get(version);
41     }
42
43     /**
44      * @return set of keys.
45      */

46     public Set keySet() {
47         return mMap.keySet();
48     }
49
50     /**
51      * @return map of versions.
52      */

53     public Map getVersions(Object JavaDoc key) {
54         return (Map)mMap.get(key);
55     }
56
57     /**
58      * @return number of items in this map.
59      */

60     public int size() {
61         return mMap.size();
62     }
63 }
64
Popular Tags