test cc change revoked.
[jalview.git] / src / jalview / util / DBRefUtils.java
index 81710dd..3e0004e 100755 (executable)
@@ -54,7 +54,7 @@ public class DBRefUtils
     {
       if (srcs.containsKey(dbrefs[i].getSource()))
       {
-        res.add(dbrefs[i]);
+        res.addElement(dbrefs[i]);
       }
     }
 
@@ -117,6 +117,7 @@ public class DBRefUtils
     if (CanonicalSourceNameLookup==null) {
       CanonicalSourceNameLookup = new Hashtable();
       CanonicalSourceNameLookup.put("uniprotkb/swiss-prot", jalview.datamodel.DBRefSource.UNIPROT);
+      CanonicalSourceNameLookup.put("uniprotkb/trembl", jalview.datamodel.DBRefSource.UNIPROT);
       CanonicalSourceNameLookup.put("pdb", jalview.datamodel.DBRefSource.PDB);
     }
     String canonical = (String) CanonicalSourceNameLookup.get(source.
@@ -127,4 +128,41 @@ public class DBRefUtils
     }
     return canonical;
   }
+  /**
+   * find RefEntry corresponding to a particular pattern
+   * the equals method of each entry is used, from String attributes right down to Mapping attributes.
+   * @param ref Set of references to search
+   * @param entry pattern to collect - null any entry for wildcard match
+   * @return
+   */
+  public static DBRefEntry[] searchRefs(DBRefEntry[] ref, DBRefEntry entry)
+  {
+    if (ref==null || entry==null)
+      return null;
+    Vector rfs = new Vector();
+    for (int i=0; i<ref.length;i++)
+    {
+      if (entry.getSource()==null || ref[i].getSource().equals(entry.getSource()))
+      {
+        if (entry.getVersion()==null || ref[i].getVersion().equals(entry.getVersion()))
+        {
+          if (entry.getAccessionId()==null || ref[i].getAccessionId().equals(entry.getAccessionId()))
+          {
+            if (entry.getMap()==null || (ref[i].getMap()!=null && ref[i].getMap().equals(entry.getMap())))
+            {
+              rfs.addElement(ref[i]);
+            }
+          }
+        }
+      }
+    }
+    // TODO Auto-generated method stub
+    if (rfs.size()>0)
+    {
+      DBRefEntry[] rf = new DBRefEntry[rfs.size()];
+      rfs.copyInto(rf);
+      return rf;
+    }
+    return null;
+  }
 }