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