1
2
3
4 package net.sourceforge.pmd.lang.rule.properties;
5
6 import java.util.Enumeration;
7 import java.util.Map;
8
9 import net.sourceforge.pmd.PropertyDescriptorFactory;
10 import net.sourceforge.pmd.lang.rule.properties.factories.BasicPropertyDescriptorFactory;
11
12
13
14
15
16
17
18
19
20
21 public class EnumeratedProperty<E> extends AbstractEnumeratedProperty<E, Object> {
22
23 public static final PropertyDescriptorFactory FACTORY = new BasicPropertyDescriptorFactory<EnumeratedProperty>(
24 Enumeration.class) {
25
26 public EnumeratedProperty createWith(Map<String, String> valuesById) {
27
28 return new EnumeratedProperty(nameIn(valuesById), descriptionIn(valuesById), labelsIn(valuesById),
29 choicesIn(valuesById), indexIn(valuesById), 0f);
30 }
31 };
32
33
34
35
36
37
38
39
40
41
42
43
44 public EnumeratedProperty(String theName, String theDescription, String[] theLabels, E[] theChoices,
45 int defaultIndex, float theUIOrder) {
46 super(theName, theDescription, theLabels, theChoices, new int[] { defaultIndex }, theUIOrder, false);
47 }
48
49
50
51
52
53 public Class<Object> type() {
54 return Object.class;
55 }
56
57
58
59
60
61
62 @Override
63 public String errorFor(Object value) {
64 return labelsByChoice.containsKey(value) ? null : nonLegalValueMsgFor(value);
65 }
66
67
68
69
70
71
72
73 public Object valueFrom(String value) throws IllegalArgumentException {
74 return choiceFrom(value);
75 }
76
77
78
79
80
81
82
83 @Override
84 public String asDelimitedString(Object value) {
85 return labelsByChoice.get(value);
86 }
87 }