X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Frest%2FInputType.java;h=c83879afba682bbf442539e03f9b25181c913862;hb=f37c3fd4fe12799de498de5f397252e9f457fee9;hp=20476328ef1bf7cbf0d43ff4d718bfd4edf31b50;hpb=865a855a4ca87eadb3e5ff284ed32ed307d9c34b;p=jalview.git diff --git a/src/jalview/ws/rest/InputType.java b/src/jalview/ws/rest/InputType.java index 2047632..c83879a 100644 --- a/src/jalview/ws/rest/InputType.java +++ b/src/jalview/ws/rest/InputType.java @@ -1,19 +1,21 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.ws.rest; @@ -28,7 +30,6 @@ import jalview.ws.params.simple.Option; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -44,6 +45,9 @@ import org.apache.http.entity.mime.content.StringBody; */ public abstract class InputType { + private static final Pattern URL_PATTERN = Pattern + .compile("^([^=]+)=?'?([^']*)?'?"); + /** * not used yet */ @@ -53,9 +57,9 @@ public abstract class InputType { NUC, PROT, MIX; - public static Collection toStringValues() + public static List toStringValues() { - Collection c = new ArrayList(); + List c = new ArrayList<>(); for (molType type : values()) { c.add(type.toString()); @@ -70,7 +74,7 @@ public abstract class InputType public int max = 0; // unbounded - protected ArrayList inputData = new ArrayList(); + protected List inputData = new ArrayList<>(); /** * initialise the InputType with a list of jalview data classes that the @@ -99,7 +103,9 @@ public abstract class InputType public boolean validFor(RestJob restJob) { if (!validFor(restJob.rsd)) + { return false; + } for (Class cl : inputData) { if (!restJob.hasDataOfType(cl)) @@ -113,7 +119,9 @@ public abstract class InputType public boolean validFor(RestServiceDescription restServiceDescription) { if (!restServiceDescription.inputParams.values().contains(this)) + { return false; + } return true; } @@ -125,13 +133,13 @@ public abstract class InputType { if (type == null) { - return new StringBody(utf8.encode(content).asCharBuffer() - .toString()); + return new StringBody( + utf8.encode(content).asCharBuffer().toString()); } else { - return new StringBody(utf8.encode(content).asCharBuffer() - .toString(), type, utf8); + return new StringBody( + utf8.encode(content).asCharBuffer().toString(), type, utf8); } } catch (Exception ex) { @@ -207,7 +215,7 @@ public abstract class InputType boolean valid = true; for (String tok : tokenstring) { - Matcher mtch = Pattern.compile("^([^=]+)=?'?([^']*)?'?").matcher(tok); + Matcher mtch = URL_PATTERN.matcher(tok); if (mtch.find()) { try @@ -265,7 +273,7 @@ public abstract class InputType public List getBaseOptions() { - ArrayList opts = new ArrayList(); + ArrayList opts = new ArrayList<>(); opts.add(new IntegerParameter("min", "Minimum number of data of this type", true, 1, min, 0, -1)); opts.add(new IntegerParameter("max", @@ -290,7 +298,7 @@ public abstract class InputType public void configureFromArgumentI(List currentSettings) throws InvalidArgumentException { - ArrayList urltoks = new ArrayList(); + List urltoks = new ArrayList<>(); String rg; for (ArgumentI arg : currentSettings) { @@ -302,9 +310,10 @@ public abstract class InputType { // TODO: revise architecture - this is counter intuitive - options with // different values to their names are actually parameters - rg = (arg.getValue().length() > 0) ? (arg.getValue().equals( - arg.getName()) ? arg.getName() : arg.getName() + "='" - + arg.getValue() + "'") : arg.getName(); + rg = (arg.getValue().length() > 0) + ? (arg.getValue().equals(arg.getName()) ? arg.getName() + : arg.getName() + "='" + arg.getValue() + "'") + : arg.getName(); } if (rg.length() > 0) { @@ -312,7 +321,8 @@ public abstract class InputType } } StringBuffer warnings; - if (!configureFromURLtokenString(urltoks, warnings = new StringBuffer())) + if (!configureFromURLtokenString(urltoks, + warnings = new StringBuffer())) { throw new InvalidArgumentException(warnings.toString()); } @@ -321,8 +331,8 @@ public abstract class InputType protected OptionI createMolTypeOption(String name, String descr, boolean req, molType curType, molType defType) { - return new Option(name, descr, req, defType == null ? "" - : defType.toString(), + return new Option(name, descr, req, + defType == null ? "" : defType.toString(), curType == null ? "" : curType.toString(), molType.toStringValues(), null); }