JAL-1705 regular expression updates, tests, other refactoring
[jalview.git] / src / jalview / ext / ensembl / EnsemblRestClient.java
index 215eb7a..297f71b 100644 (file)
@@ -14,6 +14,8 @@ import java.util.List;
 
 import javax.ws.rs.HttpMethod;
 
+import com.stevesoft.pat.Regex;
+
 /**
  * Base class for Ensembl REST service clients
  * 
@@ -31,12 +33,28 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher
 
   private final static long RETEST_INTERVAL = 10000L; // 10 seconds
 
+  private static final Regex TRANSCRIPT_REGEX = new Regex(
+            "(ENS)([A-Z]{3}|)T[0-9]{11}$");
+
+  private static final Regex GENE_REGEX = new Regex(
+            "(ENS)([A-Z]{3}|)G[0-9]{11}$");
+
   private static boolean ensemblRestAvailable = false;
 
   private static long lastCheck = -1;
 
   protected volatile boolean inProgress = false;
 
+  public static boolean isTranscriptIdentifier(String query)
+  {
+    return query == null ? false : TRANSCRIPT_REGEX.search(query);
+  }
+
+  public static boolean isGeneIdentifier(String query)
+  {
+    return query == null ? false : GENE_REGEX.search(query);
+  }
+
   @Override
   public boolean queryInProgress()
   {