Clover icon

Coverage Report

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

File SimpleParamSet.java

 

Coverage histogram

../../../img/srcFileCovDistChart0.png
60% of files have more coverage

Code metrics

2
39
24
2
281
144
25
0.64
1.62
12
1.04

Classes

Class Line # Actions
SimpleParamSet 20 28 16
0.00%
SimpleParamSet.Builder 27 11 9
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package jalview.ws2.params;
2   
3    import java.util.ArrayList;
4    import java.util.Arrays;
5    import java.util.Collections;
6    import java.util.List;
7   
8    import jalview.ws.params.ArgumentI;
9    import jalview.ws.params.WsParamSetI;
10   
11    /**
12    * A simple, web service client agnostic, representation of parameter sets.
13    * Instances are created from the service data fetched from the server or from
14    * the user preset files. This implementation of {@link WsParamSetI} is meant to
15    * decouple parameter set representation form specific clients.
16    *
17    * @author mmwarowny
18    *
19    */
 
20    public class SimpleParamSet implements WsParamSetI
21    {
22    /**
23    * A convenience builder of {@link SimpleParamSet} objects.
24    *
25    * @author mmwarowny
26    */
 
27    public static class Builder
28    {
29    private String name = "default";
30   
31    private String description = "";
32   
33    private List<String> applicableUrls = new ArrayList<>();
34   
35    private boolean modifiable = false;
36   
37    private List<ArgumentI> arguments = new ArrayList<>();
38   
 
39  0 toggle public Builder()
40    {
41    }
42   
43    /**
44    * Set a name of parameter set.
45    *
46    * @param val
47    * name
48    */
 
49  0 toggle public void name(String val)
50    {
51  0 name = val;
52    }
53   
54    /**
55    * Set a description of parameter set.
56    *
57    * @param val
58    * description
59    */
 
60  0 toggle public void description(String val)
61    {
62  0 description = val;
63    }
64   
65    /**
66    * Add a url to applicable urls for parameter set.
67    *
68    * @param val
69    * applicable url
70    */
 
71  0 toggle public void url(String val)
72    {
73  0 applicableUrls.add(val);
74    }
75   
76    /**
77    * Set all applicable urls for parameter set. Current url list will be
78    * replaced by provided urls.
79    *
80    * @param val
81    * applicable urls
82    */
 
83  0 toggle public void urls(String[] val)
84    {
85  0 applicableUrls.clear();
86  0 for (String url : val)
87  0 applicableUrls.add(url);
88    }
89   
90    /**
91    * Set modifiable flag for parameter set.
92    *
93    * @param val
94    * modifiable
95    */
 
96  0 toggle public void modifiable(boolean val)
97    {
98  0 modifiable = val;
99    }
100   
101    /**
102    * Add an argument to the preset arguments.
103    *
104    * @param val
105    * argument to be added
106    */
 
107  0 toggle public void argument(ArgumentI val)
108    {
109  0 arguments.add(val);
110    }
111   
112    /**
113    * Set arguments for parameter set. Current parameters list will be
114    * replaced by provided arguments.
115    *
116    * @param val
117    * arguments to be added
118    */
 
119  0 toggle public void arguments(List<? extends ArgumentI> val)
120    {
121  0 arguments.clear();
122  0 arguments.addAll(val);
123    }
124   
125    /**
126    * Build a new {@link SimpleParamSet} object from the current state of this
127    * builder.
128    *
129    * @return new paramset instance
130    */
 
131  0 toggle public SimpleParamSet build()
132    {
133  0 return new SimpleParamSet(this);
134    }
135    }
136   
137    protected String name;
138   
139    protected String description;
140   
141    protected String[] applicableUrls;
142   
143    protected String sourceFile;
144   
145    protected boolean modifiable;
146   
147    protected List<ArgumentI> arguments;
148   
 
149  0 toggle protected SimpleParamSet(Builder builder)
150    {
151  0 this.name = builder.name;
152  0 this.description = builder.description;
153  0 this.applicableUrls = builder.applicableUrls.toArray(new String[0]);
154  0 this.sourceFile = null;
155  0 this.modifiable = builder.modifiable;
156  0 setArguments(builder.arguments);
157    }
158   
159    /**
160    * Create a copy of the provided paramset. The new instance has the same
161    * properties as the original paramset. The arguments list is a shallow copy
162    * of the original arguments.
163    *
164    * @param copy
165    */
 
166  0 toggle public SimpleParamSet(WsParamSetI copy)
167    {
168  0 this.name = copy.getName();
169  0 this.description = copy.getDescription();
170  0 var urls = copy.getApplicableUrls();
171  0 this.applicableUrls = Arrays.copyOf(urls, urls.length);
172  0 this.sourceFile = copy.getSourceFile();
173  0 this.modifiable = copy.isModifiable();
174  0 setArguments(copy.getArguments());
175    }
176   
177    /**
178    * Create a new instance of the parameter set builder.
179    *
180    * @return new parameter set builder
181    */
 
182  0 toggle public static Builder newBuilder()
183    {
184  0 return new Builder();
185    }
186   
 
187  0 toggle @Override
188    public String getName()
189    {
190  0 return name;
191    }
192   
193    /**
194    * Set a human readable name for this parameter set.
195    *
196    * @param name
197    * new name
198    */
 
199  0 toggle public void setName(String name)
200    {
201  0 this.name = name;
202    }
203   
 
204  0 toggle @Override
205    public String getDescription()
206    {
207  0 return description;
208    }
209   
210    /**
211    * Set additional notes for this parameter set.
212    *
213    * @param description
214    * additional notes
215    */
 
216  0 toggle public void setDescription(String description)
217    {
218  0 this.description = description;
219    }
220   
 
221  0 toggle @Override
222    public String[] getApplicableUrls()
223    {
224  0 return applicableUrls;
225    }
226   
227    /**
228    * Set the list of service endpoints which this parameter set is valid for.
229    *
230    * @param urls
231    * new service endpoints
232    */
 
233  0 toggle public void setApplicableUrls(String[] urls)
234    {
235  0 this.applicableUrls = urls;
236    }
237   
 
238  0 toggle @Override
239    public String getSourceFile()
240    {
241  0 return sourceFile;
242    }
243   
 
244  0 toggle @Override
245    public void setSourceFile(String newFile)
246    {
247  0 this.sourceFile = newFile;
248    }
249   
 
250  0 toggle @Override
251    public boolean isModifiable()
252    {
253  0 return this.modifiable;
254    }
255   
256    /**
257    * Set whether this parameter set is modifiable or not.
258    *
259    * @param modifiable
260    * new modifiable value
261    */
 
262  0 toggle public void setModifiable(boolean modifiable)
263    {
264  0 this.modifiable = modifiable;
265    }
266   
 
267  0 toggle @Override
268    public List<ArgumentI> getArguments()
269    {
270  0 return this.arguments;
271    }
272   
 
273  0 toggle @Override
274    public void setArguments(List<ArgumentI> args)
275    {
276  0 if (!isModifiable())
277  0 throw new UnsupportedOperationException(
278    "Attempting to modify an unmodifiable parameter set");
279  0 this.arguments = Collections.unmodifiableList(new ArrayList<>(args));
280    }
281    }