Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.bin

File ArgsParser.java

 

Coverage histogram

../../img/srcFileCovDistChart8.png
20% of files have more coverage

Code metrics

20
33
8
1
215
124
20
0.61
4.12
8
2.5

Classes

Class Line # Actions
ArgsParser 38 33 20
0.7377049373.8%
 

Contributing tests

This file is covered by 62 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.bin;
22   
23    import jalview.util.Platform;
24   
25    import java.net.URLDecoder;
26    import java.util.ArrayList;
27    import java.util.List;
28   
29    /**
30    * Notes: this argParser does not distinguish between parameter switches,
31    * parameter values and argument text. If an argument happens to be identical to
32    * a parameter, it will be taken as such (even though it didn't have a '-'
33    * prefixing it).
34    *
35    * @author Andrew Waterhouse and JBP documented.
36    *
37    */
 
38    public class ArgsParser
39    {
40   
41    // BH 2019 - new
42   
43    public static final String NOCALCULATION = "nocalculation";
44   
45    public static final String NOMENUBAR = "nomenubar";
46   
47    public static final String NOSTATUS = "nostatus";
48   
49    public static final String SHOWOVERVIEW = "showoverview";
50   
51    //
52    public static final String ANNOTATIONS = "annotations";
53   
54    public static final String COLOUR = "colour";
55   
56    public static final String FEATURES = "features";
57   
58    public static final String GROOVY = "groovy";
59   
60    public static final String GROUPS = "groups";
61   
62    public static final String HEADLESS = "headless";
63   
64    public static final String JABAWS = "jabaws";
65   
66    public static final String NOANNOTATION = "no-annotation";
67   
68    public static final String NOANNOTATION2 = "noannotation"; // BH 2019.05.07
69   
70    public static final String NODISPLAY = "nodisplay";
71   
72    public static final String NOGUI = "nogui";
73   
74    public static final String NONEWS = "nonews";
75   
76    public static final String NOQUESTIONNAIRE = "noquestionnaire";
77   
78    public static final String NOSORTBYTREE = "nosortbytree";
79   
80    public static final String NOUSAGESTATS = "nousagestats";
81   
82    public static final String OPEN = "open";
83   
84    public static final String OPEN2 = "open2"; // BH added -- for applet
85    // compatibility; not fully
86    // implemented
87   
88    public static final String PROPS = "props";
89   
90    public static final String QUESTIONNAIRE = "questionnaire";
91   
92    public static final String SETPROP = "setprop";
93   
94    public static final String SORTBYTREE = "sortbytree";
95   
96    public static final String TREE = "tree";
97   
98    public static final String VDOC = "vdoc";
99   
100    public static final String VSESS = "vsess";
101   
102    private List<String> vargs = null;
103   
104    private boolean isApplet;
105   
106    private AppletParams appletParams;
107   
 
108  0 toggle public boolean isApplet()
109    {
110  0 return isApplet;
111    }
112   
 
113  142 toggle public ArgsParser(String[] args)
114    {
115  142 vargs = new ArrayList<>();
116  142 isApplet = (args.length > 0 && args[0].startsWith("<applet"));
117  142 if (isApplet)
118    {
119  0 appletParams = AppletParams.getAppletParams(args, vargs);
120    }
121    else
122    {
123  142 if (Platform.isJS())
124   
125    {
126  0 isApplet = true;
127  0 appletParams = AppletParams
128    .getAppletParams(Platform.getAppletInfoAsMap(), vargs);
129    }
130  930 for (int i = 0; i < args.length; i++)
131    {
132  788 String arg = args[i].trim();
133  788 if (arg.charAt(0) == '-')
134    {
135  628 arg = arg.substring(1);
136    }
137  788 vargs.add(arg);
138    }
139    }
140    }
141   
142    /**
143    * check for and remove first occurence of arg+parameter in arglist.
144    *
145    * @param arg
146    * @return return the argument following the given arg if arg was in list.
147    */
 
148  454 toggle public String getValue(String arg)
149    {
150  454 return getValue(arg, false);
151    }
152   
 
153  777 toggle public String getValue(String arg, boolean utf8decode)
154    {
155  777 int index = vargs.indexOf(arg);
156  777 String dc = null, ret = null;
157  777 if (index != -1)
158    {
159  28 ret = vargs.get(index + 1).toString();
160  28 vargs.remove(index);
161  28 vargs.remove(index);
162  28 if (utf8decode && ret != null)
163    {
164  24 try
165    {
166  24 dc = URLDecoder.decode(ret, "UTF-8");
167  24 ret = dc;
168    } catch (Exception e)
169    {
170    // TODO: log failure to decode
171    }
172    }
173    }
174  777 return ret;
175    }
176   
177    /**
178    * check for and remove first occurence of arg in arglist.
179    *
180    * @param arg
181    * @return true if arg was present in argslist.
182    */
 
183  1888 toggle public boolean contains(String arg)
184    {
185  1888 if (vargs.contains(arg))
186    {
187  22 vargs.remove(arg);
188  22 return true;
189    }
190    else
191    {
192  1866 return false;
193    }
194    }
195   
 
196  36 toggle public String nextValue()
197    {
198  36 return vargs.remove(0);
199    }
200   
 
201  55 toggle public int getSize()
202    {
203  55 return vargs.size();
204    }
205   
 
206  0 toggle public Object getAppletValue(String key, String def, boolean asString)
207    {
208  0 Object value;
209  0 return (appletParams == null ? null
210  ? : (value = appletParams.get(key.toLowerCase())) == null
211  0 ? def : asString ? "" + value
212    : value);
213    }
214   
215    }