Support prebuild and postbuild for UserExtension for Platform build. If UserExtension...
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / toolchain / ToolChainKey.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 ToolChainKey.java
14
15 Abstract:
16
17 --*/
18
19 package org.tianocore.build.toolchain;
20
21 import org.tianocore.exception.EdkException;
22
23 public class ToolChainKey implements java.io.Serializable, Comparable<ToolChainKey> {
24 static final long serialVersionUID = -8034897190740066933L;
25 private String delimiter = "_";
26
27 public final static int keyLength = 5;
28
29 private String[] keySet = null;
30
31 private String keyString = null;
32
33 private int hashValue = 0;
34
35 public ToolChainKey(String keyString, String delimiter) throws Exception {
36 setKey(keyString, delimiter);
37 }
38
39 public ToolChainKey(String keyString) throws EdkException {
40 setKey(keyString);
41 }
42
43 public ToolChainKey(String[] keySet) throws EdkException {
44 setKey(keySet);
45 }
46
47 public int hashCode() {
48 if (hashValue != 0) {
49 return hashValue;
50 }
51
52 for (int i = 0; i < keySet.length; ++i) {
53 char[] keyStringValue = new char[keySet[i].length()];
54 this.keySet[i].getChars(0, keyStringValue.length, keyStringValue, 0);
55
56 for (int j = 0; j < keyStringValue.length; ++j) {
57 hashValue = keyStringValue[j] + hashValue * 31;
58 }
59 }
60
61 return hashValue;
62 }
63
64 public int compareTo(ToolChainKey dstKey) {
65 String[] dstKeySet = dstKey.getKeySet();
66 int result = 0;
67 for (int i = 0; i < this.keyLength; ++i) {
68 result = this.keySet[i].compareToIgnoreCase(dstKeySet[i]);
69 if (result != 0) {
70 break;
71 }
72 }
73
74 return result;
75 }
76
77 public boolean equals(Object o) {
78 ToolChainKey dstKey = (ToolChainKey)o;
79 String[] dstKeySet = dstKey.getKeySet();
80
81 if (this == dstKey) {
82 return true;
83 }
84
85 if (dstKeySet.length != this.keyLength) {
86 return false;
87 }
88
89 for (int i = 0; i < this.keyLength; ++i) {
90 if (!this.keySet[i].equalsIgnoreCase(dstKeySet[i])) {
91 return false;
92 }
93 }
94
95 return true;
96 }
97
98 public void setKey(String[] keySet) throws EdkException {
99 if (keySet.length != this.keyLength) {
100 throw new EdkException("Invalid ToolChain key");
101 }
102
103 this.keySet = new String[this.keyLength];
104 System.arraycopy(keySet, 0, this.keySet, 0, this.keyLength);
105 for (int i = 0; i < this.keyLength; ++i) {
106 if (this.keySet[i] == null || this.keySet[i].length() == 0) {
107 this.keySet[i] = "*";
108 }
109 }
110 this.keyString = null;
111 this.hashValue = 0;
112 }
113
114 public void setKey(String keySetString, int index) throws EdkException {
115 if (index >= this.keyLength) {
116 throw new EdkException("Invalid ToolChain key index");
117 }
118
119 if (keySetString == null || keySetString.length() == 0) {
120 keySetString = "*";
121 }
122 this.keySet[index] = keySetString;
123 this.keyString = null;
124 this.hashValue = 0;
125 }
126
127 public void setKey(String keyString) throws EdkException {
128 this.keySet = keyString.split(this.delimiter);
129
130 if (this.keySet.length != this.keyLength) {
131 throw new EdkException("Invalid ToolChain key");
132 }
133
134 this.keyString = keyString;
135 this.hashValue = 0;
136 }
137
138 public void setKey(String keyString, String delimiter) throws Exception {
139 this.keySet = keyString.split(delimiter);
140
141 if (this.keySet.length != this.keyLength) {
142 throw new Exception("Invalid ToolChain key");
143 }
144
145 this.keyString = keyString;
146 this.delimiter = delimiter;
147 this.hashValue = 0;
148 }
149
150 public String[] getKeySet() {
151 return keySet;
152 }
153
154 public String toString() {
155 if (this.keyString == null) {
156 StringBuffer keyStringBuf = new StringBuffer(64);
157 int i = 0;
158
159 keyStringBuf.append(this.keySet[i++]);
160 for (; i < this.keyLength; ++i) {
161 keyStringBuf.append(this.delimiter);
162 keyStringBuf.append(this.keySet[i]);
163 }
164
165 this.keyString = keyStringBuf.toString();
166 }
167
168 return this.keyString;
169 }
170 }
171