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 supports multiple double-type property values within an upper and lower boundary.
14   * 
15   * @author Brian Remedios
16   */
17  public class DoubleMultiProperty extends AbstractMultiNumericProperty<Double[]> {
18  	
19  	public static final PropertyDescriptorFactory FACTORY = new BasicPropertyDescriptorFactory<DoubleMultiProperty>(Double[].class, numberFieldTypesByKey) {
20  
21  		public DoubleMultiProperty createWith(Map<String, String> valuesById) {
22  			final String[] minMax = minMaxFrom(valuesById);
23  			Double[] defaultValues = doublesIn(defaultValueIn(valuesById));
24  			return new DoubleMultiProperty(
25  					nameIn(valuesById),
26  					descriptionIn(valuesById),
27  					Double.parseDouble(minMax[0]),
28  					Double.parseDouble(minMax[1]),
29  					defaultValues,
30  					0f
31  					);
32  		};
33  	};
34  	
35  	/**
36  	 * Constructor for DoubleProperty.
37  	 * @param theName String
38  	 * @param theDescription String
39  	 * @param min Double
40  	 * @param max Double
41  	 * @param defaultValues Double[]
42  	 * @param theUIOrder float
43  	 */
44  	public DoubleMultiProperty(String theName, String theDescription, Double min, Double max, Double[] defaultValues, float theUIOrder) {
45  		super(theName, theDescription, min, max, defaultValues, theUIOrder);
46  	}
47  	
48  	/**
49  	 * @return Class
50  	 * @see net.sourceforge.pmd.PropertyDescriptor#type()
51  	 */
52  	public Class<Double[]> type() {
53  		return Double[].class;
54  	}
55  
56  	/**
57  	 * @param value String
58  	 * @return Object
59  	 */
60  	protected Object createFrom(String value) {
61  		return Double.valueOf(value);
62  	}
63  
64  	/**
65  	 * @param size int
66  	 * @return Object[]
67  	 */
68  	protected Object[] arrayFor(int size) {
69  		return new Double[size];
70  	}
71  }