Clover icon

Coverage Report

  1. Project Clover database Wed Dec 3 2025 17:03:17 GMT
  2. Package jalview.ws.params.simple

File IntegerParameter.java

 

Coverage histogram

../../../../img/srcFileCovDistChart7.png
30% of files have more coverage

Code metrics

16
36
19
2
181
124
28
0.78
1.89
9.5
1.47

Classes

Class Line # Actions
IntegerParameter 31 23 16
0.5238095552.4%
IntegerParameter.Builder 33 13 12
0.8620689586.2%
 

Contributing tests

This file is covered by 63 tests. .

Source view

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.ArgumentI;
24    import jalview.ws.params.ParameterI;
25    import jalview.ws.params.ValueConstrainI;
26   
27    /**
28    * @author jimp
29    *
30    */
 
31    public class IntegerParameter extends Option implements ParameterI
32    {
 
33    public static class Builder extends Option.Builder
34    {
35    // assigning them the opposite way results in no limits unless both are set
36    protected int min = Integer.MAX_VALUE;
37   
38    protected int max = Integer.MIN_VALUE;
39   
 
40  0 toggle @Override
41    public void setDefaultValue(String defaultValue)
42    {
43  0 throw new UnsupportedOperationException();
44    }
45   
 
46  3014 toggle public void setDefaultValue(Integer defaultValue)
47    {
48  3014 if (defaultValue != null)
49  3008 super.setDefaultValue(defaultValue.toString());
50    else
51  6 super.setDefaultValue(null);
52    }
53   
 
54  0 toggle @Override
55    public void setValue(String value)
56    {
57  0 throw new UnsupportedOperationException();
58    }
59   
 
60  3014 toggle public void setValue(Integer value)
61    {
62  3014 if (value != null)
63  10 super.setValue(value.toString());
64    else
65  3004 super.setValue(null);
66    }
67   
 
68  3004 toggle public void setMin(Integer min)
69    {
70  3004 this.min = min != null ? min : Integer.MAX_VALUE;
71    }
72   
 
73  3004 toggle public void setMax(Integer max)
74    {
75  3004 this.max = max != null ? max : Integer.MIN_VALUE;
76    }
77   
 
78  3004 toggle public void setBounds(Integer min, Integer max)
79    {
80  3004 setMin(min);
81  3004 setMax(max);
82    }
83   
 
84  3014 toggle public IntegerParameter build()
85    {
86  3014 return new IntegerParameter(this);
87    }
88    }
89   
 
90  3014 toggle public static Builder newBuilder()
91    {
92  3014 return new Builder();
93    }
94   
95    int defval;
96   
97    int min;
98   
99    int max;
100   
 
101  3 toggle @Override
102    public ValueConstrainI getValidValue()
103    {
104  3 return new ValueConstrainI()
105    {
106   
 
107  1 toggle @Override
108    public ValueType getType()
109    {
110  1 return ValueType.Integer;
111    }
112   
 
113  2 toggle @Override
114    public Number getMin()
115    {
116  2 return min < max ? min : null;
117    }
118   
 
119  2 toggle @Override
120    public Number getMax()
121    {
122  2 return min < max ? max : null;
123    }
124    };
125    }
126   
 
127  3014 toggle protected IntegerParameter(Builder builder)
128    {
129  3014 super(builder);
130  3014 min = builder.min;
131  3014 max = builder.max;
132  3014 if (defvalue != null)
133  3008 defval = Integer.parseInt(defvalue);
134    }
135   
 
136  0 toggle public IntegerParameter(IntegerParameter parm)
137    {
138  0 super(parm);
139  0 max = parm.max;
140  0 min = parm.min;
141    }
142   
 
143  0 toggle public IntegerParameter(String name, String description, boolean required,
144    int defValue, int min, int max)
145    {
146  0 super(name, description, required, String.valueOf(defValue), null, null,
147    null);
148  0 defval = defValue;
149  0 this.min = min;
150  0 this.max = max;
151    }
152   
 
153  0 toggle public IntegerParameter(String name, String description, boolean required,
154    int defValue, int value, int min, int max)
155    {
156  0 super(name, description, required, String.valueOf(defValue),
157    String.valueOf(value), null, null);
158  0 defval = defValue;
159  0 this.min = min;
160  0 this.max = max;
161    }
162   
 
163  0 toggle @Override
164    public IntegerParameter copy()
165    {
166  0 return new IntegerParameter(this);
167    }
168   
169    /**
170    * Return argument value as int or null if string value is null or empty.
171    *
172    * @param arg argument to extract value from
173    * @return value as int
174    */
 
175  0 toggle public static Integer parseInt(ArgumentI arg)
176    {
177  0 return arg.getValue() != null && !arg.getValue().isEmpty() ?
178    Integer.parseInt(arg.getValue()) : null;
179    }
180   
181    }