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