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.
14 package org
.tianocore
.build
.toolchain
;
16 import org
.tianocore
.common
.exception
.EdkException
;
18 public class ToolChainKey
implements java
.io
.Serializable
, Comparable
<ToolChainKey
> {
19 static final long serialVersionUID
= -8034897190740066933L;
20 private String delimiter
= "_";
22 public final static int keyLength
= 5;
24 private String
[] keySet
= null;
26 private String keyString
= null;
28 private int hashValue
= 0;
30 public ToolChainKey(String keyString
, String delimiter
) throws Exception
{
31 setKey(keyString
, delimiter
);
34 public ToolChainKey(String keyString
) throws EdkException
{
38 public ToolChainKey(String
[] keySet
) throws EdkException
{
42 public int hashCode() {
47 for (int i
= 0; i
< keySet
.length
; ++i
) {
48 char[] keyStringValue
= new char[keySet
[i
].length()];
49 this.keySet
[i
].getChars(0, keyStringValue
.length
, keyStringValue
, 0);
51 for (int j
= 0; j
< keyStringValue
.length
; ++j
) {
52 hashValue
= keyStringValue
[j
] + hashValue
* 31;
59 public int compareTo(ToolChainKey dstKey
) {
60 String
[] dstKeySet
= dstKey
.getKeySet();
62 for (int i
= 0; i
< this.keyLength
; ++i
) {
63 result
= this.keySet
[i
].compareToIgnoreCase(dstKeySet
[i
]);
72 public boolean equals(Object o
) {
73 ToolChainKey dstKey
= (ToolChainKey
)o
;
74 String
[] dstKeySet
= dstKey
.getKeySet();
80 if (dstKeySet
.length
!= this.keyLength
) {
84 for (int i
= 0; i
< this.keyLength
; ++i
) {
85 if (!this.keySet
[i
].equalsIgnoreCase(dstKeySet
[i
])) {
93 public void setKey(String
[] keySet
) throws EdkException
{
94 if (keySet
.length
!= this.keyLength
) {
95 throw new EdkException("Invalid ToolChain key");
98 this.keySet
= new String
[this.keyLength
];
99 System
.arraycopy(keySet
, 0, this.keySet
, 0, this.keyLength
);
100 for (int i
= 0; i
< this.keyLength
; ++i
) {
101 if (this.keySet
[i
] == null || this.keySet
[i
].length() == 0) {
102 this.keySet
[i
] = "*";
105 this.keyString
= null;
109 public void setKey(String keySetString
, int index
) throws EdkException
{
110 if (index
>= this.keyLength
) {
111 throw new EdkException("Invalid ToolChain key index");
114 if (keySetString
== null || keySetString
.length() == 0) {
117 this.keySet
[index
] = keySetString
;
118 this.keyString
= null;
122 public void setKey(String keyString
) throws EdkException
{
123 this.keySet
= keyString
.split(this.delimiter
);
125 if (this.keySet
.length
!= this.keyLength
) {
126 throw new EdkException("Invalid ToolChain key");
129 this.keyString
= keyString
;
133 public void setKey(String keyString
, String delimiter
) throws Exception
{
134 this.keySet
= keyString
.split(delimiter
);
136 if (this.keySet
.length
!= this.keyLength
) {
137 throw new Exception("Invalid ToolChain key");
140 this.keyString
= keyString
;
141 this.delimiter
= delimiter
;
145 public String
[] getKeySet() {
149 public String
toString() {
150 if (this.keyString
== null) {
151 StringBuffer keyStringBuf
= new StringBuffer(64);
154 keyStringBuf
.append(this.keySet
[i
++]);
155 for (; i
< this.keyLength
; ++i
) {
156 keyStringBuf
.append(this.delimiter
);
157 keyStringBuf
.append(this.keySet
[i
]);
160 this.keyString
= keyStringBuf
.toString();
163 return this.keyString
;