formatting
[jalview.git] / src / jalview / ws / params / simple / IntegerParameter.java
1 /*******************************************************************************
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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  *******************************************************************************/
18 /**
19  * 
20  */
21 package jalview.ws.params.simple;
22
23 import jalview.ws.params.ParameterI;
24 import jalview.ws.params.ValueConstrainI;
25
26 import compbio.metadata.ValueConstrain.Type;
27
28 /**
29  * @author jimp
30  * 
31  */
32 public class IntegerParameter extends Option implements ParameterI
33 {
34   int defval;
35
36   int min, max;
37
38   public ValueConstrainI getValidValue()
39   {
40     return new ValueConstrainI()
41     {
42
43       @Override
44       public ValueType getType()
45       {
46         return ValueType.Integer;
47       }
48
49       @Override
50       public Number getMin()
51       {
52         if (min < max)
53         {
54           return min;
55         }
56         else
57         {
58           return null;
59         }
60       }
61
62       @Override
63       public Number getMax()
64       {
65         if (min < max)
66         {
67           return max;
68         }
69         else
70         {
71           return null;
72         }
73       }
74     };
75   }
76
77   public IntegerParameter(IntegerParameter parm)
78   {
79     super(parm);
80     max = parm.max;
81     min = parm.min;
82   }
83
84   public IntegerParameter(String name, String description,
85           boolean required, int defValue, int min, int max)
86   {
87     super(name, description, required, String.valueOf(defValue), null,
88             null, null);
89     defval = defValue;
90     this.min = min;
91     this.max = max;
92   }
93
94   public IntegerParameter(String name, String description,
95           boolean required, int defValue, int value, int min, int max)
96   {
97     super(name, description, required, String.valueOf(defValue), String
98             .valueOf(value), null, null);
99     defval = defValue;
100     this.min = min;
101     this.max = max;
102   }
103
104   @Override
105   public IntegerParameter copy()
106   {
107     return new IntegerParameter(this);
108   }
109
110 }