Fixed basic name to sequence ID matching (bug http://dragonfly.compbio.dundee.ac...
authorjprocter <Jim Procter>
Wed, 17 Aug 2005 15:20:10 +0000 (15:20 +0000)
committerjprocter <Jim Procter>
Wed, 17 Aug 2005 15:20:10 +0000 (15:20 +0000)
and improved code robustness when dealing with badly formed IDs (null strings).

src/jalview/analysis/SequenceIdMatcher.java

index b88a03f..f4f305b 100755 (executable)
@@ -115,12 +115,15 @@ public class SequenceIdMatcher
 \r
     SeqIdName(String s)\r
     {\r
-      id = new String(s);\r
+      if (s!=null)\r
+        id = new String(s);\r
+      else\r
+        id = "";\r
     }\r
 \r
     public int hashCode()\r
     {\r
-      return (id.substring(0, 4).hashCode());\r
+      return ((id.length()>=4) ? id.substring(0, 4).hashCode() : id.hashCode());\r
     }\r
 \r
     public boolean equals(Object s)\r
@@ -141,20 +144,28 @@ public class SequenceIdMatcher
     }\r
 \r
     /**\r
-     * matches if one ID properly contains another at a whitespace boundary.\r
-     * TODO: (JBPNote) These are not efficient. should use char[] for speed\r
-     * @param s SeqIdName\r
-     * @return boolean\r
+     * Characters that define the end of a unique sequence ID at\r
+     * the beginning of an arbitrary ID string\r
      */\r
+    private String WORD_SEP="~. |#\\/<>!\"£$%^*)}[@',?";\r
+\r
+   /**\r
+    * matches if one ID properly contains another at a whitespace boundary.\r
+    * TODO: (JBPNote) These are not efficient. should use char[] for speed\r
+    * todo: (JBPNote) Set separator characters appropriately\r
+    * @param s SeqIdName\r
+    * @return boolean\r
+    */\r
     public boolean equals(SeqIdName s)\r
     {\r
       if (id.length()>s.id.length()) {\r
         return id.startsWith(s.id) ?\r
-            (id.equals(s.id) ? true : id.startsWith(s.id+" "))\r
+            (WORD_SEP.indexOf(id.charAt(s.id.length()))>-1)\r
             : false;\r
       } else\r
         return s.id.startsWith(id) ?\r
-            (s.id.equals(id) ? true : s.id.startsWith(id+" "))\r
+            (s.id.equals(id) ? true :\r
+             (WORD_SEP.indexOf(s.id.charAt(id.length()))>-1))\r
             : false;\r
     }\r
 \r
@@ -162,11 +173,12 @@ public class SequenceIdMatcher
     {\r
       if (id.length()>s.length()) {\r
         return id.startsWith(s) ?\r
-            (id.equals(s) ? true : id.startsWith(s+" "))\r
+            (WORD_SEP.indexOf(id.charAt(s.length()))>-1)\r
             : false;\r
       } else\r
         return s.startsWith(id) ?\r
-            (s.equals(id) ? true : s.startsWith(id+" "))\r
+            (s.equals(id) ? true :\r
+             (WORD_SEP.indexOf(s.charAt(id.length()))>-1))\r
             : false;\r
     }\r
   }\r