JAL-3210 Improvements to eclipse detection. New src tree and SwingJS updated from...
[jalview.git] / src / jalview / util / DBRefUtils.java
index fb54bba..197261a 100755 (executable)
@@ -32,7 +32,6 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import com.stevesoft.pat.Regex;
 
@@ -96,14 +95,14 @@ public class DBRefUtils
        }
 
        // BH TODO (what?)
-       HashSet<String> srcs = new HashSet<String>();
+       HashSet<String> srcs = new HashSet<>();
        for (String src : sources) 
        {
          srcs.add(src.toUpperCase());
        }
 
        int nrefs = dbrefs.size();
-       List<DBRefEntry> res = new ArrayList<DBRefEntry>();
+       List<DBRefEntry> res = new ArrayList<>();
        for (int ib = 0; ib < nrefs; ib++) 
        {
          DBRefEntry dbr = dbrefs.get(ib);
@@ -217,7 +216,7 @@ public class DBRefUtils
         * @return
         */
        public static List<DBRefEntry> searchRefs(List<DBRefEntry> refs, String accId) {
-               List<DBRefEntry> rfs = new ArrayList<DBRefEntry>();
+               List<DBRefEntry> rfs = new ArrayList<>();
                if (refs == null || accId == null) {
                        return rfs;
                }
@@ -243,7 +242,7 @@ public class DBRefUtils
         * @return
         */
        static List<DBRefEntry> searchRefs(List<DBRefEntry> refs, DBRefEntry entry, DbRefComp comparator, int mode) {
-               List<DBRefEntry> rfs = new ArrayList<DBRefEntry>();
+               List<DBRefEntry> rfs = new ArrayList<>();
                if (refs == null || entry == null) {
                        return rfs;
                }
@@ -450,6 +449,14 @@ public class DBRefUtils
     return matches;
   }
 
+  private static Regex PARSE_REGEX;
+
+  private static Regex getParseRegex()
+  {
+    return (PARSE_REGEX == null ? PARSE_REGEX = Platform.newRegex(
+            "([0-9][0-9A-Za-z]{3})\\s*(.?)\\s*;\\s*([0-9]+)-([0-9]+)", null)
+            : PARSE_REGEX);
+  }
        /**
         * Parses a DBRefEntry and adds it to the sequence, also a PDBEntry if the
         * database is PDB.
@@ -471,7 +478,7 @@ public class DBRefUtils
                                /*
                                 * Check for PFAM style stockhom PDB accession id citation e.g. "1WRI A; 7-80;"
                                 */
-                               Regex r = new com.stevesoft.pat.Regex("([0-9][0-9A-Za-z]{3})\\s*(.?)\\s*;\\s*([0-9]+)-([0-9]+)");
+        Regex r = getParseRegex();
                                if (r.search(acn.trim())) {
                                        String pdbid = r.stringMatched(1);
                                        String chaincode = r.stringMatched(2);
@@ -558,7 +565,7 @@ public class DBRefUtils
         * @return
         */
        public static List<DBRefEntry> searchRefsForSource(List<DBRefEntry> dbRefs, String source) {
-               List<DBRefEntry> matches = new ArrayList<DBRefEntry>();
+               List<DBRefEntry> matches = new ArrayList<>();
                if (dbRefs != null && source != null) {
                        for (DBRefEntry dbref : dbRefs) {
                                if (source.equalsIgnoreCase(dbref.getSource())) {
@@ -621,7 +628,9 @@ public class DBRefUtils
                bsSelect.set(0, dbrefs.size());
 
                if (!selectRefsBS(dbrefs, isProtein ? DBRefSource.PROTEIN_MASK : DBRefSource.DNA_CODING_MASK, bsSelect))
-                       return;
+    {
+      return;
+    }
 
 //      selfs.addAll(selfArray);
 //    }
@@ -631,7 +640,9 @@ public class DBRefUtils
                        DBRefEntry p = pr.get(ip);
                        for (int i = bsSelect.nextSetBit(0); i >= 0; i = bsSelect.nextSetBit(i + 1)) {
                                if (dbrefs.get(i) == p)
-                                       bsSelect.clear(i);
+        {
+          bsSelect.clear(i);
+        }
                        }
 //      while (selfs.contains(p))
 //      {
@@ -655,7 +666,9 @@ public class DBRefUtils
                                // TODO: promote transcript refs ??
                        }
                        if (keys == 0 || !selectRefsBS(dbrefs, keys, bsSelect))
-                               return;
+      {
+        return;
+      }
 //      if (candidates != null)
                        {
                                for (int ic = bsSelect.nextSetBit(0); ic >= 0; ic = bsSelect.nextSetBit(ic + 1))