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.ParameterI;
24 import jalview.ws.params.ValueConstrainI;
25 import static java.util.Objects.requireNonNullElse;
31 public class IntegerParameter extends Option implements ParameterI
33 public static class Builder extends Option.Builder
35 // assigning them the opposite way results in no limits unless both are set
36 protected int min = Integer.MAX_VALUE;
38 protected int max = Integer.MIN_VALUE;
41 public void setDefaultValue(String defaultValue)
43 throw new UnsupportedOperationException();
46 public void setDefaultValue(Integer defaultValue)
48 if (defaultValue != null)
49 super.setDefaultValue(defaultValue.toString());
51 super.setDefaultValue(null);
55 public void setValue(String value)
57 throw new UnsupportedOperationException();
60 public void setValue(Integer value)
63 super.setValue(value.toString());
68 public void setMin(Integer min)
70 this.min = requireNonNullElse(min, Integer.MAX_VALUE);
73 public void setMax(Integer max)
75 this.max = requireNonNullElse(max, Integer.MIN_VALUE);
78 public void setBounds(Integer min, Integer max)
84 public IntegerParameter build()
86 return new IntegerParameter(this);
90 public static Builder newBuilder()
102 public ValueConstrainI getValidValue()
104 return new ValueConstrainI()
108 public ValueType getType()
110 return ValueType.Integer;
114 public Number getMin()
116 return min < max ? min : null;
120 public Number getMax()
122 return min < max ? max : null;
127 protected IntegerParameter(Builder builder)
132 if (defvalue != null)
133 defval = Integer.parseInt(defvalue);
136 public IntegerParameter(IntegerParameter parm)
143 public IntegerParameter(String name, String description, boolean required,
144 int defValue, int min, int max)
146 super(name, description, required, String.valueOf(defValue), null, null,
153 public IntegerParameter(String name, String description, boolean required,
154 int defValue, int value, int min, int max)
156 super(name, description, required, String.valueOf(defValue),
157 String.valueOf(value), null, null);
164 public IntegerParameter copy()
166 return new IntegerParameter(this);