2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.ws.params.simple;
23 import jalview.ws.params.OptionI;
26 import java.util.ArrayList;
27 import java.util.List;
28 import static java.util.Objects.requireNonNull;
30 public class Option implements OptionI
33 * A builder class which avoids multiple telescoping parameters nightmare.
38 public static class Builder
40 protected String name = null;
42 protected String label = null;
44 protected String description = "";
46 protected boolean required = false;
48 protected String defaultValue = null;
50 protected String value = null;
52 protected List<String> possibleValues = null;
54 protected List<String> displayValues = null;
56 protected URL detailsUrl = null;
58 public void setName(String name)
63 public void setLabel(String label)
68 public void setDescription(String description)
70 this.description = description;
73 public void setRequired(boolean required)
75 this.required = required;
78 public void setDefaultValue(String defaultValue)
80 this.defaultValue = defaultValue;
83 public void setValue(String value)
88 public void setPossibleValues(List<String> possibleValues)
90 this.possibleValues = possibleValues;
93 public void setDisplayValues(List<String> displayValues)
95 this.displayValues = displayValues;
98 public void setDetailsUrl(URL detailsUrl)
100 this.detailsUrl = detailsUrl;
103 public Option build()
105 return new Option(this);
109 public static Builder newBuilder()
111 return new Builder();
119 * current value in string format, or "null" if undefined
124 * default value in string format, or "null" if undefined
130 List<String> possibleVals;
133 * optional display names corresponding to possibleVals
135 List<String> displayVals;
141 protected Option(Builder builder)
143 requireNonNull(builder.name);
145 label = builder.label != null ? builder.label : name;
146 description = builder.description;
147 required = builder.required;
148 defvalue = builder.defaultValue;
149 value = builder.value;
150 if (builder.possibleValues != null)
151 possibleVals = new ArrayList<>(builder.possibleValues);
152 if (builder.displayValues != null)
153 displayVals = new ArrayList<>(builder.displayValues);
155 displayVals = possibleVals;
156 if (possibleVals == null && displayVals != null)
157 throw new IllegalArgumentException(
158 "cannot use displayValues if possibleValues is null");
159 if (possibleVals != null && possibleVals.size() != displayVals.size())
160 throw new IllegalArgumentException(
161 "displayValues size does not match possibleValues");
162 fdetails = builder.detailsUrl;
170 public Option(Option opt)
175 defvalue = opt.defvalue;
176 description = opt.description;
177 if (opt.possibleVals != null)
179 possibleVals = new ArrayList<>(opt.possibleVals);
181 required = opt.required;
182 // URLs are singletons - so we copy by reference. nasty but true.
183 fdetails = opt.fdetails;
190 public Option(String name, String description, String label, boolean isrequired,
191 String defValue, String val, List<String> possibleVals, URL fdetails)
193 this(name, description, isrequired, defValue, val, possibleVals, fdetails);
198 * Constructor including display names for possible values
201 * @param description2
205 * @param possibleVals
208 public Option(String name2, String description2, boolean isrequired,
209 String defValue, String val, List<String> possibleVals,
210 List<String> displayNames, URL fdetails)
213 description = description2;
215 this.required = isrequired;
216 this.defvalue = defValue;
217 if (possibleVals != null)
219 this.possibleVals = new ArrayList<>(possibleVals);
221 if (displayNames != null)
223 this.displayVals = new ArrayList<>(displayNames);
225 this.fdetails = fdetails;
232 * @param description2
236 * @param possibleVals
239 public Option(String name2, String description2, boolean isrequired,
240 String defValue, String val, List<String> possibleVals,
243 this(name2, description2, isrequired, defValue, val, possibleVals, null,
248 public OptionI copy()
250 Option opt = new Option(this);
255 * toString method to help identify options in the debugger only
258 public String toString()
260 return this.getClass().getName() + ":" + name;
264 public String getName()
270 public String getLabel()
272 return label != null ? label : name;
276 public String getValue()
278 return value == null ? defvalue : value;
282 public void setValue(String selectedItem)
284 value = selectedItem;
288 public URL getFurtherDetails()
294 public boolean isRequired()
300 public String getDescription()
306 public List<String> getPossibleValues()
312 public List<String> getDisplayNames()