Merge branch 'Jalview-JS/develop' into merge_js_develop
[jalview.git] / src / jalview / ws / params / simple / IntegerParameter.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.ws.params.simple;
22
23 import jalview.ws.params.ParameterI;
24 import jalview.ws.params.ValueConstrainI;
25
26 /**
27  * @author jimp
28  * 
29  */
30 public class IntegerParameter extends Option implements ParameterI
31 {
32   int defval;
33
34   int min;
35
36   int max;
37
38   @Override
39   public ValueConstrainI getValidValue()
40   {
41     return new ValueConstrainI()
42     {
43
44       @Override
45       public ValueType getType()
46       {
47         return ValueType.Integer;
48       }
49
50       @Override
51       public Number getMin()
52       {
53         return min < max ? min : null;
54       }
55
56       @Override
57       public Number getMax()
58       {
59         return min < max ? max : null;
60       }
61     };
62   }
63
64   public IntegerParameter(IntegerParameter parm)
65   {
66     super(parm);
67     max = parm.max;
68     min = parm.min;
69   }
70
71   public IntegerParameter(String name, String description, boolean required,
72           int defValue, int min, int max)
73   {
74     super(name, description, required, String.valueOf(defValue), null, null,
75             null);
76     defval = defValue;
77     this.min = min;
78     this.max = max;
79   }
80
81   public IntegerParameter(String name, String description, boolean required,
82           int defValue, int value, int min, int max)
83   {
84     super(name, description, required, String.valueOf(defValue),
85             String.valueOf(value), null, null);
86     defval = defValue;
87     this.min = min;
88     this.max = max;
89   }
90
91   @Override
92   public IntegerParameter copy()
93   {
94     return new IntegerParameter(this);
95   }
96
97 }