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