JAL-2738 copy to spikes/mungo
[jalview.git] / src / jalview / ws / rest / RestServiceDescription.java
index e7c861f..5533406 100644 (file)
  */
 package jalview.ws.rest;
 
+import jalview.datamodel.SequenceI;
+import jalview.io.packed.DataProvider.JvDataType;
+import jalview.util.StringUtils;
+import jalview.ws.rest.params.Alignment;
+import jalview.ws.rest.params.AnnotationFile;
+import jalview.ws.rest.params.SeqGroupIndexVector;
+
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -31,16 +38,10 @@ import java.util.StringTokenizer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import jalview.datamodel.SequenceI;
-import jalview.io.packed.DataProvider.JvDataType;
-import jalview.util.StringUtils;
-import jalview.ws.rest.params.Alignment;
-import jalview.ws.rest.params.AnnotationFile;
-import jalview.ws.rest.params.SeqGroupIndexVector;
-
 public class RestServiceDescription
 {
-  private static final Pattern PARAM_ENCODED_URL_PATTERN = Pattern.compile("([?&])([A-Za-z0-9_]+)=\\$([^$]+)\\$");
+  private static final Pattern PARAM_ENCODED_URL_PATTERN = Pattern
+          .compile("([?&])([A-Za-z0-9_]+)=\\$([^$]+)\\$");
 
   /**
    * create a new rest service description ready to be configured
@@ -91,8 +92,9 @@ public class RestServiceDescription
     boolean diff = (gapCharacter != other.gapCharacter);
     diff |= vseparable != other.vseparable;
     diff |= hseparable != other.hseparable;
-    diff |= !(urlSuffix == null && other.urlSuffix == null || (urlSuffix != null
-            && other.urlSuffix != null && urlSuffix.equals(other.urlSuffix)));
+    diff |= !(urlSuffix == null && other.urlSuffix == null
+            || (urlSuffix != null && other.urlSuffix != null
+                    && urlSuffix.equals(other.urlSuffix)));
     // TODO - robust diff that includes constants and reordering of URL
     // diff |= !(postUrl.equals(other.postUrl));
     // diff |= !inputParams.equals(other.inputParams);
@@ -461,8 +463,8 @@ public class RestServiceDescription
         resultData.add(JvDataType.valueOf(tok = st.nextToken()));
       } catch (NoSuchElementException x)
       {
-        warnings.append("Invalid result type: '" + tok
-                + "' (must be one of: ");
+        warnings.append(
+                "Invalid result type: '" + tok + "' (must be one of: ");
         String sep = "";
         for (JvDataType vl : JvDataType.values())
         {
@@ -490,7 +492,8 @@ public class RestServiceDescription
     ;
     vls.add(new String("gapCharacter='" + gapCharacter + "'"));
     vls.add(new String("returns='" + _genOutputFormatString() + "'"));
-    return StringUtils.arrayToSeparatorList(vls.toArray(new String[0]), ",");
+    return StringUtils.arrayToSeparatorList(vls.toArray(new String[0]),
+            ",");
   }
 
   public String toString()
@@ -555,7 +558,8 @@ public class RestServiceDescription
    * @param p
    * @return
    */
-  protected int parseServiceList(String[] list, StringBuffer warnings, int p)
+  protected int parseServiceList(String[] list, StringBuffer warnings,
+          int p)
   {
     boolean invalid = false;
     // look for the first non-empty position - expect it to be service name
@@ -580,7 +584,8 @@ public class RestServiceDescription
               && list[p + 4].trim().length() > 5)
       {
         urlSuffix = null;
-        invalid |= !configureFromInputParamEncodedUrl(list[p + 4], warnings);
+        invalid |= !configureFromInputParamEncodedUrl(list[p + 4],
+                warnings);
         p += 5;
       }
     }
@@ -634,8 +639,8 @@ public class RestServiceDescription
             url.append("$");
             url.append(param.getValue().getURLtokenPrefix());
             url.append(":");
-            url.append(StringUtils.arrayToSeparatorList(vals.toArray(new String[0]),
-                    ","));
+            url.append(StringUtils.arrayToSeparatorList(
+                    vals.toArray(new String[0]), ","));
             url.append("$");
           }
         }
@@ -661,8 +666,7 @@ public class RestServiceDescription
     boolean valid = true;
     int lastp = 0;
     String url = new String();
-    Matcher prms = PARAM_ENCODED_URL_PATTERN
-            .matcher(ipurl);
+    Matcher prms = PARAM_ENCODED_URL_PATTERN.matcher(ipurl);
     Map<String, InputType> iparams = new Hashtable<String, InputType>();
     InputType jinput;
     while (prms.find())
@@ -682,8 +686,8 @@ public class RestServiceDescription
         iprmparams = iprm.substring(colon + 1);
         iprm = iprm.substring(0, colon);
       }
-      valid = parseTypeString(prms.group(0), tok, iprm, iprmparams,
-              iparams, warnings);
+      valid = parseTypeString(prms.group(0), tok, iprm, iprmparams, iparams,
+              warnings);
     }
     if (valid)
     {
@@ -704,11 +708,9 @@ public class RestServiceDescription
   public static Class[] getInputTypes()
   {
     // TODO - find a better way of maintaining this classlist
-    return new Class[]
-    { jalview.ws.rest.params.Alignment.class,
+    return new Class[] { jalview.ws.rest.params.Alignment.class,
         jalview.ws.rest.params.AnnotationFile.class,
-        SeqGroupIndexVector.class,
-        jalview.ws.rest.params.SeqIdVector.class,
+        SeqGroupIndexVector.class, jalview.ws.rest.params.SeqIdVector.class,
         jalview.ws.rest.params.SeqVector.class,
         jalview.ws.rest.params.Tree.class };
   }
@@ -727,7 +729,8 @@ public class RestServiceDescription
         if (iprm.equalsIgnoreCase(jinput.getURLtokenPrefix()))
         {
           ArrayList<String> al = new ArrayList<String>();
-          for (String prprm : StringUtils.separatorListToArray(iprmparams, ","))
+          for (String prprm : StringUtils.separatorListToArray(iprmparams,
+                  ","))
           {
             // hack to ensure that strings like "sep=','" containing unescaped
             // commas as values are concatenated
@@ -800,7 +803,8 @@ public class RestServiceDescription
   /**
    * search the input types for an instance of the given class
    * 
-   * @param <validInput.inputType> class1
+   * @param <validInput.inputType>
+   *          class1
    * @return
    */
   public boolean inputInvolves(Class<?> class1)