View Javadoc

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