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