View Javadoc

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