Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 16:11:35 GMT
  2. Package jalview.ws.params.simple

File Option.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
43% of files have more coverage

Code metrics

20
62
28
2
316
202
40
0.65
2.21
14
1.43

Classes

Class Line # Actions
Option 30 52 30
0.440%
Option.Builder 38 10 10
0.990%
 

Contributing tests

This file is covered by 63 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.ws.params.simple;
22   
23    import jalview.ws.params.OptionI;
24   
25    import java.net.URL;
26    import java.util.ArrayList;
27    import java.util.List;
28    import static java.util.Objects.requireNonNull;
29   
 
30    public class Option implements OptionI
31    {
32    /**
33    * A builder class which avoids multiple telescoping parameters nightmare.
34    *
35    * @author mmwarowny
36    *
37    */
 
38    public static class Builder
39    {
40    protected String name = null;
41   
42    protected String label = null;
43   
44    protected String description = "";
45   
46    protected boolean required = false;
47   
48    protected String defaultValue = null;
49   
50    protected String value = null;
51   
52    protected List<String> possibleValues = null;
53   
54    protected List<String> displayValues = null;
55   
56    protected URL detailsUrl = null;
57   
 
58  13743 toggle public void setName(String name)
59    {
60  13743 this.name = name;
61    }
62   
 
63  13743 toggle public void setLabel(String label)
64    {
65  13743 this.label = label;
66    }
67   
 
68  11727 toggle public void setDescription(String description)
69    {
70  11727 this.description = description;
71    }
72   
 
73  11727 toggle public void setRequired(boolean required)
74    {
75  11727 this.required = required;
76    }
77   
 
78  8560 toggle public void setDefaultValue(String defaultValue)
79    {
80  8560 this.defaultValue = defaultValue;
81    }
82   
 
83  5311 toggle public void setValue(String value)
84    {
85  5311 this.value = value;
86    }
87   
 
88  3279 toggle public void setPossibleValues(List<String> possibleValues)
89    {
90  3279 this.possibleValues = possibleValues;
91    }
92   
 
93  30 toggle public void setDisplayValues(List<String> displayValues)
94    {
95  30 this.displayValues = displayValues;
96    }
97   
 
98  11717 toggle public void setDetailsUrl(URL detailsUrl)
99    {
100  11717 this.detailsUrl = detailsUrl;
101    }
102   
 
103  0 toggle public Option build()
104    {
105  0 return new Option(this);
106    }
107    }
108   
 
109  0 toggle public static Builder newBuilder()
110    {
111  0 return new Builder();
112    }
113   
114    String name;
115   
116    String label;
117   
118    /*
119    * current value in string format, or "null" if undefined
120    */
121    String value;
122   
123    /*
124    * default value in string format, or "null" if undefined
125    */
126    String defvalue;
127   
128    String description;
129   
130    List<String> possibleVals;
131   
132    /*
133    * optional display names corresponding to possibleVals
134    */
135    List<String> displayVals;
136   
137    boolean required;
138   
139    URL fdetails;
140   
 
141  13631 toggle protected Option(Builder builder)
142    {
143  13631 requireNonNull(builder.name);
144  13631 name = builder.name;
145  13631 label = builder.label != null ? builder.label : name;
146  13631 description = builder.description;
147  13631 required = builder.required;
148  13631 defvalue = builder.defaultValue;
149  13631 value = builder.value;
150  13631 if (builder.possibleValues != null)
151  3279 possibleVals = new ArrayList<>(builder.possibleValues);
152  13631 if (builder.displayValues != null)
153  30 displayVals = new ArrayList<>(builder.displayValues);
154    else
155  13601 displayVals = possibleVals;
156  13631 if (possibleVals == null && displayVals != null)
157  0 throw new IllegalArgumentException(
158    "cannot use displayValues if possibleValues is null");
159  13630 if (possibleVals != null && possibleVals.size() != displayVals.size())
160  0 throw new IllegalArgumentException(
161    "displayValues size does not match possibleValues");
162  13631 fdetails = builder.detailsUrl;
163    }
164   
165    /**
166    * Copy constructor
167    *
168    * @param opt
169    */
 
170  0 toggle public Option(Option opt)
171    {
172  0 name = opt.name;
173  0 label = opt.label;
174  0 value = opt.value;
175  0 defvalue = opt.defvalue;
176  0 description = opt.description;
177  0 if (opt.possibleVals != null)
178    {
179  0 possibleVals = new ArrayList<>(opt.possibleVals);
180    }
181  0 required = opt.required;
182    // URLs are singletons - so we copy by reference. nasty but true.
183  0 fdetails = opt.fdetails;
184    }
185   
 
186  0 toggle public Option()
187    {
188    }
189   
 
190  0 toggle public Option(String name, String description, String label, boolean isrequired,
191    String defValue, String val, List<String> possibleVals, URL fdetails)
192    {
193  0 this(name, description, isrequired, defValue, val, possibleVals, fdetails);
194  0 this.label = label;
195    }
196   
197    /**
198    * Constructor including display names for possible values
199    *
200    * @param name2
201    * @param description2
202    * @param isrequired
203    * @param defValue
204    * @param val
205    * @param possibleVals
206    * @param fdetails
207    */
 
208  0 toggle public Option(String name2, String description2, boolean isrequired,
209    String defValue, String val, List<String> possibleVals,
210    List<String> displayNames, URL fdetails)
211    {
212  0 name = name2;
213  0 description = description2;
214  0 this.value = val;
215  0 this.required = isrequired;
216  0 this.defvalue = defValue;
217  0 if (possibleVals != null)
218    {
219  0 this.possibleVals = new ArrayList<>(possibleVals);
220    }
221  0 if (displayNames != null)
222    {
223  0 this.displayVals = new ArrayList<>(displayNames);
224    }
225  0 this.fdetails = fdetails;
226    }
227   
228    /**
229    * Constructor
230    *
231    * @param name2
232    * @param description2
233    * @param isrequired
234    * @param defValue
235    * @param val
236    * @param possibleVals
237    * @param fdetails
238    */
 
239  0 toggle public Option(String name2, String description2, boolean isrequired,
240    String defValue, String val, List<String> possibleVals,
241    URL fdetails)
242    {
243  0 this(name2, description2, isrequired, defValue, val, possibleVals, null,
244    fdetails);
245    }
246   
 
247  0 toggle @Override
248    public OptionI copy()
249    {
250  0 Option opt = new Option(this);
251  0 return opt;
252    }
253   
254    /**
255    * toString method to help identify options in the debugger only
256    */
 
257  0 toggle @Override
258    public String toString()
259    {
260  0 return this.getClass().getName() + ":" + name;
261    }
262   
 
263  3 toggle @Override
264    public String getName()
265    {
266  3 return name;
267    }
268   
 
269  3 toggle @Override
270    public String getLabel()
271    {
272  3 return label != null ? label : name;
273    }
274   
 
275  3 toggle @Override
276    public String getValue()
277    {
278  3 return value == null ? defvalue : value;
279    }
280   
 
281  0 toggle @Override
282    public void setValue(String selectedItem)
283    {
284  0 value = selectedItem;
285    }
286   
 
287  0 toggle @Override
288    public URL getFurtherDetails()
289    {
290  0 return fdetails;
291    }
292   
 
293  3 toggle @Override
294    public boolean isRequired()
295    {
296  3 return required;
297    }
298   
 
299  3 toggle @Override
300    public String getDescription()
301    {
302  3 return description;
303    }
304   
 
305  0 toggle @Override
306    public List<String> getPossibleValues()
307    {
308  0 return possibleVals;
309    }
310   
 
311  0 toggle @Override
312    public List<String> getDisplayNames()
313    {
314  0 return displayVals;
315    }
316    }