Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.ws.params.simple

File DoubleParameter.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
43% of files have more coverage

Code metrics

18
37
20
2
180
129
31
0.84
1.85
10
1.55

Classes

Class Line # Actions
DoubleParameter 12 24 19
0.217391321.7%
DoubleParameter.Builder 14 13 12
0.8620689586.2%
 

Contributing tests

This file is covered by 57 tests. .

Source view

1    package jalview.ws.params.simple;
2   
3    import jalview.ws.params.ArgumentI;
4    import jalview.ws.params.ParameterI;
5    import jalview.ws.params.ValueConstrainI;
6   
7    /**
8    *
9    * @author TZVanaalten
10    *
11    */
 
12    public class DoubleParameter extends Option implements ParameterI
13    {
 
14    public static class Builder extends Option.Builder
15    {
16    // setting them the opposite way disables limits until both are set.
17    protected double min = Double.POSITIVE_INFINITY;
18   
19    protected double max = Double.NEGATIVE_INFINITY;
20   
21    /**
22    * Setting string on double parameter is not allowed, use
23    * {@link #setValue(Double)} instead.
24    */
 
25  0 toggle @Override
26    public void setValue(String value)
27    {
28  0 throw new UnsupportedOperationException();
29    }
30   
 
31  2087 toggle public void setValue(Double value)
32    {
33  2087 if (value != null)
34  110 super.setValue(value.toString());
35    else
36  1977 super.setValue(null);
37    }
38   
39    /**
40    * Setting string on double parameter is not allowed, use
41    * {@link #setDefaultValue(Double)} instead.
42    */
 
43  0 toggle @Override
44    public void setDefaultValue(String defaultValue)
45    {
46  0 throw new UnsupportedOperationException();
47    }
48   
 
49  2087 toggle public void setDefaultValue(Double defaultValue)
50    {
51  2087 if (defaultValue != null)
52  2086 super.setDefaultValue(defaultValue.toString());
53    else
54  1 super.setDefaultValue(null);
55    }
56   
 
57  2077 toggle public void setMin(Double min)
58    {
59  2077 this.min = min != null ? min : Double.POSITIVE_INFINITY;
60    }
61   
 
62  2037 toggle public void setMax(Double max)
63    {
64  2037 this.max = max != null ? max : Double.NEGATIVE_INFINITY;
65    }
66   
 
67  1977 toggle public void setBounds(Double min, Double max)
68    {
69  1977 setMin(min);
70  1977 setMax(max);
71    }
72   
 
73  2087 toggle public DoubleParameter build()
74    {
75  2087 return new DoubleParameter(this);
76    }
77    }
78   
 
79  2087 toggle public static Builder newBuilder()
80    {
81  2087 return new Builder();
82    }
83   
84    double defval;
85   
86    double min;
87   
88    double max;
89   
 
90  0 toggle @Override
91    public ValueConstrainI getValidValue()
92    {
93  0 return new ValueConstrainI()
94    {
 
95  0 toggle @Override
96    public ValueType getType()
97    {
98  0 return ValueType.Double;
99    }
100   
 
101  0 toggle @Override
102    public Number getMin()
103    {
104  0 return min < max ? min : null;
105    }
106   
 
107  0 toggle @Override
108    public Number getMax()
109    {
110  0 return min < max ? max : null;
111    }
112    };
113    }
114   
 
115  2087 toggle protected DoubleParameter(Builder builder)
116    {
117  2087 super(builder);
118  2087 this.min = builder.min;
119  2087 this.max = builder.max;
120  2087 if (defvalue != null)
121  2086 defval = Double.parseDouble(defvalue);
122    }
123   
 
124  0 toggle public DoubleParameter(DoubleParameter parm)
125    {
126  0 super(parm);
127  0 max = parm.max;
128  0 min = parm.min;
129    }
130   
 
131  0 toggle public DoubleParameter(String name, String description, boolean required,
132    Double defValue, double min, double max)
133    {
134  0 super(name, description, required, String.valueOf(defValue), null, null,
135    null);
136  0 defval = defValue;
137  0 this.min = min;
138  0 this.max = max;
139    }
140   
 
141  0 toggle public DoubleParameter(String name, String description, boolean required,
142    Double defValue, Double value, double min, double max)
143    {
144  0 super(name, description, required, String.valueOf(defValue),
145    String.valueOf(value), null, null);
146  0 defval = defValue;
147  0 this.min = min;
148  0 this.max = max;
149    }
150   
 
151  0 toggle @Override
152    public DoubleParameter copy()
153    {
154  0 return new DoubleParameter(this);
155    }
156   
157    /**
158    * Return argument value as double or null if string value is null or empty.
159    *
160    * @param arg argument to extract value form
161    * @return argument value as double
162    */
 
163  0 toggle public static Double parseDouble(ArgumentI arg)
164    {
165  0 return arg.getValue() != null && !arg.getValue().isEmpty() ?
166    Double.parseDouble(arg.getValue()) : null;
167    }
168   
169    /**
170    * Return argument value as float or null if string value is null or empty.
171    *
172    * @param arg argument to extract value from
173    * @return value as float
174    */
 
175  0 toggle public static Float parseFloat(ArgumentI arg)
176    {
177  0 return arg.getValue() != null && !arg.getValue().isEmpty() ?
178    Float.parseFloat(arg.getValue()) : null;
179    }
180    }