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