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