1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.charts.params; |
21 |
|
|
22 |
|
import java.text.NumberFormat; |
23 |
|
import java.util.Locale; |
24 |
|
import java.util.Map; |
25 |
|
|
26 |
|
import com.xpn.xwiki.plugin.charts.exceptions.InvalidArgumentException; |
27 |
|
import com.xpn.xwiki.plugin.charts.exceptions.MissingArgumentException; |
28 |
|
import com.xpn.xwiki.plugin.charts.exceptions.ParamException; |
29 |
|
|
|
|
| 0% |
Uncovered Elements: 54 (54) |
Complexity: 15 |
Complexity Density: 0.5 |
|
30 |
|
public class NumberFormatChartParam extends LocaleChartParam |
31 |
|
{ |
32 |
|
public static final String TYPE = "type"; |
33 |
|
|
34 |
|
public static final String GENERAL = "general"; |
35 |
|
|
36 |
|
public static final String NUMBER = "number"; |
37 |
|
|
38 |
|
public static final String INTEGER = "integer"; |
39 |
|
|
40 |
|
public static final String CURRENCY = "currency"; |
41 |
|
|
42 |
|
public static final String PERCENT = "percent"; |
43 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
44 |
0 |
public NumberFormatChartParam(String name)... |
45 |
|
{ |
46 |
0 |
super(name); |
47 |
|
} |
48 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
49 |
0 |
public NumberFormatChartParam(String name, boolean optional)... |
50 |
|
{ |
51 |
0 |
super(name, optional); |
52 |
|
} |
53 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
0 |
@Override... |
55 |
|
public Class getType() |
56 |
|
{ |
57 |
0 |
return NumberFormat.class; |
58 |
|
} |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 47 (47) |
Complexity: 12 |
Complexity Density: 0.44 |
|
60 |
0 |
@Override... |
61 |
|
public Object convert(String value) throws ParamException |
62 |
|
{ |
63 |
0 |
Map map = parseMap(value); |
64 |
0 |
String type = getStringArg(map, TYPE); |
65 |
0 |
Locale locale; |
66 |
0 |
try { |
67 |
0 |
locale = (Locale) super.convert(value); |
68 |
|
} catch (MissingArgumentException e) { |
69 |
0 |
locale = null; |
70 |
|
} |
71 |
|
|
72 |
0 |
if (type.equals(GENERAL)) { |
73 |
0 |
if (locale != null) { |
74 |
0 |
return NumberFormat.getInstance(locale); |
75 |
|
} else { |
76 |
0 |
return NumberFormat.getInstance(); |
77 |
|
} |
78 |
0 |
} else if (type.equals(NUMBER)) { |
79 |
0 |
if (locale != null) { |
80 |
0 |
return NumberFormat.getNumberInstance(locale); |
81 |
|
} else { |
82 |
0 |
return NumberFormat.getNumberInstance(); |
83 |
|
} |
84 |
0 |
} else if (type.equals(INTEGER)) { |
85 |
0 |
if (locale != null) { |
86 |
0 |
return NumberFormat.getIntegerInstance(locale); |
87 |
|
} else { |
88 |
0 |
return NumberFormat.getIntegerInstance(); |
89 |
|
} |
90 |
0 |
} else if (type.equals(CURRENCY)) { |
91 |
0 |
if (locale != null) { |
92 |
0 |
return NumberFormat.getCurrencyInstance(locale); |
93 |
|
} else { |
94 |
0 |
return NumberFormat.getCurrencyInstance(); |
95 |
|
} |
96 |
0 |
} else if (type.equals(PERCENT)) { |
97 |
0 |
if (locale != null) { |
98 |
0 |
return NumberFormat.getPercentInstance(locale); |
99 |
|
} else { |
100 |
0 |
return NumberFormat.getPercentInstance(); |
101 |
|
} |
102 |
|
} else { |
103 |
0 |
throw new InvalidArgumentException("Invalid value for parameter " + getName() |
104 |
|
+ ": Unexpected value for type argument: " + type); |
105 |
|
} |
106 |
|
} |
107 |
|
} |