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;
24 import java.util.Arrays;
25 import java.util.List;
27 import jalview.ws.params.ArgumentI;
29 public class BooleanOption extends Option
31 public static class Builder extends Option.Builder
33 private boolean defaultValue = false;
35 private boolean value = false;
37 private String reprValue = null;
39 public void setDefaultValue(Boolean defaultValue)
41 this.defaultValue = defaultValue != null ? defaultValue : false;
44 public void setValue(Boolean value)
46 this.value = value != null ? value : false;
49 public void setReprValue(String reprValue)
51 this.reprValue = reprValue;
55 public void setPossibleValues(List<String> possibleValues)
57 throw new UnsupportedOperationException("cannot set possible values for boolean");
61 public BooleanOption build()
63 return new BooleanOption(this);
67 public static Builder newBuilder()
72 protected BooleanOption(Builder builder)
75 String reprValue = builder.reprValue != null ? builder.reprValue : name;
76 defvalue = builder.defaultValue ? reprValue : null;
77 value = builder.value ? reprValue : null;
78 possibleVals = List.of(reprValue);
79 displayVals = List.of(label);
82 public BooleanOption(String name, String descr, boolean required,
83 Boolean defVal, Boolean val, URL link)
85 super(name, descr, required, (defVal != null && defVal ? name : null),
86 (val != null && val ? name : null), Arrays.asList(name), link);
89 public BooleanOption(String name, String description, String label,
90 boolean isrequired, Boolean defValue, String reprValue, URL link)
92 super(name, description, label, isrequired,
93 defValue != null && defValue ? reprValue : null,
94 defValue != null && defValue ? reprValue : null,
95 Arrays.asList(reprValue), link);
98 public BooleanOption(String name, String description, String label,
99 boolean isrequired, Boolean defValue, URL link)
101 this(name, description, label, isrequired, defValue, String.valueOf(true), link);
104 public static Boolean parseBoolean(ArgumentI argument)
106 return argument.getValue() != null && !argument.getValue().isEmpty() ?