|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LongArrayConverter | Line # 34 | 15 | 7 | 54,2% |
0.5416667
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (1) | |||
| Result | |||
|
0.5416667
|
net.smartlab.web.ActionTest.testValorize
net.smartlab.web.ActionTest.testValorize
|
1 PASS | |
| 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 | ||
| 24 | package net.smartlab.web.bean; | |
| 25 | ||
| 26 | import java.util.List; | |
| 27 | import java.util.Locale; | |
| 28 | ||
| 29 | /** | |
| 30 | * TODO documentation | |
| 31 | * | |
| 32 | * @author rlogiacco | |
| 33 | */ | |
| 34 | public class LongArrayConverter extends ArrayConverter { | |
| 35 | ||
| 36 | private static final long[] model = new long[0]; | |
| 37 | ||
| 38 | /** | |
| 39 | * @see net.smartlab.web.bean.Converter#convert(java.lang.Class, | |
| 40 | * java.lang.Object, java.util.Locale) | |
| 41 | */ | |
| 42 | 1 |
public Object convert(Class type, 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 | ||
| 48 | // Deal with input value as a String array | |
| 49 | 1 | if (ArrayConverter.model.getClass() == value.getClass()) { |
| 50 | 1 | try { |
| 51 | 1 | String values[] = (String[])value; |
| 52 | 1 | long[] results = new long[values.length]; |
| 53 | 4 | for (int i = 0; i < values.length; i++) { |
| 54 | 3 | results[i] = Long.parseLong(values[i]); |
| 55 | } | |
| 56 | 1 | return (results); |
| 57 | } catch (Exception e) { | |
| 58 | throw new ConversionException(value.toString(), e); | |
| 59 | } | |
| 60 | } | |
| 61 | ||
| 62 | // Parse the input value as a String into elements | |
| 63 | // and convert to the appropriate type | |
| 64 | 0 | try { |
| 65 | 0 | List list = parseElements(value.toString()); |
| 66 | 0 | long[] results = new long[list.size()]; |
| 67 | 0 | for (int i = 0; i < results.length; i++) { |
| 68 | 0 | results[i] = Long.parseLong((String)list.get(i)); |
| 69 | } | |
| 70 | 0 | return (results); |
| 71 | } catch (Exception e) { | |
| 72 | throw new ConversionException(value.toString(), e); | |
| 73 | } | |
| 74 | } | |
| 75 | } | |
|
||||||||||