methods for searching DBRef lists
authorjprocter <Jim Procter>
Tue, 14 Mar 2006 11:22:04 +0000 (11:22 +0000)
committerjprocter <Jim Procter>
Tue, 14 Mar 2006 11:22:04 +0000 (11:22 +0000)
src/jalview/util/DBRefUtils.java [new file with mode: 0755]

diff --git a/src/jalview/util/DBRefUtils.java b/src/jalview/util/DBRefUtils.java
new file mode 100755 (executable)
index 0000000..86ab201
--- /dev/null
@@ -0,0 +1,32 @@
+package jalview.util;
+
+import java.util.Vector;
+import java.util.Hashtable;
+
+public class DBRefUtils
+{
+    /**
+     * Utilities for handling DBRef objects and their collections.
+     */
+    public static Vector selectRefs(java.util.Vector dbrefs, String[] sources) {
+      if (dbrefs==null)
+        return null;
+      if (sources==null)
+        return dbrefs;
+      Hashtable srcs = new Hashtable();
+      Vector res=new Vector();
+      for (int i=0; i<sources.length; i++)
+        srcs.put(new String(sources[i]), new Integer(i));
+      for (int i=0, j=dbrefs.size(); i<j; i++)
+        if (dbrefs.get(i) instanceof jalview.datamodel.DBRefEntry) {
+          jalview.datamodel.DBRefEntry entry = (jalview.datamodel.DBRefEntry) dbrefs.get(i);
+          if (srcs.containsKey(entry.getSource()))
+            res.add(entry);
+        }
+      if (res.size()>0)
+        return res;
+      res = null;
+      // there are probable  memory leaks in the hashtable!
+      return null;
+    }
+  }