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;
30 public class IntegerParameter extends Option implements ParameterI
32 public static class Builder extends Option.Builder
34 // assigning them the opposite way results in no limits unless both are set
35 protected int min = Integer.MAX_VALUE;
37 protected int max = Integer.MIN_VALUE;
40 public void setDefaultValue(String defaultValue)
42 throw new UnsupportedOperationException();
45 public void setDefaultValue(Integer defaultValue)
47 if (defaultValue != null)
48 super.setDefaultValue(defaultValue.toString());
50 super.setDefaultValue(null);
54 public void setValue(String value)
56 throw new UnsupportedOperationException();
59 public void setValue(Integer value)
62 super.setValue(value.toString());
67 public void setMin(Integer min)
69 this.min = min != null ? min : Integer.MAX_VALUE;
72 public void setMax(Integer max)
74 this.max = max != null ? max : Integer.MIN_VALUE;
77 public void setBounds(Integer min, Integer max)
83 public IntegerParameter build()
85 return new IntegerParameter(this);
89 public static Builder newBuilder()
101 public ValueConstrainI getValidValue()
103 return new ValueConstrainI()
107 public ValueType getType()
109 return ValueType.Integer;
113 public Number getMin()
115 return min < max ? min : null;
119 public Number getMax()
121 return min < max ? max : null;
126 protected IntegerParameter(Builder builder)
131 if (defvalue != null)
132 defval = Integer.parseInt(defvalue);
135 public IntegerParameter(IntegerParameter parm)
142 public IntegerParameter(String name, String description, boolean required,
143 int defValue, int min, int max)
145 super(name, description, required, String.valueOf(defValue), null, null,
152 public IntegerParameter(String name, String description, boolean required,
153 int defValue, int value, int min, int max)
155 super(name, description, required, String.valueOf(defValue),
156 String.valueOf(value), null, null);
163 public IntegerParameter copy()
165 return new IntegerParameter(this);