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 supports multiple double-type property values
13   * 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>(
20              Double[].class, NUMBER_FIELD_TYPES_BY_KEY) {
21  
22          public DoubleMultiProperty createWith(Map<String, String> valuesById) {
23              String[] minMax = minMaxFrom(valuesById);
24              char delimiter = delimiterIn(valuesById, DEFAULT_NUMERIC_DELIMITER);
25              Double[] defaultValues = doublesIn(numericDefaultValueIn(valuesById), delimiter);
26              return new DoubleMultiProperty(nameIn(valuesById), descriptionIn(valuesById),
27                      Double.parseDouble(minMax[0]), Double.parseDouble(minMax[1]), defaultValues, 0f);
28          }
29      };
30  
31      /**
32       * Constructor for DoubleProperty.
33       * 
34       * @param theName String
35       * @param theDescription String
36       * @param min Double
37       * @param max Double
38       * @param defaultValues Double[]
39       * @param theUIOrder float
40       */
41      public DoubleMultiProperty(String theName, String theDescription, Double min, Double max, Double[] defaultValues,
42              float theUIOrder) {
43          super(theName, theDescription, min, max, defaultValues, theUIOrder);
44      }
45  
46      /**
47       * @return Class
48       * @see net.sourceforge.pmd.PropertyDescriptor#type()
49       */
50      public Class<Double[]> type() {
51          return Double[].class;
52      }
53  
54      /**
55       * @param value String
56       * @return Object
57       */
58      protected Object createFrom(String value) {
59          return Double.valueOf(value);
60      }
61  
62      /**
63       * @param size int
64       * @return Object[]
65       */
66      protected Object[] arrayFor(int size) {
67          return new Double[size];
68      }
69  }