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.List; |
26 |
|
import java.util.Locale; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
@author |
32 |
|
|
|
|
| 47,5% |
Uncovered Elements: 21 (40) |
Complexity: 27 |
Complexity Density: 1,17 |
|
33 |
|
public class BooleanArrayConverter extends ArrayConverter { |
34 |
|
|
35 |
|
private static final boolean[] model = new boolean[0]; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@see |
40 |
|
|
41 |
|
|
|
|
| 46,2% |
Uncovered Elements: 21 (39) |
Complexity: 27 |
Complexity Density: 1,17 |
|
42 |
1
|
public Object convert(Class to, Object value, Locale locale) throws ConversionException {... |
43 |
|
|
44 |
1
|
if (model.getClass() == value.getClass()) { |
45 |
0
|
return (value); |
46 |
|
} |
47 |
|
|
48 |
1
|
if (ArrayConverter.model.getClass() == value.getClass()) { |
49 |
1
|
try { |
50 |
1
|
String values[] = (String[])value; |
51 |
1
|
boolean[] results = new boolean[values.length]; |
52 |
4
|
for (int i = 0; i < values.length; i++) { |
53 |
3
|
if (values[i].toString().equalsIgnoreCase("on") || values[i].toString().equalsIgnoreCase("y") |
54 |
|
|| values[i].toString().equalsIgnoreCase("yes") |
55 |
|
|| values[i].toString().equalsIgnoreCase("1") |
56 |
|
|| values[i].toString().equalsIgnoreCase("true")) { |
57 |
2
|
results[i] = true; |
58 |
1
|
} else if (values[i].toString().equalsIgnoreCase("off") |
59 |
|
|| values[i].toString().equalsIgnoreCase("n") |
60 |
|
|| values[i].toString().equalsIgnoreCase("no") |
61 |
|
|| values[i].toString().equalsIgnoreCase("0") |
62 |
|
|| values[i].toString().equalsIgnoreCase("false")) { |
63 |
1
|
results[i] = false; |
64 |
|
} else { |
65 |
0
|
throw new ConversionException(); |
66 |
|
} |
67 |
|
} |
68 |
1
|
return (results); |
69 |
|
} catch (Exception e) { |
70 |
|
throw new ConversionException(value.toString(), e); |
71 |
|
} |
72 |
|
} |
73 |
|
|
74 |
|
|
75 |
0
|
try { |
76 |
0
|
List list = parseElements(value.toString()); |
77 |
0
|
boolean[] results = new boolean[list.size()]; |
78 |
0
|
for (int i = 0; i < results.length; i++) { |
79 |
0
|
if (((String)list.get(i)).equalsIgnoreCase("on") || ((String)list.get(i)).equalsIgnoreCase("y") |
80 |
|
|| ((String)list.get(i)).equalsIgnoreCase("yes") || ((String)list.get(i)).equalsIgnoreCase("1") |
81 |
|
|| ((String)list.get(i)).equalsIgnoreCase("true")) { |
82 |
0
|
results[i] = true; |
83 |
0
|
} else if (((String)list.get(i)).equalsIgnoreCase("off") || ((String)list.get(i)).equalsIgnoreCase("n") |
84 |
|
|| ((String)list.get(i)).equalsIgnoreCase("no") || ((String)list.get(i)).equalsIgnoreCase("0") |
85 |
|
|| ((String)list.get(i)).equalsIgnoreCase("false")) { |
86 |
0
|
results[i] = false; |
87 |
|
} else { |
88 |
0
|
throw new ConversionException(); |
89 |
|
} |
90 |
|
} |
91 |
0
|
return (results); |
92 |
|
} catch (Exception e) { |
93 |
|
throw new ConversionException(value.toString(), e); |
94 |
|
} |
95 |
|
} |
96 |
|
} |