86ab201843b94a6509d9ffd877e3d4247b375f50
[jalview.git] / src / jalview / util / DBRefUtils.java
1 package jalview.util;
2
3 import java.util.Vector;
4 import java.util.Hashtable;
5
6 public class DBRefUtils
7 {
8     /**
9      * Utilities for handling DBRef objects and their collections.
10      */
11     public static Vector selectRefs(java.util.Vector dbrefs, String[] sources) {
12       if (dbrefs==null)
13         return null;
14       if (sources==null)
15         return dbrefs;
16       Hashtable srcs = new Hashtable();
17       Vector res=new Vector();
18       for (int i=0; i<sources.length; i++)
19         srcs.put(new String(sources[i]), new Integer(i));
20       for (int i=0, j=dbrefs.size(); i<j; i++)
21         if (dbrefs.get(i) instanceof jalview.datamodel.DBRefEntry) {
22           jalview.datamodel.DBRefEntry entry = (jalview.datamodel.DBRefEntry) dbrefs.get(i);
23           if (srcs.containsKey(entry.getSource()))
24             res.add(entry);
25         }
26       if (res.size()>0)
27         return res;
28       res = null;
29       // there are probable  memory leaks in the hashtable!
30       return null;
31     }
32   }