JAL-1432 updated copyright notices
[jalview.git] / src / jalview / ws / params / simple / IntegerParameter.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3  * Copyright (C) 2014 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 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.ws.params.simple;
20
21 import jalview.ws.params.ParameterI;
22 import jalview.ws.params.ValueConstrainI;
23
24 /**
25  * @author jimp
26  * 
27  */
28 public class IntegerParameter extends Option implements ParameterI
29 {
30   int defval;
31
32   int min, max;
33
34   public ValueConstrainI getValidValue()
35   {
36     return new ValueConstrainI()
37     {
38
39       @Override
40       public ValueType getType()
41       {
42         return ValueType.Integer;
43       }
44
45       @Override
46       public Number getMin()
47       {
48         if (min < max)
49         {
50           return min;
51         }
52         else
53         {
54           return null;
55         }
56       }
57
58       @Override
59       public Number getMax()
60       {
61         if (min < max)
62         {
63           return max;
64         }
65         else
66         {
67           return null;
68         }
69       }
70     };
71   }
72
73   public IntegerParameter(IntegerParameter parm)
74   {
75     super(parm);
76     max = parm.max;
77     min = parm.min;
78   }
79
80   public IntegerParameter(String name, String description,
81           boolean required, int defValue, int min, int max)
82   {
83     super(name, description, required, String.valueOf(defValue), null,
84             null, null);
85     defval = defValue;
86     this.min = min;
87     this.max = max;
88   }
89
90   public IntegerParameter(String name, String description,
91           boolean required, int defValue, int value, int min, int max)
92   {
93     super(name, description, required, String.valueOf(defValue), String
94             .valueOf(value), null, null);
95     defval = defValue;
96     this.min = min;
97     this.max = max;
98   }
99
100   @Override
101   public IntegerParameter copy()
102   {
103     return new IntegerParameter(this);
104   }
105
106 }