]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Java/Source/GenBuild/org/tianocore/build/toolchain/ToolChainKey.java
1. Update to just keep several line JAVA related msg; 2. Remove file PropertyManager...
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / toolchain / ToolChainKey.java
... / ...
CommitLineData
1/** @file\r
2ToolChainKey class\r
3\r
4ToolChainKey class is representing the "name" part of tool chain definition.\r
5\r
6Copyright (c) 2006, Intel Corporation\r
7All rights reserved. This program and the accompanying materials\r
8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17package org.tianocore.build.toolchain;\r
18\r
19import org.tianocore.build.exception.GenBuildException;\r
20\r
21/**\r
22 ToolChainKey class is the java class form of the "name" of tool chain definition.\r
23 It's primarily for the key of a Map data structure.\r
24 **/\r
25public class ToolChainKey implements java.io.Serializable, Comparable<ToolChainKey> {\r
26 static final long serialVersionUID = -8034897190740066933L;\r
27\r
28 ///\r
29 /// The part number of key. Currently we only support fixed five parts.\r
30 /// \r
31 public final static int keyLength = 5;\r
32\r
33 //\r
34 // Default delimiter which is used for concatenating the parts of key\r
35 // \r
36 private String delimiter = "_";\r
37\r
38 //\r
39 // Key value in string array form\r
40 // \r
41 private String[] keySet = null;\r
42\r
43 //\r
44 // Key value in one string form\r
45 // \r
46 private String keyString = null;\r
47\r
48 //\r
49 // Key hash value used for hash table \r
50 // \r
51 private int hashValue = 0;\r
52\r
53 /**\r
54 Public constructor which can override default delimiter.\r
55\r
56 @param keyString The key string value\r
57 @param delimiter Delimiter charater concatenating the key parts\r
58 **/\r
59 public ToolChainKey(String keyString, String delimiter) throws GenBuildException {\r
60 setKey(keyString, delimiter);\r
61 }\r
62\r
63 /**\r
64 Public constructor which uses default delimiter.\r
65\r
66 @param keyString The key string value\r
67 **/\r
68 public ToolChainKey(String keyString) throws GenBuildException {\r
69 setKey(keyString);\r
70 }\r
71\r
72 /**\r
73 Public constructor which doesn't use any delimiter.\r
74\r
75 @param keySet\r
76 **/\r
77 public ToolChainKey(String[] keySet) throws GenBuildException {\r
78 setKey(keySet);\r
79 }\r
80\r
81 /**\r
82 Calculate hash value of the key string (without the delimiter). It's used\r
83 for Hash Table kind of Map.\r
84\r
85 @return int The hash value\r
86 **/\r
87 public int hashCode() {\r
88 if (hashValue != 0) {\r
89 return hashValue;\r
90 }\r
91\r
92 for (int i = 0; i < keySet.length; ++i) {\r
93 char[] keyStringValue = new char[keySet[i].length()];\r
94 this.keySet[i].getChars(0, keyStringValue.length, keyStringValue, 0);\r
95\r
96 for (int j = 0; j < keyStringValue.length; ++j) {\r
97 hashValue = keyStringValue[j] + hashValue * 31;\r
98 }\r
99 }\r
100\r
101 return hashValue;\r
102 }\r
103\r
104 /**\r
105 Compare the string value of two keys . It's used for Tree kind of Map.\r
106 \r
107 @param dstKey Another key to compare to.\r
108 \r
109 @retval 0 Two keys are equal\r
110 @retval >0 This key is after the given key\r
111 @retval <0 This key is before the given key\r
112 **/\r
113 public int compareTo(ToolChainKey dstKey) {\r
114 String[] dstKeySet = dstKey.getKeySet();\r
115 int result = 0;\r
116 for (int i = 0; i < ToolChainKey.keyLength; ++i) {\r
117 result = this.keySet[i].compareToIgnoreCase(dstKeySet[i]);\r
118 if (result != 0) {\r
119 break;\r
120 }\r
121 }\r
122\r
123 return result;\r
124 }\r
125\r
126 /**\r
127 Check if this key is the same as the given key.\r
128\r
129 @param o Another key to compare to\r
130 \r
131 @return boolean\r
132 **/\r
133 public boolean equals(Object o) {\r
134 ToolChainKey dstKey = (ToolChainKey)o;\r
135 String[] dstKeySet = dstKey.getKeySet();\r
136\r
137 if (this == dstKey) {\r
138 return true;\r
139 }\r
140\r
141 if (dstKeySet.length != ToolChainKey.keyLength) {\r
142 return false;\r
143 }\r
144\r
145 for (int i = 0; i < ToolChainKey.keyLength; ++i) {\r
146 if (!this.keySet[i].equalsIgnoreCase(dstKeySet[i])) {\r
147 return false;\r
148 }\r
149 }\r
150\r
151 return true;\r
152 }\r
153\r
154 /**\r
155 Set the key value in form of string array.\r
156\r
157 @param keySet The string array of key value\r
158 **/\r
159 public void setKey(String[] keySet) throws GenBuildException {\r
160 if (keySet.length != ToolChainKey.keyLength) {\r
161 throw new GenBuildException("Invalid ToolChain key");\r
162 }\r
163\r
164 //\r
165 // Clone the string array because we don't want to change original one\r
166 // \r
167 this.keySet = new String[ToolChainKey.keyLength];\r
168 System.arraycopy(keySet, 0, this.keySet, 0, ToolChainKey.keyLength);\r
169 for (int i = 0; i < ToolChainKey.keyLength; ++i) {\r
170 if (this.keySet[i] == null || this.keySet[i].length() == 0) {\r
171 this.keySet[i] = "*";\r
172 }\r
173 }\r
174\r
175 //\r
176 // We need to re-generate the single key string and hash value.\r
177 // \r
178 this.keyString = null;\r
179 this.hashValue = 0;\r
180 }\r
181\r
182 /**\r
183 Set key value at the specified key part .\r
184 \r
185 @param keySetString The new value of "index" part of key\r
186 @param index The key part index\r
187 **/\r
188 public void setKey(String keySetString, int index) throws GenBuildException {\r
189 if (index >= ToolChainKey.keyLength) {\r
190 throw new GenBuildException("Invalid ToolChain key index");\r
191 }\r
192\r
193 //\r
194 // Allow wildcard in key string\r
195 // \r
196 if (keySetString == null || keySetString.length() == 0) {\r
197 keySetString = "*";\r
198 }\r
199 this.keySet[index] = keySetString;\r
200\r
201 //\r
202 // We need to re-generate the single key string and hash value.\r
203 // \r
204 this.keyString = null;\r
205 this.hashValue = 0;\r
206 }\r
207\r
208 /**\r
209 Set key value in the form of single string.\r
210 \r
211 @param keyString The key value string\r
212 **/\r
213 public void setKey(String keyString) throws GenBuildException {\r
214 this.keySet = keyString.split(this.delimiter);\r
215\r
216 if (this.keySet.length != ToolChainKey.keyLength) {\r
217 throw new GenBuildException("Invalid ToolChain key");\r
218 }\r
219\r
220 this.keyString = keyString;\r
221 //\r
222 // We need to re-generate hash value.\r
223 // \r
224 this.hashValue = 0;\r
225 }\r
226\r
227 /**\r
228 Set key value in the form of single string with specified delimiter.\r
229 \r
230 @param keyString The key value string\r
231 @param delimiter The delimiter concatenating the key string\r
232 **/\r
233 public void setKey(String keyString, String delimiter) throws GenBuildException {\r
234 this.keySet = keyString.split(delimiter);\r
235\r
236 if (this.keySet.length != ToolChainKey.keyLength) {\r
237 throw new GenBuildException("Invalid ToolChain key");\r
238 }\r
239\r
240 this.keyString = keyString;\r
241 this.delimiter = delimiter;\r
242 //\r
243 // We need to re-generate hash value.\r
244 // \r
245 this.hashValue = 0;\r
246 }\r
247\r
248 /**\r
249 Return the string array form of key\r
250\r
251 @return String[]\r
252 **/\r
253 public String[] getKeySet() {\r
254 return keySet;\r
255 }\r
256\r
257 /**\r
258 Return the single string form of key.\r
259\r
260 @return String\r
261 **/\r
262 public String toString() {\r
263 if (this.keyString == null) {\r
264 StringBuffer keyStringBuf = new StringBuffer(64);\r
265\r
266 keyStringBuf.append(this.keySet[0]);\r
267 for (int i = 1; i < ToolChainKey.keyLength; ++i) {\r
268 keyStringBuf.append(this.delimiter);\r
269 keyStringBuf.append(this.keySet[i]);\r
270 }\r
271\r
272 this.keyString = keyStringBuf.toString();\r
273 }\r
274\r
275 return this.keyString;\r
276 }\r
277}\r
278\r