Support prebuild and postbuild for UserExtension for Platform build. If UserExtension...
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / toolchain / ToolChainKey.java
CommitLineData
a29c47e0 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13 ToolChainKey.java\r
14\r
15Abstract:\r
16\r
17--*/\r
18\r
19package org.tianocore.build.toolchain;\r
20\r
136adffc 21import org.tianocore.exception.EdkException;\r
a29c47e0 22\r
23public class ToolChainKey implements java.io.Serializable, Comparable<ToolChainKey> {\r
a84091c4 24 static final long serialVersionUID = -8034897190740066933L;\r
a29c47e0 25 private String delimiter = "_";\r
26\r
27 public final static int keyLength = 5;\r
28\r
29 private String[] keySet = null;\r
30\r
31 private String keyString = null;\r
32\r
33 private int hashValue = 0;\r
34\r
35 public ToolChainKey(String keyString, String delimiter) throws Exception {\r
36 setKey(keyString, delimiter);\r
37 }\r
38\r
39 public ToolChainKey(String keyString) throws EdkException {\r
40 setKey(keyString);\r
41 }\r
42\r
43 public ToolChainKey(String[] keySet) throws EdkException {\r
44 setKey(keySet);\r
45 }\r
46\r
47 public int hashCode() {\r
48 if (hashValue != 0) {\r
49 return hashValue;\r
50 }\r
51\r
52 for (int i = 0; i < keySet.length; ++i) {\r
53 char[] keyStringValue = new char[keySet[i].length()];\r
54 this.keySet[i].getChars(0, keyStringValue.length, keyStringValue, 0);\r
55\r
56 for (int j = 0; j < keyStringValue.length; ++j) {\r
57 hashValue = keyStringValue[j] + hashValue * 31;\r
58 }\r
59 }\r
60\r
61 return hashValue;\r
62 }\r
63\r
64 public int compareTo(ToolChainKey dstKey) {\r
65 String[] dstKeySet = dstKey.getKeySet();\r
66 int result = 0;\r
67 for (int i = 0; i < this.keyLength; ++i) {\r
68 result = this.keySet[i].compareToIgnoreCase(dstKeySet[i]);\r
69 if (result != 0) {\r
70 break;\r
71 }\r
72 }\r
73\r
74 return result;\r
75 }\r
76\r
77 public boolean equals(Object o) {\r
78 ToolChainKey dstKey = (ToolChainKey)o;\r
79 String[] dstKeySet = dstKey.getKeySet();\r
80\r
81 if (this == dstKey) {\r
82 return true;\r
83 }\r
84\r
85 if (dstKeySet.length != this.keyLength) {\r
86 return false;\r
87 }\r
88\r
89 for (int i = 0; i < this.keyLength; ++i) {\r
90 if (!this.keySet[i].equalsIgnoreCase(dstKeySet[i])) {\r
91 return false;\r
92 }\r
93 }\r
94\r
95 return true;\r
96 }\r
97\r
98 public void setKey(String[] keySet) throws EdkException {\r
99 if (keySet.length != this.keyLength) {\r
100 throw new EdkException("Invalid ToolChain key");\r
101 }\r
102\r
103 this.keySet = new String[this.keyLength];\r
104 System.arraycopy(keySet, 0, this.keySet, 0, this.keyLength);\r
105 for (int i = 0; i < this.keyLength; ++i) {\r
106 if (this.keySet[i] == null || this.keySet[i].length() == 0) {\r
107 this.keySet[i] = "*";\r
108 }\r
109 }\r
110 this.keyString = null;\r
111 this.hashValue = 0;\r
112 }\r
113\r
114 public void setKey(String keySetString, int index) throws EdkException {\r
115 if (index >= this.keyLength) {\r
116 throw new EdkException("Invalid ToolChain key index");\r
117 }\r
118\r
119 if (keySetString == null || keySetString.length() == 0) {\r
120 keySetString = "*";\r
121 }\r
122 this.keySet[index] = keySetString;\r
123 this.keyString = null;\r
124 this.hashValue = 0;\r
125 }\r
126\r
127 public void setKey(String keyString) throws EdkException {\r
128 this.keySet = keyString.split(this.delimiter);\r
129\r
130 if (this.keySet.length != this.keyLength) {\r
131 throw new EdkException("Invalid ToolChain key");\r
132 }\r
133\r
134 this.keyString = keyString;\r
135 this.hashValue = 0;\r
136 }\r
137\r
138 public void setKey(String keyString, String delimiter) throws Exception {\r
139 this.keySet = keyString.split(delimiter);\r
140\r
141 if (this.keySet.length != this.keyLength) {\r
142 throw new Exception("Invalid ToolChain key");\r
143 }\r
144\r
145 this.keyString = keyString;\r
146 this.delimiter = delimiter;\r
147 this.hashValue = 0;\r
148 }\r
149\r
150 public String[] getKeySet() {\r
151 return keySet;\r
152 }\r
153\r
154 public String toString() {\r
155 if (this.keyString == null) {\r
156 StringBuffer keyStringBuf = new StringBuffer(64);\r
157 int i = 0;\r
158\r
159 keyStringBuf.append(this.keySet[i++]);\r
160 for (; i < this.keyLength; ++i) {\r
161 keyStringBuf.append(this.delimiter);\r
162 keyStringBuf.append(this.keySet[i]);\r
163 }\r
164\r
165 this.keyString = keyStringBuf.toString();\r
166 }\r
167\r
168 return this.keyString;\r
169 }\r
170}\r
171\r