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