From 414bdec32b25f6b2282902dbbf16ca138c13df37 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 9 Nov 2015 14:50:16 +0000 Subject: [PATCH] JAL-1705 type enum can encapsulate the corresponding url parameter value --- src/jalview/ext/ensembl/SeqFetcher.java | 48 +++++++++++++------------------ 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/src/jalview/ext/ensembl/SeqFetcher.java b/src/jalview/ext/ensembl/SeqFetcher.java index 9258558..7c913bf 100644 --- a/src/jalview/ext/ensembl/SeqFetcher.java +++ b/src/jalview/ext/ensembl/SeqFetcher.java @@ -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 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 vals = getObjectTypeArg(returnType); boolean f = true; for (NameValuePair nvp : vals) -- 1.7.10.2