1
2
3
4 package net.sourceforge.pmd.lang.rule.properties;
5
6 import java.util.Map;
7
8 import net.sourceforge.pmd.PropertyDescriptorFactory;
9 import net.sourceforge.pmd.lang.rule.properties.factories.BasicPropertyDescriptorFactory;
10 import net.sourceforge.pmd.util.StringUtil;
11
12
13
14
15
16
17 public class CharacterMultiProperty extends AbstractProperty<Character[]> {
18
19 public static final PropertyDescriptorFactory FACTORY = new BasicPropertyDescriptorFactory<CharacterMultiProperty>(
20 Character[].class) {
21
22 public CharacterMultiProperty createWith(Map<String, String> valuesById) {
23 char delimiter = delimiterIn(valuesById);
24 return new CharacterMultiProperty(nameIn(valuesById), descriptionIn(valuesById), charsIn(
25 defaultValueIn(valuesById), delimiter), 0.0f, delimiter);
26 }
27 };
28
29
30
31
32
33
34
35
36
37
38
39 public CharacterMultiProperty(String theName, String theDescription, Character[] theDefaults, float theUIOrder,
40 char delimiter) {
41 super(theName, theDescription, theDefaults, theUIOrder, delimiter);
42
43 if (theDefaults != null) {
44 for (int i = 0; i < theDefaults.length; i++) {
45 if (theDefaults[i].charValue() == delimiter) {
46 throw new IllegalArgumentException("Cannot include the delimiter in the set of defaults");
47 }
48 }
49 }
50 }
51
52
53
54
55
56 public Class<Character[]> type() {
57 return Character[].class;
58 }
59
60
61
62
63
64
65
66 public Character[] valueFrom(String valueString) throws IllegalArgumentException {
67 String[] values = StringUtil.substringsOf(valueString, multiValueDelimiter());
68
69 Character[] chars = new Character[values.length];
70 for (int i = 0; i < values.length; i++) {
71 chars[i] = Character.valueOf(values[i].charAt(0));
72 }
73 return chars;
74 }
75
76
77
78
79
80 @Override
81 public boolean isMultiValue() {
82 return true;
83 }
84 }