Clover Coverage Report - Commons BeanUtils 1.8.3-kuali-SNAPSHOT
Coverage timestamp: Thu Jun 9 2011 14:31:17 EDT
../../../../../../img/srcFileCovDistChart8.png 43% of files have more coverage
20   237   17   1.54
4   58   0.85   13
13     1.31  
1    
 
  BigIntegerLocaleConverter       Line # 36 20 0% 17 10 73% 0.7297297
 
  (24)
 
1    /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10    *
11    * Unless required by applicable law or agreed to in writing, software
12    * distributed under the License is distributed on an "AS IS" BASIS,
13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    * See the License for the specific language governing permissions and
15    * limitations under the License.
16    */
17   
18    package org.apache.commons.beanutils.locale.converters;
19   
20    import java.util.Locale;
21    import java.math.BigInteger;
22    import java.text.ParseException;
23    import org.apache.commons.beanutils.ConversionException;
24   
25    /**
26    * <p>Standard {@link org.apache.commons.beanutils.locale.LocaleConverter}
27    * implementation that converts an incoming
28    * locale-sensitive String into a <code>java.math.BigInteger</code> object,
29    * optionally using a default value or throwing a
30    * {@link org.apache.commons.beanutils.ConversionException}
31    * if a conversion error occurs.</p>
32    *
33    * @author Yauheny Mikulski
34    */
35   
 
36    public class BigIntegerLocaleConverter extends DecimalLocaleConverter {
37   
38   
39    // ----------------------------------------------------------- Constructors
40   
41    /**
42    * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
43    * that will throw a {@link org.apache.commons.beanutils.ConversionException}
44    * if a conversion error occurs. The locale is the default locale for
45    * this instance of the Java Virtual Machine and an unlocalized pattern is used
46    * for the convertion.
47    *
48    */
 
49  1 toggle public BigIntegerLocaleConverter() {
50   
51  1 this(false);
52    }
53   
54    /**
55    * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
56    * that will throw a {@link org.apache.commons.beanutils.ConversionException}
57    * if a conversion error occurs. The locale is the default locale for
58    * this instance of the Java Virtual Machine.
59    *
60    * @param locPattern Indicate whether the pattern is localized or not
61    */
 
62  2 toggle public BigIntegerLocaleConverter(boolean locPattern) {
63   
64  2 this(Locale.getDefault(), locPattern);
65    }
66   
67    /**
68    * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
69    * that will throw a {@link org.apache.commons.beanutils.ConversionException}
70    * if a conversion error occurs. An unlocalized pattern is used for the convertion.
71    *
72    * @param locale The locale
73    */
 
74  1 toggle public BigIntegerLocaleConverter(Locale locale) {
75   
76  1 this(locale, false);
77    }
78   
79    /**
80    * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
81    * that will throw a {@link org.apache.commons.beanutils.ConversionException}
82    * if a conversion error occurs.
83    *
84    * @param locale The locale
85    * @param locPattern Indicate whether the pattern is localized or not
86    */
 
87  24 toggle public BigIntegerLocaleConverter(Locale locale, boolean locPattern) {
88   
89  24 this(locale, (String) null, locPattern);
90    }
91   
92    /**
93    * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
94    * that will throw a {@link org.apache.commons.beanutils.ConversionException}
95    * if a conversion error occurs. An unlocalized pattern is used for the convertion.
96    *
97    * @param locale The locale
98    * @param pattern The convertion pattern
99    */
 
100  1 toggle public BigIntegerLocaleConverter(Locale locale, String pattern) {
101   
102  1 this(locale, pattern, false);
103    }
104   
105    /**
106    * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
107    * that will throw a {@link org.apache.commons.beanutils.ConversionException}
108    * if a conversion error occurs.
109    *
110    * @param locale The locale
111    * @param pattern The convertion pattern
112    * @param locPattern Indicate whether the pattern is localized or not
113    */
 
114  26 toggle public BigIntegerLocaleConverter(Locale locale, String pattern, boolean locPattern) {
115   
116  26 super(locale, pattern, locPattern);
117    }
118   
119    /**
120    * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
121    * that will return the specified default value
122    * if a conversion error occurs. The locale is the default locale for
123    * this instance of the Java Virtual Machine and an unlocalized pattern is used
124    * for the convertion.
125    *
126    * @param defaultValue The default value to be returned
127    */
 
128  1 toggle public BigIntegerLocaleConverter(Object defaultValue) {
129   
130  1 this(defaultValue, false);
131    }
132   
133    /**
134    * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
135    * that will return the specified default value
136    * if a conversion error occurs. The locale is the default locale for
137    * this instance of the Java Virtual Machine.
138    *
139    * @param defaultValue The default value to be returned
140    * @param locPattern Indicate whether the pattern is localized or not
141    */
 
142  2 toggle public BigIntegerLocaleConverter(Object defaultValue, boolean locPattern) {
143   
144  2 this(defaultValue, Locale.getDefault(), locPattern);
145    }
146   
147    /**
148    * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
149    * that will return the specified default value
150    * if a conversion error occurs. An unlocalized pattern is used for the convertion.
151    *
152    * @param defaultValue The default value to be returned
153    * @param locale The locale
154    */
 
155  0 toggle public BigIntegerLocaleConverter(Object defaultValue, Locale locale) {
156   
157  0 this(defaultValue, locale, false);
158    }
159   
160    /**
161    * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
162    * that will return the specified default value
163    * if a conversion error occurs.
164    *
165    * @param defaultValue The default value to be returned
166    * @param locale The locale
167    * @param locPattern Indicate whether the pattern is localized or not
168    */
 
169  2 toggle public BigIntegerLocaleConverter(Object defaultValue, Locale locale, boolean locPattern) {
170   
171  2 this(defaultValue, locale, null, locPattern);
172    }
173   
174    /**
175    * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
176    * that will return the specified default value
177    * if a conversion error occurs. An unlocalized pattern is used for the convertion.
178    *
179    * @param defaultValue The default value to be returned
180    * @param locale The locale
181    * @param pattern The convertion pattern
182    */
 
183  0 toggle public BigIntegerLocaleConverter(Object defaultValue, Locale locale, String pattern) {
184   
185  0 this(defaultValue, locale, pattern, false);
186    }
187   
188    /**
189    * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
190    * that will return the specified default value
191    * if a conversion error occurs.
192    *
193    * @param defaultValue The default value to be returned
194    * @param locale The locale
195    * @param pattern The convertion pattern
196    * @param locPattern Indicate whether the pattern is localized or not
197    */
 
198  4 toggle public BigIntegerLocaleConverter(Object defaultValue, Locale locale, String pattern, boolean locPattern) {
199   
200  4 super(defaultValue, locale, pattern, locPattern);
201    }
202   
203    /**
204    * Convert the specified locale-sensitive input object into an output object of
205    * BigInteger type.
206    *
207    * @param value The input object to be converted
208    * @param pattern The pattern is used for the convertion
209    * @return The converted value
210    *
211    * @exception ConversionException if conversion cannot be performed
212    * successfully
213    * @throws ParseException if an error occurs parsing a String to a Number
214    * @since 1.8.0
215    */
 
216  33 toggle protected Object parse(Object value, String pattern) throws ParseException {
217   
218  33 Object result = super.parse(value, pattern);
219   
220  23 if (result == null || result instanceof BigInteger) {
221  0 return result;
222    }
223   
224  23 if (result instanceof Number) {
225  23 return BigInteger.valueOf(((Number)result).longValue());
226    }
227   
228  0 try {
229  0 return new BigInteger(result.toString());
230    }
231    catch (NumberFormatException ex) {
232  0 throw new ConversionException("Suplied number is not of type BigInteger: " + result);
233    }
234   
235    }
236   
237    }