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;
29 import static java.util.Objects.requireNonNullElse;
31 public class Option implements OptionI
34 * A builder class which avoids multiple telescoping parameters nightmare.
39 public static class Builder
41 protected String name = null;
43 protected String label = null;
45 protected String description = "";
47 protected boolean required = false;
49 protected String defaultValue = null;
51 protected String value = null;
53 protected List<String> possibleValues = null;
55 protected List<String> displayValues = null;
57 protected URL detailsUrl = null;
59 public void setName(String name)
64 public void setLabel(String label)
69 public void setDescription(String description)
71 this.description = description;
74 public void setRequired(boolean required)
76 this.required = required;
79 public void setDefaultValue(String defaultValue)
81 this.defaultValue = defaultValue;
84 public void setValue(String value)
89 public void setPossibleValues(List<String> possibleValues)
91 this.possibleValues = possibleValues;
94 public void setDisplayValues(List<String> displayValues)
96 this.displayValues = displayValues;
99 public void setDetailsUrl(URL detailsUrl)
101 this.detailsUrl = detailsUrl;
104 public Option build()
106 return new Option(this);
110 public static Builder newBuilder()
112 return new Builder();
120 * current value in string format, or "null" if undefined
125 * default value in string format, or "null" if undefined
131 List<String> possibleVals;
134 * optional display names corresponding to possibleVals
136 List<String> displayVals;
142 protected Option(Builder builder)
144 requireNonNull(builder.name);
146 label = requireNonNullElse(builder.label, name);
147 description = builder.description;
148 required = builder.required;
149 defvalue = builder.defaultValue;
150 value = builder.value;
151 if (builder.possibleValues != null)
152 possibleVals = new ArrayList<>(builder.possibleValues);
153 if (builder.displayValues != null)
154 displayVals = new ArrayList<>(builder.displayValues);
156 displayVals = possibleVals;
157 if (possibleVals == null && displayVals != null)
158 throw new IllegalArgumentException(
159 "cannot use displayValues if possibleValues is null");
160 if (possibleVals != null && possibleVals.size() != displayVals.size())
161 throw new IllegalArgumentException(
162 "displayValues size does not match possibleValues");
163 fdetails = builder.detailsUrl;
171 public Option(Option opt)
176 defvalue = opt.defvalue;
177 description = opt.description;
178 if (opt.possibleVals != null)
180 possibleVals = new ArrayList<>(opt.possibleVals);
182 required = opt.required;
183 // URLs are singletons - so we copy by reference. nasty but true.
184 fdetails = opt.fdetails;
191 public Option(String name, String description, String label, boolean isrequired,
192 String defValue, String val, List<String> possibleVals, URL fdetails)
194 this(name, description, isrequired, defValue, val, possibleVals, fdetails);
199 * Constructor including display names for possible values
202 * @param description2
206 * @param possibleVals
209 public Option(String name2, String description2, boolean isrequired,
210 String defValue, String val, List<String> possibleVals,
211 List<String> displayNames, URL fdetails)
214 description = description2;
216 this.required = isrequired;
217 this.defvalue = defValue;
218 if (possibleVals != null)
220 this.possibleVals = new ArrayList<>(possibleVals);
222 if (displayNames != null)
224 this.displayVals = new ArrayList<>(displayNames);
226 this.fdetails = fdetails;
233 * @param description2
237 * @param possibleVals
240 public Option(String name2, String description2, boolean isrequired,
241 String defValue, String val, List<String> possibleVals,
244 this(name2, description2, isrequired, defValue, val, possibleVals, null,
249 public OptionI copy()
251 Option opt = new Option(this);
256 * toString method to help identify options in the debugger only
259 public String toString()
261 return this.getClass().getName() + ":" + name;
265 public String getName()
271 public String getLabel()
273 return label != null ? label : name;
277 public String getValue()
279 return value == null ? defvalue : value;
283 public void setValue(String selectedItem)
285 value = selectedItem;
289 public URL getFurtherDetails()
295 public boolean isRequired()
301 public String getDescription()
307 public List<String> getPossibleValues()
313 public List<String> getDisplayNames()