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
11
12
13
14
15
16 public class CharacterProperty extends AbstractProperty<Character> {
17
18 public static final PropertyDescriptorFactory FACTORY = new BasicPropertyDescriptorFactory<CharacterProperty>(
19 Character.class) {
20
21 public CharacterProperty createWith(Map<String, String> valuesById) {
22 return new CharacterProperty(nameIn(valuesById), descriptionIn(valuesById),
23 defaultValueIn(valuesById) != null ? new Character(defaultValueIn(valuesById).charAt(0)) : null, 0f);
24 }
25 };
26
27
28
29
30
31
32
33
34
35 public CharacterProperty(String theName, String theDescription, Character theDefault, float theUIOrder) {
36 super(theName, theDescription, theDefault, theUIOrder);
37 }
38
39
40
41
42
43
44
45
46
47
48 public CharacterProperty(String theName, String theDescription, String defaultStr, float theUIOrder) {
49 this(theName, theDescription, charFrom(defaultStr), theUIOrder);
50 }
51
52
53
54
55
56 public static Character charFrom(String charStr) {
57
58 if (charStr == null || charStr.length() != 1) {
59 throw new IllegalArgumentException("missing/invalid character value");
60 }
61 return charStr.charAt(0);
62 }
63
64
65
66
67
68 public Class<Character> type() {
69 return Character.class;
70 }
71
72
73
74
75
76
77
78 public Character valueFrom(String valueString) throws IllegalArgumentException {
79 return charFrom(valueString);
80 }
81
82
83
84
85
86
87 protected String defaultAsString() {
88 return Character.toString(defaultValue());
89 }
90 }