1 package jalview.ws2.params;
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.Collections;
8 import jalview.ws.params.ArgumentI;
9 import jalview.ws.params.WsParamSetI;
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.
20 public class SimpleParamSet implements WsParamSetI
23 * A convenience builder of {@link SimpleParamSet} objects.
27 public static class Builder
29 private String name = "default";
31 private String description = "";
33 private List<String> applicableUrls = new ArrayList<>();
35 private boolean modifiable = false;
37 private List<ArgumentI> arguments = new ArrayList<>();
44 * Set a name of parameter set.
49 public void name(String val)
55 * Set a description of parameter set.
60 public void description(String val)
66 * Add a url to applicable urls for parameter set.
71 public void url(String val)
73 applicableUrls.add(val);
77 * Set all applicable urls for parameter set. Current url list will be
78 * replaced by provided urls.
83 public void urls(String[] val)
85 applicableUrls.clear();
86 for (String url : val)
87 applicableUrls.add(url);
91 * Set modifiable flag for parameter set.
96 public void modifiable(boolean val)
102 * Add an argument to the preset arguments.
105 * argument to be added
107 public void argument(ArgumentI val)
113 * Set arguments for parameter set. Current parameters list will be
114 * replaced by provided arguments.
117 * arguments to be added
119 public void arguments(List<? extends ArgumentI> val)
122 arguments.addAll(val);
126 * Build a new {@link SimpleParamSet} object from the current state of this
129 * @return new paramset instance
131 public SimpleParamSet build()
133 return new SimpleParamSet(this);
137 protected String name;
139 protected String description;
141 protected String[] applicableUrls;
143 protected String sourceFile;
145 protected boolean modifiable;
147 protected List<ArgumentI> arguments;
149 protected SimpleParamSet(Builder builder)
151 this.name = builder.name;
152 this.description = builder.description;
153 this.applicableUrls = builder.applicableUrls.toArray(new String[0]);
154 this.sourceFile = null;
155 this.modifiable = builder.modifiable;
156 setArguments(builder.arguments);
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.
166 public SimpleParamSet(WsParamSetI copy)
168 this.name = copy.getName();
169 this.description = copy.getDescription();
170 var urls = copy.getApplicableUrls();
171 this.applicableUrls = Arrays.copyOf(urls, urls.length);
172 this.sourceFile = copy.getSourceFile();
173 this.modifiable = copy.isModifiable();
174 setArguments(copy.getArguments());
178 * Create a new instance of the parameter set builder.
180 * @return new parameter set builder
182 public static Builder newBuilder()
184 return new Builder();
188 public String getName()
194 * Set a human readable name for this parameter set.
199 public void setName(String name)
205 public String getDescription()
211 * Set additional notes for this parameter set.
216 public void setDescription(String description)
218 this.description = description;
222 public String[] getApplicableUrls()
224 return applicableUrls;
228 * Set the list of service endpoints which this parameter set is valid for.
231 * new service endpoints
233 public void setApplicableUrls(String[] urls)
235 this.applicableUrls = urls;
239 public String getSourceFile()
245 public void setSourceFile(String newFile)
247 this.sourceFile = newFile;
251 public boolean isModifiable()
253 return this.modifiable;
257 * Set whether this parameter set is modifiable or not.
260 * new modifiable value
262 public void setModifiable(boolean modifiable)
264 this.modifiable = modifiable;
268 public List<ArgumentI> getArguments()
270 return this.arguments;
274 public void setArguments(List<ArgumentI> args)
277 throw new UnsupportedOperationException(
278 "Attempting to modify an unmodifiable parameter set");
279 this.arguments = Collections.unmodifiableList(new ArrayList<>(args));