]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainKey.java
Added comments and polished the code.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / toolchain / ToolChainKey.java
index f71fe3a3335f8c97d72844569a2ef86d3d0cb636..765d6f913cb772442b82e5a9ab57b3ffae7d2c3d 100644 (file)
@@ -1,4 +1,7 @@
-/*++\r
+/** @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
@@ -9,36 +12,78 @@ http://opensource.org/licenses/bsd-license.php
 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
 \r
 package org.tianocore.build.toolchain;\r
 \r
 import org.tianocore.common.exception.EdkException;\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
-    private String delimiter = "_";\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
-    public ToolChainKey(String keyString, String delimiter) throws Exception {\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 EdkException {\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 EdkException {\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 EdkException {\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
@@ -56,6 +101,15 @@ public class ToolChainKey implements java.io.Serializable, Comparable<ToolChainK
         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
@@ -69,6 +123,13 @@ public class ToolChainKey implements java.io.Serializable, Comparable<ToolChainK
         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
@@ -90,11 +151,19 @@ public class ToolChainKey implements java.io.Serializable, Comparable<ToolChainK
         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 EdkException {\r
         if (keySet.length != this.keyLength) {\r
             throw new EdkException("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[this.keyLength];\r
         System.arraycopy(keySet, 0, this.keySet, 0, this.keyLength);\r
         for (int i = 0; i < this.keyLength; ++i) {\r
@@ -102,23 +171,45 @@ public class ToolChainKey implements java.io.Serializable, Comparable<ToolChainK
                 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 EdkException {\r
         if (index >= this.keyLength) {\r
             throw new EdkException("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 EdkException {\r
         this.keySet = keyString.split(this.delimiter);\r
 \r
@@ -127,32 +218,53 @@ public class ToolChainKey implements java.io.Serializable, Comparable<ToolChainK
         }\r
 \r
         this.keyString = keyString;\r
+        //\r
+        // We need to re-generate hash value.\r
+        // \r
         this.hashValue = 0;\r
     }\r
 \r
-    public void setKey(String keyString, String delimiter) throws Exception {\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 EdkException {\r
         this.keySet = keyString.split(delimiter);\r
 \r
         if (this.keySet.length != this.keyLength) {\r
-            throw new Exception("Invalid ToolChain key");\r
+            throw new EdkException("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
-            int i = 0;\r
 \r
-            keyStringBuf.append(this.keySet[i++]);\r
-            for (; i < this.keyLength; ++i) {\r
+            keyStringBuf.append(this.keySet[0]);\r
+            for (int i = 1; i < this.keyLength; ++i) {\r
                 keyStringBuf.append(this.delimiter);\r
                 keyStringBuf.append(this.keySet[i]);\r
             }\r