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