AbstractDelimitedProperty.java
01 package net.sourceforge.pmd.lang.rule.properties;
02 
03 import java.util.Map;
04 
05 /**
06  * Concrete subclasses represent properties whose values when serialized onto a string can 
07  * be problematic without specifying a unique delimiter that won't appear in the value set.
08  
09  @author Brian Remedios
10  */
11 public abstract class AbstractDelimitedProperty<T> extends AbstractProperty<T> {
12 
13     private char multiValueDelimiter;
14     
15     private static final String DELIM_ID = "delimiter";
16     
17     /**
18      * Constructor for AbstractDelimitedProperty.
19      @param theName String
20      @param theDescription String
21      @param theDefault T
22      @param delimiter char
23      @param theUIOrder float
24      */
25     protected AbstractDelimitedProperty(String theName, String theDescription, T theDefault, char delimiter, float theUIOrder) {
26         super(theName, theDescription, theDefault, theUIOrder);
27         
28         multiValueDelimiter = delimiter;
29     }
30 
31     protected static char delimiterIn(Map<String, String> parameters) {
32         if (!parameters.containsKey(DELIM_ID)) {
33             throw new IllegalArgumentException("missing delimiter value");
34         }
35         
36         return parameters.get(DELIM_ID).charAt(0);
37     }
38     
39     /**
40      @param attributes Map<String,String>
41      */
42     protected void addAttributesTo(Map<String, String> attributes) {
43         super.addAttributesTo(attributes);
44         
45         attributes.put(DELIM_ID, Character.toString(multiValueDelimiter));
46     }
47     
48     /**
49      @return String
50      */
51     protected String defaultAsString() {
52         return asDelimitedString(defaultValue(), multiValueDelimiter);
53     }
54     
55     /**
56      @param aDelimiter char
57      */
58     protected void multiValueDelimiter(char aDelimiter) {
59         multiValueDelimiter = aDelimiter;
60     }
61     
62     /**
63      @return char
64      @see net.sourceforge.pmd.PropertyDescriptor#multiValueDelimiter()
65      */
66     public char multiValueDelimiter() {
67         return multiValueDelimiter;
68     }
69     
70     /**
71      @return boolean
72      @see net.sourceforge.pmd.PropertyDescriptor#isMultiValue()
73      */
74     @Override
75     public boolean isMultiValue() {
76         return true;
77     }
78 }