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 float property values within an upper and lower boundary.
13   * 
14   * @author Brian Remedios
15   */
16  public class FloatProperty extends AbstractNumericProperty<Float> {
17  
18  	public static final PropertyDescriptorFactory FACTORY = new BasicPropertyDescriptorFactory<FloatProperty>(float.class, numberFieldTypesByKey) {
19  
20  		public FloatProperty createWith(Map<String, String> valuesById) {
21  			final String[] minMax = minMaxFrom(valuesById);
22  			return new FloatProperty(
23  					nameIn(valuesById),
24  					descriptionIn(valuesById),
25  					Float.valueOf(minMax[0]),
26  					Float.valueOf(minMax[1]),
27  					Float.valueOf(numericDefaultValueIn(valuesById)),
28  					0f);
29  		}
30  	};
31  		
32  	
33  	/**
34  	 * Constructor for FloatProperty that limits itself to a single value within the specified limits.
35  	 * 
36  	 * @param theName String
37  	 * @param theDescription String
38  	 * @param min float
39  	 * @param max float
40  	 * @param theDefault float
41  	 * @param theUIOrder float
42  	 * @throws IllegalArgumentException
43  	 */
44  	public FloatProperty(String theName, String theDescription,	Float min, Float max, Float theDefault, float theUIOrder) {
45  		super(theName, theDescription, Float.valueOf(min), Float.valueOf(max), Float.valueOf(theDefault), theUIOrder);		
46  	}
47  	
48  	/**
49       * Constructor for FloatProperty that limits itself to a single value within the specified limits. 
50       * Converts string arguments into the Float values.
51       * 
52       * @param theName String
53       * @param theDescription String
54       * @param minStr String
55       * @param maxStr String
56       * @param defaultStr String
57       * @param theUIOrder float
58       * @throws IllegalArgumentException
59       */
60      public FloatProperty(String theName, String theDescription, String minStr, String maxStr, String defaultStr, float theUIOrder) {
61          this(theName, theDescription, floatFrom(minStr), floatFrom(maxStr), floatFrom(defaultStr), theUIOrder);      
62      }
63  	
64      /**
65       * @param numberString String
66       * @return Float
67       */
68      public static Float floatFrom(String numberString) {
69          return Float.valueOf(numberString);
70      }
71      
72  	/**
73  	 * @return Class
74  	 * @see net.sourceforge.pmd.PropertyDescriptor#type()
75  	 */
76  	public Class<Float> type() {
77  		return Float.class;
78  	}
79  
80  	/**
81  	 * Creates an property value of the right type from a raw string.
82  	 * 
83  	 * @param value String
84  	 * @return Object
85  	 */
86  	protected Object createFrom(String value) {
87  		return floatFrom(value);
88  	}
89  }