JAL-2089 patch broken merge to master for Release 2.10.0b1
[jalview.git] / src / jalview / analysis / SequenceIdMatcher.java
index 8351686..c12de4e 100755 (executable)
@@ -46,7 +46,7 @@ public class SequenceIdMatcher
   }
 
   /**
-   * add more sequences to this matcher - also used by the constructor
+   * Adds sequences to this matcher
    * 
    * @param seqs
    */
@@ -54,26 +54,36 @@ public class SequenceIdMatcher
   {
     for (SequenceI seq : seqs)
     {
-      // TODO: deal with ID collisions - SequenceI should be appended to list
-      // associated with this key.
-      names.put(new SeqIdName(seq.getDisplayId(true)), seq);
-      SequenceI dbseq = seq;
-      while (dbseq.getDatasetSequence() != null)
-      {
-        dbseq = dbseq.getDatasetSequence();
-      }
-      // add in any interesting identifiers
-      if (dbseq.getDBRefs() != null)
+      add(seq);
+    }
+  }
+
+  /**
+   * Adds one sequence to this matcher
+   * 
+   * @param seq
+   */
+  public void add(SequenceI seq)
+  {
+    // TODO: deal with ID collisions - SequenceI should be appended to list
+    // associated with this key.
+    names.put(new SeqIdName(seq.getDisplayId(true)), seq);
+    SequenceI dbseq = seq;
+    while (dbseq.getDatasetSequence() != null)
+    {
+      dbseq = dbseq.getDatasetSequence();
+    }
+    // add in any interesting identifiers
+    if (dbseq.getDBRefs() != null)
+    {
+      DBRefEntry dbr[] = dbseq.getDBRefs();
+      SeqIdName sid = null;
+      for (int r = 0; r < dbr.length; r++)
       {
-        DBRefEntry dbr[] = dbseq.getDBRefs();
-        SeqIdName sid = null;
-        for (int r = 0; r < dbr.length; r++)
+        sid = new SeqIdName(dbr[r].getAccessionId());
+        if (!names.containsKey(sid))
         {
-          sid = new SeqIdName(dbr[r].getAccessionId());
-          if (!names.containsKey(sid))
-          {
-            names.put(sid, seq);
-          }
+          names.put(sid, seq);
         }
       }
     }
@@ -280,7 +290,7 @@ public class SequenceIdMatcher
     {
       if (s != null)
       {
-        id = new String(s);
+        id = s.toLowerCase();
       }
       else
       {
@@ -304,13 +314,13 @@ public class SequenceIdMatcher
       }
       if (s instanceof SeqIdName)
       {
-        return this.equals((SeqIdName) s);
+        return this.stringequals(((SeqIdName) s).id);
       }
       else
       {
         if (s instanceof String)
         {
-          return this.equals((String) s);
+          return this.stringequals(((String) s).toLowerCase());
         }
       }
 
@@ -332,26 +342,9 @@ public class SequenceIdMatcher
      * todo: (JBPNote) Set separator characters appropriately
      * 
      * @param s
-     *          SeqIdName
      * @return boolean
      */
-    public boolean equals(SeqIdName s)
-    {
-      // TODO: JAL-732 patch for cases when name includes a list of IDs, and the
-      // match contains one ID flanked
-      if (id.length() > s.id.length())
-      {
-        return id.startsWith(s.id) ? (WORD_SEP.indexOf(id.charAt(s.id
-                .length())) > -1) : false;
-      }
-      else
-      {
-        return s.id.startsWith(id) ? (s.id.equals(id) ? true : (WORD_SEP
-                .indexOf(s.id.charAt(id.length())) > -1)) : false;
-      }
-    }
-
-    public boolean equals(String s)
+    private boolean stringequals(String s)
     {
       if (id.length() > s.length())
       {
@@ -364,5 +357,15 @@ public class SequenceIdMatcher
                 .indexOf(s.charAt(id.length())) > -1)) : false;
       }
     }
+
+    /**
+     * toString method returns the wrapped sequence id. For debugging purposes
+     * only, behaviour not guaranteed not to change.
+     */
+    @Override
+    public String toString()
+    {
+      return id;
+    }
   }
 }