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 float property values within an upper and lower boundary.
13   * 
14   * @author Brian Remedios
15   */
16  public class FloatMultiProperty extends AbstractMultiNumericProperty<Float[]> {
17  	
18  	public static final PropertyDescriptorFactory FACTORY = new BasicPropertyDescriptorFactory<FloatMultiProperty>(Float[].class, numberFieldTypesByKey) {
19  
20  		public FloatMultiProperty createWith(Map<String, String> valuesById) {
21  			final String[] minMax = minMaxFrom(valuesById);
22  			Float[] defaultValues = floatsIn(defaultValueIn(valuesById));
23  			return new FloatMultiProperty(
24  					nameIn(valuesById),
25  					descriptionIn(valuesById),
26  					Float.parseFloat(minMax[0]),
27  					Float.parseFloat(minMax[1]),
28  					defaultValues,
29  					0f
30  					);
31  		};
32  	};
33  	
34  	/**
35  	 * Constructor for FloatProperty that configures it to accept multiple values and any number of defaults.
36  	 * 
37  	 * @param theName String
38  	 * @param theDescription String
39  	 * @param min Float
40  	 * @param max Float
41  	 * @param defaultValues Float[]
42  	 * @param theUIOrder float
43  	 * @throws IllegalArgumentException
44  	 */
45  	public FloatMultiProperty(String theName, String theDescription, Float min, Float max, Float[] defaultValues, float theUIOrder) {
46  		super(theName, theDescription, min, max, defaultValues, theUIOrder);
47  	}
48  	
49  	/**
50  	 * @return Class
51  	 * @see net.sourceforge.pmd.PropertyDescriptor#type()
52  	 */
53  	public Class<Float[]> type() {
54  		return Float[].class;
55  	}
56  	
57  	/**
58  	 * Creates an property value of the right type from a raw string.
59  	 * 
60  	 * @param value String
61  	 * @return Object
62  	 */
63  	protected Object createFrom(String value) {
64  		return Float.valueOf(value);
65  	}
66  
67  	/**
68  	 * Returns an array of the correct type for the receiver.
69  	 * 
70  	 * @param size int
71  	 * @return Object[]
72  	 */
73  	protected Object[] arrayFor(int size) {
74  		return new Float[size];
75  	}
76  }