new search method for finding references like other references.
authorjprocter <Jim Procter>
Fri, 13 Jul 2007 14:55:21 +0000 (14:55 +0000)
committerjprocter <Jim Procter>
Fri, 13 Jul 2007 14:55:21 +0000 (14:55 +0000)
src/jalview/util/DBRefUtils.java

index 3ea47f2..f016fe6 100755 (executable)
@@ -127,4 +127,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;
+  }
 }