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