1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.plugin.charts.params

File NumberFormatChartParam.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

20
30
4
1
107
75
15
0.5
7.5
4
3.75

Classes

Class Line # Actions
NumberFormatChartParam 30 30 0% 15 54
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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   
 
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   
 
44  0 toggle public NumberFormatChartParam(String name)
45    {
46  0 super(name);
47    }
48   
 
49  0 toggle public NumberFormatChartParam(String name, boolean optional)
50    {
51  0 super(name, optional);
52    }
53   
 
54  0 toggle @Override
55    public Class getType()
56    {
57  0 return NumberFormat.class;
58    }
59   
 
60  0 toggle @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    }