]>
Commit | Line | Data |
---|---|---|
a29c47e0 | 1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | Module Name:\r | |
13 | ToolChainMap.java\r | |
14 | \r | |
15 | Abstract:\r | |
16 | \r | |
17 | --*/\r | |
18 | \r | |
19 | package org.tianocore.build.toolchain;\r | |
20 | \r | |
21 | import java.util.HashMap;\r | |
22 | import java.util.Map;\r | |
23 | import java.util.Set;\r | |
24 | \r | |
136adffc | 25 | import org.tianocore.exception.EdkException;\r |
a29c47e0 | 26 | \r |
27 | public class ToolChainMap {\r | |
28 | \r | |
29 | private int matchLevel = ToolChainKey.keyLength - 2;\r | |
30 | \r | |
31 | private Map<ToolChainKey, String> map = null;\r | |
32 | \r | |
33 | public ToolChainMap() {\r | |
34 | //this.map = new TreeMap<ToolChainKey, String>();\r | |
35 | this.map = new HashMap<ToolChainKey, String>();\r | |
36 | }\r | |
37 | \r | |
38 | public String put(String key, String delimiter, String value)throws EdkException {\r | |
39 | ToolChainKey toolChainKey;\r | |
40 | \r | |
41 | try {\r | |
42 | toolChainKey = new ToolChainKey(key, delimiter);\r | |
43 | } catch (Exception e) {\r | |
44 | throw new EdkException(e.getMessage());\r | |
45 | }\r | |
46 | return (String)map.put(toolChainKey, value);\r | |
47 | }\r | |
48 | \r | |
49 | public String put(String key, String value) throws EdkException {\r | |
50 | ToolChainKey toolChainKey;\r | |
51 | \r | |
52 | try {\r | |
53 | toolChainKey = new ToolChainKey(key);\r | |
54 | } catch (Exception e) {\r | |
55 | throw new EdkException(e.getMessage());\r | |
56 | }\r | |
57 | return (String)map.put(toolChainKey, value);\r | |
58 | }\r | |
59 | \r | |
60 | public String put(String[] key, String value) throws EdkException {\r | |
61 | ToolChainKey toolChainKey;\r | |
62 | \r | |
63 | try {\r | |
64 | toolChainKey = new ToolChainKey(key);\r | |
65 | } catch (Exception e) {\r | |
66 | throw new EdkException(e.getMessage());\r | |
67 | }\r | |
68 | return (String)map.put(toolChainKey, value);\r | |
69 | }\r | |
70 | \r | |
71 | public String put(ToolChainKey key, String value) {\r | |
72 | return (String)map.put(key, value);\r | |
73 | }\r | |
74 | \r | |
75 | public String get(String key) throws EdkException {\r | |
76 | ToolChainKey toolChainKey;\r | |
77 | \r | |
78 | try {\r | |
79 | toolChainKey = new ToolChainKey(key);\r | |
80 | } catch (Exception e) {\r | |
81 | throw new EdkException(e.getMessage());\r | |
82 | }\r | |
83 | return get(toolChainKey);\r | |
84 | }\r | |
85 | \r | |
86 | public String get(String key, String delimiter) throws EdkException {\r | |
87 | ToolChainKey toolChainKey;\r | |
88 | \r | |
89 | try {\r | |
90 | toolChainKey = new ToolChainKey(key, delimiter);\r | |
91 | } catch (Exception e) {\r | |
92 | throw new EdkException(e.getMessage());\r | |
93 | }\r | |
94 | return get(toolChainKey);\r | |
95 | }\r | |
96 | \r | |
97 | public String get(String[] key) throws EdkException {\r | |
98 | ToolChainKey toolChainKey;\r | |
99 | \r | |
100 | try {\r | |
101 | toolChainKey = new ToolChainKey(key);\r | |
102 | } catch (Exception e) {\r | |
103 | throw new EdkException(e.getMessage());\r | |
104 | }\r | |
105 | return get(toolChainKey);\r | |
106 | }\r | |
107 | \r | |
108 | public String get(ToolChainKey key) throws EdkException {\r | |
109 | String result = map.get(key);\r | |
110 | if (result != null || map.containsKey(key)) {\r | |
111 | return result;\r | |
112 | }\r | |
113 | \r | |
114 | String[] keySet = key.getKeySet();\r | |
115 | ToolChainKey tmpKey;\r | |
116 | try {\r | |
117 | tmpKey = new ToolChainKey(keySet);\r | |
118 | } catch (Exception e) {\r | |
119 | throw new EdkException(e.getMessage());\r | |
120 | }\r | |
121 | \r | |
122 | int level = matchLevel;\r | |
123 | while (level >= 0) {\r | |
124 | int tmpLevel = level;\r | |
125 | while (tmpLevel >= level) {\r | |
126 | String[] tmpKeySet = tmpKey.getKeySet();\r | |
127 | try {\r | |
128 | if (!tmpKeySet[tmpLevel].equals("*")) {\r | |
129 | tmpKey.setKey("*", tmpLevel);\r | |
130 | tmpLevel = matchLevel;\r | |
131 | } else {\r | |
132 | tmpKey.setKey(keySet[tmpLevel], tmpLevel);\r | |
133 | --tmpLevel;\r | |
134 | continue;\r | |
135 | }\r | |
136 | } catch (Exception e) {\r | |
137 | throw new EdkException(e.getMessage());\r | |
138 | }\r | |
139 | \r | |
140 | result = map.get(tmpKey);\r | |
141 | if (result != null) {\r | |
142 | map.put(key, result);\r | |
143 | return result;\r | |
144 | }\r | |
145 | }\r | |
146 | --level;\r | |
147 | }\r | |
148 | \r | |
149 | map.put(key, result);\r | |
150 | return result;\r | |
151 | }\r | |
152 | \r | |
153 | public int size() {\r | |
154 | return map.size();\r | |
155 | }\r | |
156 | \r | |
157 | public Set<ToolChainKey> keySet() {\r | |
158 | return (Set<ToolChainKey>)map.keySet();\r | |
159 | }\r | |
160 | \r | |
161 | // public String toString() {\r | |
162 | // return map.toString();\r | |
163 | // }\r | |
164 | }\r | |
165 | \r |