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