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 single Boolean values.
13   * 
14   * @author Brian Remedios
15   */
16  public class BooleanProperty extends AbstractScalarProperty<Boolean> {
17  
18      public static final PropertyDescriptorFactory FACTORY = new BasicPropertyDescriptorFactory<BooleanProperty>(
19              Boolean.class) {
20  
21          public BooleanProperty createWith(Map<String, String> valuesById) {
22              return new BooleanProperty(nameIn(valuesById), descriptionIn(valuesById),
23                      Boolean.valueOf(defaultValueIn(valuesById)), 0f);
24          }
25      };
26  
27      /**
28       * Constructor for BooleanProperty limited to a single value.
29       * 
30       * @param theName String
31       * @param theDescription String
32       * @param defaultValue boolean
33       * @param theUIOrder float
34       */
35      public BooleanProperty(String theName, String theDescription, Boolean defaultValue, float theUIOrder) {
36          super(theName, theDescription, Boolean.valueOf(defaultValue), theUIOrder);
37      }
38  
39      /**
40       * Constructor for BooleanProperty limited to a single value. Converts
41       * default argument string into a boolean.
42       * 
43       * @param theName String
44       * @param theDescription String
45       * @param defaultBoolStr String
46       * @param theUIOrder float
47       */
48      public BooleanProperty(String theName, String theDescription, String defaultBoolStr, float theUIOrder) {
49          this(theName, theDescription, Boolean.valueOf(defaultBoolStr), theUIOrder);
50      }
51  
52      /**
53       * @return Class
54       * @see net.sourceforge.pmd.PropertyDescriptor#type()
55       */
56      public Class<Boolean> type() {
57          return Boolean.class;
58      }
59  
60      /**
61       * @return String
62       */
63      protected String defaultAsString() {
64          return Boolean.toString(defaultValue());
65      }
66  
67      /**
68       * Creates and returns a Boolean instance from a raw string
69       * 
70       * @param value String
71       * @return Object
72       */
73      protected Object createFrom(String value) {
74          return Boolean.valueOf(value);
75      }
76  }