From: Jim Procter Date: Tue, 18 Jun 2013 20:38:16 +0000 (+0100) Subject: JAL-1320 sort options and parameters according to their name X-Git-Tag: Jalview_2_9~236^2~2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=3737b35aa75cf9ba9203a244de45008fb0794bc4;p=jalview.git JAL-1320 sort options and parameters according to their name --- diff --git a/src/jalview/ws/jws2/JabaParamStore.java b/src/jalview/ws/jws2/JabaParamStore.java index 204e0df..ec504dd 100644 --- a/src/jalview/ws/jws2/JabaParamStore.java +++ b/src/jalview/ws/jws2/JabaParamStore.java @@ -19,10 +19,12 @@ package jalview.ws.jws2; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Hashtable; import java.util.List; import java.util.StringTokenizer; +import org.jmol.util.ArrayUtil; import compbio.metadata.Argument; import compbio.metadata.Option; import compbio.metadata.Parameter; @@ -137,12 +139,28 @@ public class JabaParamStore implements ParamDatastoreI public static List getJwsArgsfromJaba(List jabargs) { + return getJwsArgsfromJaba(jabargs, true); + } + + public static List getJwsArgsfromJaba(List jabargs, + boolean sortByOpt) + { List rgs = new ArrayList(); + List rgnames = new ArrayList(); for (Object rg : jabargs) { - ArgumentI narg = (rg instanceof Parameter) ? new JabaParameter( - (Parameter) rg) : (rg instanceof Option) ? new JabaOption( - (Option) rg) : null; + ArgumentI narg = null; + String nargstring = null; + if (rg instanceof Parameter) + { + narg = new JabaParameter((Parameter) rg); + nargstring = narg.getName(); // just sort by name for this + } + else if (rg instanceof Option) + { + narg = new JabaOption((Option) rg); + nargstring = (String) ((Option) rg).getOptionNames().get(0); + } if (narg == null) { throw new Error( @@ -152,9 +170,17 @@ public class JabaParamStore implements ParamDatastoreI else { rgs.add(narg); + rgnames.add(nargstring); } } - return rgs; + if (!sortByOpt) + { + return rgs; + } + ArgumentI[] rgssort = rgs.toArray(new ArgumentI[rgs.size()]); + String[] rgssorton = rgnames.toArray(new String[rgs.size()]); + jalview.util.QuickSort.sort(rgssorton, rgssort); + return Arrays.asList(rgssort); } public static List getJabafromJwsArgs(List jwsargs)