JAL-3210 Improvements to eclipse detection. New src tree and SwingJS updated from...
[jalview.git] / src / jalview / io / RnamlFile.java
index eb623d3..d5a8d81 100644 (file)
@@ -26,6 +26,7 @@ import jalview.datamodel.Annotation;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
 import jalview.util.MessageManager;
+import jalview.util.Platform;
 
 import java.io.BufferedReader;
 import java.io.FileNotFoundException;
@@ -103,35 +104,35 @@ public class RnamlFile extends AlignFile
     } catch (ExceptionPermissionDenied pdx)
     {
       errormessage = MessageManager.formatMessage(
-              "exception.rnaml_couldnt_access_datasource",
-              new String[] { pdx.getMessage() });
+              "exception.rnaml_couldnt_access_datasource", new String[]
+              { pdx.getMessage() });
       throw new IOException(pdx);
     } catch (ExceptionLoadingFailed lf)
     {
       errormessage = MessageManager.formatMessage(
-              "exception.ranml_couldnt_process_data",
-              new String[] { lf.getMessage() });
+              "exception.ranml_couldnt_process_data", new String[]
+              { lf.getMessage() });
       throw new IOException(lf);
     } catch (ExceptionFileFormatOrSyntax iff)
     {
-      errormessage = MessageManager.formatMessage(
-              "exception.ranml_invalid_file",
-              new String[] { iff.getMessage() });
+      errormessage = MessageManager
+              .formatMessage("exception.ranml_invalid_file", new String[]
+              { iff.getMessage() });
       throw new IOException(iff);
     } catch (Exception x)
     {
       error = true;
       errormessage = MessageManager.formatMessage(
-              "exception.ranml_problem_parsing_data",
-              new String[] { x.getMessage() });
+              "exception.ranml_problem_parsing_data", new String[]
+              { x.getMessage() });
       throw new IOException(errormessage, x);
     }
   }
 
   @SuppressWarnings("unchecked")
-  public void _parse() throws FileNotFoundException,
-          ExceptionPermissionDenied, ExceptionLoadingFailed,
-          ExceptionFileFormatOrSyntax
+  public void _parse()
+          throws FileNotFoundException, ExceptionPermissionDenied,
+          ExceptionLoadingFailed, ExceptionFileFormatOrSyntax
   {
 
     result = RNAFactory.loadSecStrRNAML(getReader());
@@ -172,15 +173,16 @@ public class RnamlFile extends AlignFile
       }
       for (int k = 0; k < rna.length(); k++)
       {
-        ann[k] = new Annotation(annot[k], "", Rna.getRNASecStrucState(
-                annot[k]).charAt(0), 0f);
+        ann[k] = new Annotation(annot[k], "",
+                Rna.getRNASecStrucState(annot[k]).charAt(0), 0f);
       }
 
       AlignmentAnnotation align = new AlignmentAnnotation(
               "Secondary Structure",
-              current.getID().trim().length() > 0 ? "Secondary Structure for "
-                      + current.getID()
-                      : "", ann);
+              current.getID().trim().length() > 0
+                      ? "Secondary Structure for " + current.getID()
+                      : "",
+              ann);
 
       sqs[i].addAlignmentAnnotation(align);
       sqs[i].setRNA(result.get(i));
@@ -226,7 +228,7 @@ public class RnamlFile extends AlignFile
       dataName = dataName.substring(0, b - 1);
     }
     b = 0;
-    Regex m = new Regex("[\\/]?([-A-Za-z0-9]+)\\.?");
+    Regex m = getSafeRegex();
     String mm = dataName;
     while (m.searchFrom(dataName, b))
     {
@@ -235,4 +237,13 @@ public class RnamlFile extends AlignFile
     }
     return mm;
   }
+
+  private static Regex SAFE_REGEX;
+
+  private static Regex getSafeRegex()
+  {
+    return (SAFE_REGEX == null
+            ? SAFE_REGEX = Platform.newRegex("[\\/]?([-A-Za-z0-9]+)\\.?", null)
+            : SAFE_REGEX);
+  }
 }