Clover coverage report - PMD - 3.9 Coverage timestamp: Tue Dec 19 2006 09:38:44 EST FRAMES NO FRAMES |
file stats: | LOC: | 103 |  | Methods: | 7
| NCLOC: | 36 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
CharacterProperty.java | 87.5% | 90% | 85.7% | 88.6% |

1 |  | package net.sourceforge.pmd.properties;
2 |  |
3 |  | import net.sourceforge.pmd.util.StringUtil;
4 |  |
5 |  | /**
6 |  | * Defines a property type that supports Character values.
7 |  | *
8 |  | * @author Brian Remedios
9 |  | * @version $Revision$
10 |  | */
11 |  | public class CharacterProperty extends AbstractPMDProperty {
12 |  |
13 |  | /**
14 |  | * Constructor for CharacterProperty.
15 |  | * @param theName String
16 |  | * @param theDescription String
17 |  | * @param theDefault char
18 |  | * @param theUIOrder float
19 |  | */
20 | 4 | public CharacterProperty(String theName, String theDescription, char theDefault, float theUIOrder) {
21 | 4 | super(theName, theDescription, new Character(theDefault), theUIOrder);
22 |  | }
23 |  |
24 |  | /**
25 |  | * Constructor for CharacterProperty.
26 |  | * @param theName String
27 |  | * @param theDescription String
28 |  | * @param theDefaults char[]
29 |  | * @param theUIOrder float
30 |  | * @param delimiter char
31 |  | */
32 | 3 | public CharacterProperty(String theName, String theDescription, char[] theDefaults, float theUIOrder, char delimiter) {
33 | 3 | this(theName, theDescription, asCharacters(theDefaults), theUIOrder, delimiter);
34 |  | }
35 |  |
36 |  | /**
37 |  | * Constructor for CharacterProperty.
38 |  | * @param theName String
39 |  | * @param theDescription String
40 |  | * @param theDefaults String
41 |  | * @param theUIOrder float
42 |  | * @param delimiter char
43 |  | */
44 | 0 | public CharacterProperty(String theName, String theDescription, String theDefaults, float theUIOrder, char delimiter) {
45 | 0 | this(theName, theDescription, theDefaults.toCharArray(), theUIOrder, delimiter);
46 |  | }
47 |  |
48 |  | /**
49 |  | * Constructor for CharacterProperty.
50 |  | * @param theName String
51 |  | * @param theDescription String
52 |  | * @param theDefaults char[]
53 |  | * @param theUIOrder float
54 |  | * @param delimiter char
55 |  | */
56 | 3 | public CharacterProperty(String theName, String theDescription, Character[] theDefaults, float theUIOrder, char delimiter) {
57 | 3 | super(theName, theDescription, theDefaults, theUIOrder);
58 |  |
59 | 3 | multiValueDelimiter(delimiter);
60 | 3 | maxValueCount(Integer.MAX_VALUE);
61 |  | }
62 |  |
63 |  | /**
64 |  | * Method asCharacters.
65 |  | * @param chars char[]
66 |  | * @return Character[]
67 |  | */
68 | 3 | private static final Character[] asCharacters(char[] chars) {
69 | 3 | Character[] characters = new Character[chars.length];
70 | 11 | for (int i=0; i<chars.length; i++) characters[i] = new Character(chars[i]);
71 | 3 | return characters;
72 |  | }
73 |  |
74 |  | /**
75 |  | * Method type.
76 |  | * @return Class
77 |  | * @see net.sourceforge.pmd.PropertyDescriptor#type()
78 |  | */
79 | 3 | public Class type() {
80 | 3 | return Character.class;
81 |  | }
82 |  |
83 |  | /**
84 |  | * Method valueFrom.
85 |  | * @param valueString String
86 |  | * @return Object
87 |  | * @throws IllegalArgumentException
88 |  | * @see net.sourceforge.pmd.PropertyDescriptor#valueFrom(String)
89 |  | */
90 | 2 | public Object valueFrom(String valueString) throws IllegalArgumentException {
91 |  |
92 | 2 | if (maxValueCount() == 1) {
93 | 0 | if (valueString.length() > 1) throw new IllegalArgumentException(valueString);
94 | 1 | return new Character(valueString.charAt(0));
95 |  | }
96 |  |
97 | 1 | String[] values = StringUtil.substringsOf(valueString, multiValueDelimiter);
98 |  |
99 | 1 | Character[] chars = new Character[values.length];
100 | 10 | for (int i=0; i<values.length; i++) chars[i] = new Character(values[i].charAt(0));
101 | 1 | return chars;
102 |  | }
103 |  | }