JAL-1705 type enum can encapsulate the corresponding url parameter value
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 9 Nov 2015 14:50:16 +0000 (14:50 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 9 Nov 2015 14:50:16 +0000 (14:50 +0000)
src/jalview/ext/ensembl/SeqFetcher.java

index 9258558..7c913bf 100644 (file)
@@ -10,7 +10,7 @@ import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
-import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.http.NameValuePair;
@@ -18,7 +18,7 @@ import org.apache.http.message.BasicNameValuePair;
 
 public class SeqFetcher
 {
-  private static String ensemblRest = "rest.ensembl.org";
+  private final static String ENSEMBL_REST = "rest.ensembl.org";
 
   private static boolean ensemblRestavailable = false;
 
@@ -80,7 +80,7 @@ public class SeqFetcher
     }
     try
     {
-      URL ping = new URL("http://" + ensemblRest + "/info/ping");
+      URL ping = new URL("http://" + ENSEMBL_REST + "/info/ping");
       HttpURLConnection conn = (HttpURLConnection) (ping.openConnection());
       if (conn.getResponseCode() >= 200 && conn.getResponseCode() < 300)
       {
@@ -99,13 +99,24 @@ public class SeqFetcher
 
   public SeqFetcher()
   {
-
-    // TODO Auto-generated constructor stub
   }
 
   public enum EnsemblSeqType
   {
-    GENOMIC, CDS, TRANSCRIPT, PROTEIN, CDNA;
+    GENOMIC("genomic"), CDS("cds"), TRANSCRIPT("cds"), PROTEIN("protein"), CDNA(
+            "cdna");
+
+    private String type;
+
+    EnsemblSeqType(String t)
+    {
+      type = t;
+    }
+
+    public String getType()
+    {
+      return type;
+    }
   }
 
   /**
@@ -115,27 +126,8 @@ public class SeqFetcher
    */
   public List<NameValuePair> getObjectTypeArg(EnsemblSeqType type)
   {
-    String arg;
-    switch (type)
-    {
-    case CDS:
-      arg = "cds";
-      break;
-    case TRANSCRIPT:
-      arg = "cds";
-      break;
-    case CDNA:
-      arg = "cdna";
-      break;
-    case PROTEIN:
-      arg = "protein";
-      break;
-    case GENOMIC:
-    default:
-      arg = "genomic";
-    }
-    return Arrays.asList(new NameValuePair[]
-    { new BasicNameValuePair("type", arg) });
+    NameValuePair nameValue = new BasicNameValuePair("type", type.getType());
+    return Collections.singletonList(nameValue);
   }
 
   /**
@@ -152,7 +144,7 @@ public class SeqFetcher
 
     // adapted From the rest.ensembl.org documentation for sequence_id
 
-    String urls = "http://" + ensemblRest + "/sequence/id";
+    String urls = "http://" + ENSEMBL_REST + "/sequence/id";
     List<NameValuePair> vals = getObjectTypeArg(returnType);
     boolean f = true;
     for (NameValuePair nvp : vals)