|
1 |
| package net.sourceforge.pmd.properties; |
|
2 |
| |
|
3 |
| import net.sourceforge.pmd.util.StringUtil; |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| public class CharacterProperty extends AbstractPMDProperty { |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
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 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
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 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
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 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
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 |
| |
|
65 |
| |
|
66 |
| |
|
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 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
3
| public Class type() {
|
|
80 |
3
| return Character.class;
|
|
81 |
| } |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
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 |
| } |