]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainMap.java
baddd95a98d388ef23988725c79b7dfa5cd81dfd
[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 public class ToolChainMap {
26
27 private int matchLevel = ToolChainKey.keyLength - 2;
28
29 private Map<ToolChainKey, String> map = null;
30
31 public ToolChainMap() {
32 this.map = new HashMap<ToolChainKey, String>();
33 }
34
35 public String put(String key, String delimiter, String value) {
36 ToolChainKey toolChainKey;
37
38 try {
39 toolChainKey = new ToolChainKey(key, delimiter);
40 } catch (Exception e) {
41 return null;
42 }
43 return (String)map.put(toolChainKey, value);
44 }
45
46 public String put(String key, String value) {
47 ToolChainKey toolChainKey;
48
49 try {
50 toolChainKey = new ToolChainKey(key);
51 } catch (Exception e) {
52 return null;
53 }
54 return (String)map.put(toolChainKey, value);
55 }
56
57 public String put(String[] key, String value) {
58 ToolChainKey toolChainKey;
59
60 try {
61 toolChainKey = new ToolChainKey(key);
62 } catch (Exception e) {
63 return null;
64 }
65 return (String)map.put(toolChainKey, value);
66 }
67
68 public String put(ToolChainKey key, String value) {
69 return (String)map.put(key, value);
70 }
71
72 public String get(String key) {
73 ToolChainKey toolChainKey;
74
75 try {
76 toolChainKey = new ToolChainKey(key);
77 } catch (Exception e) {
78 return null;
79 }
80 return get(toolChainKey);
81 }
82
83 public String get(String key, String delimiter) {
84 ToolChainKey toolChainKey;
85
86 try {
87 toolChainKey = new ToolChainKey(key, delimiter);
88 } catch (Exception e) {
89 return null;
90 }
91 return get(toolChainKey);
92 }
93
94 public String get(String[] key) {
95 ToolChainKey toolChainKey;
96
97 try {
98 toolChainKey = new ToolChainKey(key);
99 } catch (Exception e) {
100 return null;
101 }
102 return get(toolChainKey);
103 }
104
105 public String get(ToolChainKey key) {
106 String result = map.get(key);
107 if (result != null || map.containsKey(key)) {
108 return result;
109 }
110
111 String[] keySet = key.getKeySet();
112 ToolChainKey tmpKey;
113 try {
114 tmpKey = new ToolChainKey(keySet);
115 } catch (Exception e) {
116 return null;
117 }
118
119 int level = matchLevel;
120 while (level >= 0) {
121 int tmpLevel = level;
122 while (tmpLevel >= level) {
123 String[] tmpKeySet = tmpKey.getKeySet();
124 try {
125 if (!tmpKeySet[tmpLevel].equals("*")) {
126 tmpKey.setKey("*", tmpLevel);
127 tmpLevel = matchLevel;
128 } else {
129 tmpKey.setKey(keySet[tmpLevel], tmpLevel);
130 --tmpLevel;
131 continue;
132 }
133 } catch (Exception e) {
134 return null;
135 }
136
137 result = map.get(tmpKey);
138 if (result != null) {
139 map.put(key, result);
140 return result;
141 }
142 }
143 --level;
144 }
145
146 map.put(key, result);
147 return result;
148 }
149
150 public int size() {
151 return map.size();
152 }
153
154 public Set<ToolChainKey> keySet() {
155 return (Set<ToolChainKey>)map.keySet();
156 }
157 }
158