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   import net.sourceforge.pmd.PropertyDescriptorFactory;
9   import net.sourceforge.pmd.lang.rule.properties.factories.BasicPropertyDescriptorFactory;
10  
11  /**
12   * Defines a property type that supports multiple Boolean values.
13   * 
14   * @author Brian Remedios
15   */
16  public class BooleanMultiProperty extends AbstractScalarProperty<Boolean[]> {
17  
18      public static final PropertyDescriptorFactory FACTORY = new BasicPropertyDescriptorFactory<StringMultiProperty>(
19              String[].class) {
20          public BooleanMultiProperty createWith(Map<String, String> valuesById) {
21              char delimiter = delimiterIn(valuesById);
22              return new BooleanMultiProperty(nameIn(valuesById), descriptionIn(valuesById),
23                      booleanValuesIn(defaultValueIn(valuesById), delimiter), 0f);
24          }
25      };
26  
27      /**
28       * Constructor for BooleanMultiProperty that allows for multiple values.
29       * 
30       * @param theName String
31       * @param theDescription String
32       * @param defaultValues Boolean[]
33       * @param theUIOrder float
34       */
35      public BooleanMultiProperty(String theName, String theDescription, Boolean[] defaultValues, float theUIOrder) {
36          super(theName, theDescription, defaultValues, theUIOrder);
37      }
38  
39      /**
40       * @return Class
41       * @see net.sourceforge.pmd.PropertyDescriptor#type()
42       */
43      public Class<Boolean[]> type() {
44          return Boolean[].class;
45      }
46  
47      /**
48       * @return boolean
49       * @see net.sourceforge.pmd.PropertyDescriptor#isMultiValue()
50       */
51      @Override
52      public boolean isMultiValue() {
53          return true;
54      }
55  
56      /**
57       * Creates and returns a Boolean instance from a raw string
58       * 
59       * @param value String
60       * @return Object
61       */
62      protected Object createFrom(String value) {
63          return Boolean.valueOf(value);
64      }
65  
66      /**
67       * @param size int
68       * @return Object[]
69       */
70      protected Boolean[] arrayFor(int size) {
71          return new Boolean[size];
72      }
73  
74      /**
75       * @return String
76       */
77      protected String defaultAsString() {
78          return asDelimitedString(defaultValue());
79      }
80  }