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>(Enumeration.class) {
24
25 public EnumeratedProperty createWith(Map<String, String> valuesById) {
26
27 return new EnumeratedProperty(
28 nameIn(valuesById),
29 descriptionIn(valuesById),
30 labelsIn(valuesById),
31 choicesIn(valuesById),
32 indexIn(valuesById),
33 0f
34 );
35 }
36 };
37
38
39
40
41
42
43
44
45
46
47
48 public EnumeratedProperty(String theName, String theDescription, String[] theLabels, E[] theChoices, int defaultIndex, float theUIOrder) {
49 super(theName, theDescription, theLabels, theChoices, new int[] {defaultIndex}, theUIOrder, false);
50 }
51
52
53
54
55
56 public Class<Object> type() {
57 return Object.class;
58 }
59
60
61
62
63
64
65 @Override
66 public String errorFor(Object value) {
67 return labelsByChoice.containsKey(value) ?
68 null : nonLegalValueMsgFor(value);
69 }
70
71
72
73
74
75
76
77 public Object valueFrom(String value) throws IllegalArgumentException {
78 return choiceFrom(value);
79 }
80
81
82
83
84
85
86
87 @Override
88 public String asDelimitedString(Object value) {
89 return labelsByChoice.get(value);
90 }
91 }