Clover Coverage Report - SmartWeb
Coverage timestamp: Sun Jun 8 2008 21:20:12 CEST
../../../../img/srcFileCovDistChart5.png 13% of files have more coverage
23   96   27   23
16   55   1,17   1
1     27  
1    
4,8% of code in this file is excluded from these metrics.
 
  BooleanArrayConverter       Line # 33 23 27 47,5% 0.475
 
  (1)
 
1    /*
2    * The SmartWeb Framework
3    * Copyright (C) 2004-2006
4    *
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2.1 of the License, or (at your option) any later version.
9    *
10    * This library 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 library; if not, write to the Free Software
17    * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18    *
19    * For further informations on the SmartWeb Framework please visit
20    *
21    * http://smartweb.sourceforge.net
22    */
23    package net.smartlab.web.bean;
24   
25    import java.util.List;
26    import java.util.Locale;
27   
28    /**
29    * TODO documentation
30    *
31    * @author rlogiacco
32    */
 
33    public class BooleanArrayConverter extends ArrayConverter {
34   
35    private static final boolean[] model = new boolean[0];
36   
37   
38    /**
39    * @see net.smartlab.web.bean.Converter#convert(java.lang.Class,
40    * java.lang.Object, java.util.Locale)
41    */
 
42  1 toggle public Object convert(Class to, Object value, Locale locale) throws ConversionException {
43    // Deal with the no-conversion-needed case
44  1 if (model.getClass() == value.getClass()) {
45  0 return (value);
46    }
47    // Deal with input value as a String array
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    // Parse the input value as a String into elements
74    // and convert to the appropriate type
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    }