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
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.
19 package org
.tianocore
.build
.toolchain
;
21 import java
.util
.HashMap
;
25 import org
.tianocore
.exception
.EdkException
;
27 public class ToolChainMap
{
29 private int matchLevel
= ToolChainKey
.keyLength
- 2;
31 private Map
<ToolChainKey
, String
> map
= null;
33 public ToolChainMap() {
34 //this.map = new TreeMap<ToolChainKey, String>();
35 this.map
= new HashMap
<ToolChainKey
, String
>();
38 public String
put(String key
, String delimiter
, String value
)throws EdkException
{
39 ToolChainKey toolChainKey
;
42 toolChainKey
= new ToolChainKey(key
, delimiter
);
43 } catch (Exception e
) {
44 throw new EdkException(e
.getMessage());
46 return (String
)map
.put(toolChainKey
, value
);
49 public String
put(String key
, String value
) throws EdkException
{
50 ToolChainKey toolChainKey
;
53 toolChainKey
= new ToolChainKey(key
);
54 } catch (Exception e
) {
55 throw new EdkException(e
.getMessage());
57 return (String
)map
.put(toolChainKey
, value
);
60 public String
put(String
[] key
, String value
) throws EdkException
{
61 ToolChainKey toolChainKey
;
64 toolChainKey
= new ToolChainKey(key
);
65 } catch (Exception e
) {
66 throw new EdkException(e
.getMessage());
68 return (String
)map
.put(toolChainKey
, value
);
71 public String
put(ToolChainKey key
, String value
) {
72 return (String
)map
.put(key
, value
);
75 public String
get(String key
) throws EdkException
{
76 ToolChainKey toolChainKey
;
79 toolChainKey
= new ToolChainKey(key
);
80 } catch (Exception e
) {
81 throw new EdkException(e
.getMessage());
83 return get(toolChainKey
);
86 public String
get(String key
, String delimiter
) throws EdkException
{
87 ToolChainKey toolChainKey
;
90 toolChainKey
= new ToolChainKey(key
, delimiter
);
91 } catch (Exception e
) {
92 throw new EdkException(e
.getMessage());
94 return get(toolChainKey
);
97 public String
get(String
[] key
) throws EdkException
{
98 ToolChainKey toolChainKey
;
101 toolChainKey
= new ToolChainKey(key
);
102 } catch (Exception e
) {
103 throw new EdkException(e
.getMessage());
105 return get(toolChainKey
);
108 public String
get(ToolChainKey key
) throws EdkException
{
109 String result
= map
.get(key
);
110 if (result
!= null || map
.containsKey(key
)) {
114 String
[] keySet
= key
.getKeySet();
117 tmpKey
= new ToolChainKey(keySet
);
118 } catch (Exception e
) {
119 throw new EdkException(e
.getMessage());
122 int level
= matchLevel
;
124 int tmpLevel
= level
;
125 while (tmpLevel
>= level
) {
126 String
[] tmpKeySet
= tmpKey
.getKeySet();
128 if (!tmpKeySet
[tmpLevel
].equals("*")) {
129 tmpKey
.setKey("*", tmpLevel
);
130 tmpLevel
= matchLevel
;
132 tmpKey
.setKey(keySet
[tmpLevel
], tmpLevel
);
136 } catch (Exception e
) {
137 throw new EdkException(e
.getMessage());
140 result
= map
.get(tmpKey
);
141 if (result
!= null) {
142 map
.put(key
, result
);
149 map
.put(key
, result
);
157 public Set
<ToolChainKey
> keySet() {
158 return (Set
<ToolChainKey
>)map
.keySet();
161 // public String toString() {
162 // return map.toString();