+++ /dev/null
-/** @file\r
-ToolChainKey class\r
-\r
-ToolChainKey class is representing the "name" part of tool chain definition.\r
-\r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-package org.tianocore.build.toolchain;\r
-\r
-import org.tianocore.build.exception.GenBuildException;\r
-\r
-/**\r
- ToolChainKey class is the java class form of the "name" of tool chain definition.\r
- It's primarily for the key of a Map data structure.\r
- **/\r
-public class ToolChainKey implements java.io.Serializable, Comparable<ToolChainKey> {\r
- static final long serialVersionUID = -8034897190740066933L;\r
-\r
- ///\r
- /// The part number of key. Currently we only support fixed five parts.\r
- /// \r
- public final static int keyLength = 5;\r
-\r
- //\r
- // Default delimiter which is used for concatenating the parts of key\r
- // \r
- private String delimiter = "_";\r
-\r
- //\r
- // Key value in string array form\r
- // \r
- private String[] keySet = null;\r
-\r
- //\r
- // Key value in one string form\r
- // \r
- private String keyString = null;\r
-\r
- //\r
- // Key hash value used for hash table \r
- // \r
- private int hashValue = 0;\r
-\r
- /**\r
- Public constructor which can override default delimiter.\r
-\r
- @param keyString The key string value\r
- @param delimiter Delimiter charater concatenating the key parts\r
- **/\r
- public ToolChainKey(String keyString, String delimiter) throws GenBuildException {\r
- setKey(keyString, delimiter);\r
- }\r
-\r
- /**\r
- Public constructor which uses default delimiter.\r
-\r
- @param keyString The key string value\r
- **/\r
- public ToolChainKey(String keyString) throws GenBuildException {\r
- setKey(keyString);\r
- }\r
-\r
- /**\r
- Public constructor which doesn't use any delimiter.\r
-\r
- @param keySet\r
- **/\r
- public ToolChainKey(String[] keySet) throws GenBuildException {\r
- setKey(keySet);\r
- }\r
-\r
- /**\r
- Calculate hash value of the key string (without the delimiter). It's used\r
- for Hash Table kind of Map.\r
-\r
- @return int The hash value\r
- **/\r
- public int hashCode() {\r
- if (hashValue != 0) {\r
- return hashValue;\r
- }\r
-\r
- for (int i = 0; i < keySet.length; ++i) {\r
- char[] keyStringValue = new char[keySet[i].length()];\r
- this.keySet[i].getChars(0, keyStringValue.length, keyStringValue, 0);\r
-\r
- for (int j = 0; j < keyStringValue.length; ++j) {\r
- hashValue = keyStringValue[j] + hashValue * 31;\r
- }\r
- }\r
-\r
- return hashValue;\r
- }\r
-\r
- /**\r
- Compare the string value of two keys . It's used for Tree kind of Map.\r
- \r
- @param dstKey Another key to compare to.\r
- \r
- @retval 0 Two keys are equal\r
- @retval >0 This key is after the given key\r
- @retval <0 This key is before the given key\r
- **/\r
- public int compareTo(ToolChainKey dstKey) {\r
- String[] dstKeySet = dstKey.getKeySet();\r
- int result = 0;\r
- for (int i = 0; i < ToolChainKey.keyLength; ++i) {\r
- result = this.keySet[i].compareToIgnoreCase(dstKeySet[i]);\r
- if (result != 0) {\r
- break;\r
- }\r
- }\r
-\r
- return result;\r
- }\r
-\r
- /**\r
- Check if this key is the same as the given key.\r
-\r
- @param o Another key to compare to\r
- \r
- @return boolean\r
- **/\r
- public boolean equals(Object o) {\r
- ToolChainKey dstKey = (ToolChainKey)o;\r
- String[] dstKeySet = dstKey.getKeySet();\r
-\r
- if (this == dstKey) {\r
- return true;\r
- }\r
-\r
- if (dstKeySet.length != ToolChainKey.keyLength) {\r
- return false;\r
- }\r
-\r
- for (int i = 0; i < ToolChainKey.keyLength; ++i) {\r
- if (!this.keySet[i].equalsIgnoreCase(dstKeySet[i])) {\r
- return false;\r
- }\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- Set the key value in form of string array.\r
-\r
- @param keySet The string array of key value\r
- **/\r
- public void setKey(String[] keySet) throws GenBuildException {\r
- if (keySet.length != ToolChainKey.keyLength) {\r
- throw new GenBuildException("Invalid ToolChain key");\r
- }\r
-\r
- //\r
- // Clone the string array because we don't want to change original one\r
- // \r
- this.keySet = new String[ToolChainKey.keyLength];\r
- System.arraycopy(keySet, 0, this.keySet, 0, ToolChainKey.keyLength);\r
- for (int i = 0; i < ToolChainKey.keyLength; ++i) {\r
- if (this.keySet[i] == null || this.keySet[i].length() == 0) {\r
- this.keySet[i] = "*";\r
- }\r
- }\r
-\r
- //\r
- // We need to re-generate the single key string and hash value.\r
- // \r
- this.keyString = null;\r
- this.hashValue = 0;\r
- }\r
-\r
- /**\r
- Set key value at the specified key part .\r
- \r
- @param keySetString The new value of "index" part of key\r
- @param index The key part index\r
- **/\r
- public void setKey(String keySetString, int index) throws GenBuildException {\r
- if (index >= ToolChainKey.keyLength) {\r
- throw new GenBuildException("Invalid ToolChain key index");\r
- }\r
-\r
- //\r
- // Allow wildcard in key string\r
- // \r
- if (keySetString == null || keySetString.length() == 0) {\r
- keySetString = "*";\r
- }\r
- this.keySet[index] = keySetString;\r
-\r
- //\r
- // We need to re-generate the single key string and hash value.\r
- // \r
- this.keyString = null;\r
- this.hashValue = 0;\r
- }\r
-\r
- /**\r
- Set key value in the form of single string.\r
- \r
- @param keyString The key value string\r
- **/\r
- public void setKey(String keyString) throws GenBuildException {\r
- this.keySet = keyString.split(this.delimiter);\r
-\r
- if (this.keySet.length != ToolChainKey.keyLength) {\r
- throw new GenBuildException("Invalid ToolChain key");\r
- }\r
-\r
- this.keyString = keyString;\r
- //\r
- // We need to re-generate hash value.\r
- // \r
- this.hashValue = 0;\r
- }\r
-\r
- /**\r
- Set key value in the form of single string with specified delimiter.\r
- \r
- @param keyString The key value string\r
- @param delimiter The delimiter concatenating the key string\r
- **/\r
- public void setKey(String keyString, String delimiter) throws GenBuildException {\r
- this.keySet = keyString.split(delimiter);\r
-\r
- if (this.keySet.length != ToolChainKey.keyLength) {\r
- throw new GenBuildException("Invalid ToolChain key");\r
- }\r
-\r
- this.keyString = keyString;\r
- this.delimiter = delimiter;\r
- //\r
- // We need to re-generate hash value.\r
- // \r
- this.hashValue = 0;\r
- }\r
-\r
- /**\r
- Return the string array form of key\r
-\r
- @return String[]\r
- **/\r
- public String[] getKeySet() {\r
- return keySet;\r
- }\r
-\r
- /**\r
- Return the single string form of key.\r
-\r
- @return String\r
- **/\r
- public String toString() {\r
- if (this.keyString == null) {\r
- StringBuffer keyStringBuf = new StringBuffer(64);\r
-\r
- keyStringBuf.append(this.keySet[0]);\r
- for (int i = 1; i < ToolChainKey.keyLength; ++i) {\r
- keyStringBuf.append(this.delimiter);\r
- keyStringBuf.append(this.keySet[i]);\r
- }\r
-\r
- this.keyString = keyStringBuf.toString();\r
- }\r
-\r
- return this.keyString;\r
- }\r
-}\r
-\r