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
.io
.Serializable
;
22 import java
.util
.AbstractMap
;
23 import java
.util
.HashMap
;
25 import java
.util
.TreeMap
;
27 import org
.tianocore
.exception
.EdkException
;
29 public class ToolChainKey
implements java
.io
.Serializable
, Comparable
<ToolChainKey
> {
30 static final long serialVersionUID
= -8034897190740066933L;
31 private String delimiter
= "_";
33 public final static int keyLength
= 5;
35 private String
[] keySet
= null;
37 private String keyString
= null;
39 private int hashValue
= 0;
41 public ToolChainKey(String keyString
, String delimiter
) throws Exception
{
42 setKey(keyString
, delimiter
);
45 public ToolChainKey(String keyString
) throws EdkException
{
49 public ToolChainKey(String
[] keySet
) throws EdkException
{
53 public int hashCode() {
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);
62 for (int j
= 0; j
< keyStringValue
.length
; ++j
) {
63 hashValue
= keyStringValue
[j
] + hashValue
* 31;
70 public int compareTo(ToolChainKey dstKey
) {
71 String
[] dstKeySet
= dstKey
.getKeySet();
73 for (int i
= 0; i
< this.keyLength
; ++i
) {
74 result
= this.keySet
[i
].compareToIgnoreCase(dstKeySet
[i
]);
83 public boolean equals(Object o
) {
84 ToolChainKey dstKey
= (ToolChainKey
)o
;
85 String
[] dstKeySet
= dstKey
.getKeySet();
91 if (dstKeySet
.length
!= this.keyLength
) {
95 for (int i
= 0; i
< this.keyLength
; ++i
) {
96 if (!this.keySet
[i
].equalsIgnoreCase(dstKeySet
[i
])) {
104 public void setKey(String
[] keySet
) throws EdkException
{
105 if (keySet
.length
!= this.keyLength
) {
106 throw new EdkException("Invalid ToolChain key");
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
] = "*";
116 this.keyString
= null;
120 public void setKey(String keySetString
, int index
) throws EdkException
{
121 if (index
>= this.keyLength
) {
122 throw new EdkException("Invalid ToolChain key index");
125 if (keySetString
== null || keySetString
.length() == 0) {
128 this.keySet
[index
] = keySetString
;
129 this.keyString
= null;
133 public void setKey(String keyString
) throws EdkException
{
134 this.keySet
= keyString
.split(this.delimiter
);
136 if (this.keySet
.length
!= this.keyLength
) {
137 throw new EdkException("Invalid ToolChain key");
140 this.keyString
= keyString
;
144 public void setKey(String keyString
, String delimiter
) throws Exception
{
145 this.keySet
= keyString
.split(delimiter
);
147 if (this.keySet
.length
!= this.keyLength
) {
148 throw new Exception("Invalid ToolChain key");
151 this.keyString
= keyString
;
152 this.delimiter
= delimiter
;
156 public String
[] getKeySet() {
160 public String
toString() {
161 if (this.keyString
== null) {
162 StringBuffer keyStringBuf
= new StringBuffer(64);
165 keyStringBuf
.append(this.keySet
[i
++]);
166 for (; i
< this.keyLength
; ++i
) {
167 keyStringBuf
.append(this.delimiter
);
168 keyStringBuf
.append(this.keySet
[i
]);
171 this.keyString
= keyStringBuf
.toString();
174 return this.keyString
;