1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
package net.smartlab.web.bean; |
24 |
|
|
25 |
|
import java.util.Locale; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
@author |
31 |
|
|
|
|
| 50% |
Uncovered Elements: 12 (24) |
Complexity: 18 |
Complexity Density: 1,5 |
|
32 |
|
public class BooleanConverter extends Converter { |
33 |
|
|
34 |
|
private boolean value; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@param |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
42 |
2
|
public BooleanConverter(boolean value) {... |
43 |
2
|
this.value = value; |
44 |
|
} |
45 |
|
|
46 |
|
|
47 |
|
@see |
48 |
|
|
49 |
|
|
|
|
| 52,9% |
Uncovered Elements: 8 (17) |
Complexity: 15 |
Complexity Density: 1,67 |
|
50 |
2
|
public Object convert(Class type, Object value, Locale locale) throws ConversionException {... |
51 |
2
|
if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) { |
52 |
1
|
if (value == null || value.toString().trim().length() == 0) { |
53 |
0
|
value = "off"; |
54 |
|
} |
55 |
1
|
if (value.toString().equalsIgnoreCase("on") || value.toString().equalsIgnoreCase("y") |
56 |
|
|| value.toString().equalsIgnoreCase("yes") || value.toString().equalsIgnoreCase("1") |
57 |
|
|| value.toString().equalsIgnoreCase("true")) { |
58 |
1
|
return Boolean.TRUE; |
59 |
0
|
} else if (value.toString().equalsIgnoreCase("off") || value.toString().equalsIgnoreCase("n") |
60 |
|
|| value.toString().equalsIgnoreCase("no") || value.toString().equalsIgnoreCase("0") |
61 |
|
|| value.toString().equalsIgnoreCase("false")) { |
62 |
0
|
return Boolean.FALSE; |
63 |
|
} else { |
64 |
0
|
throw new ConversionException("Unable to convert to boolean `" + value + "`"); |
65 |
|
} |
66 |
|
} else { |
67 |
1
|
return value.toString(); |
68 |
|
} |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
@return |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
0
|
protected boolean hasDefault() {... |
77 |
0
|
return true; |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
@return |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
0
|
protected boolean getDefault() {... |
86 |
0
|
return value; |
87 |
|
} |
88 |
|
} |