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 single Integer property values within an
13   * upper and lower boundary.
14   * 
15   * @author Brian Remedios
16   */
17  public class IntegerProperty extends AbstractNumericProperty<Integer> {
18  
19      public static final PropertyDescriptorFactory FACTORY = new BasicPropertyDescriptorFactory<IntegerProperty>(
20              Integer.class, NUMBER_FIELD_TYPES_BY_KEY) {
21  
22          public IntegerProperty createWith(Map<String, String> valuesById) {
23              final String[] minMax = minMaxFrom(valuesById);
24              return new IntegerProperty(nameIn(valuesById), descriptionIn(valuesById), Integer.valueOf(minMax[0]),
25                      Integer.valueOf(minMax[1]), Integer.valueOf(numericDefaultValueIn(valuesById)), 0f);
26          }
27      };
28  
29      /**
30       * Constructor for IntegerProperty that limits itself to a single value
31       * within the specified limits.
32       * 
33       * @param theName String
34       * @param theDescription String
35       * @param min Integer
36       * @param max Integer
37       * @param theDefault Integer
38       * @param theUIOrder float
39       * @throws IllegalArgumentException
40       */
41      public IntegerProperty(String theName, String theDescription, Integer min, Integer max, Integer theDefault,
42              float theUIOrder) {
43          super(theName, theDescription, min, max, theDefault, theUIOrder);
44      }
45  
46      /**
47       * Constructor for IntegerProperty that limits itself to a single value
48       * within the specified limits. Converts string arguments into the Float
49       * values.
50       * 
51       * @param theName String
52       * @param theDescription String
53       * @param minStr String
54       * @param maxStr String
55       * @param defaultStr String
56       * @param theUIOrder
57       * @throws IllegalArgumentException
58       */
59      public IntegerProperty(String theName, String theDescription, String minStr, String maxStr, String defaultStr,
60              float theUIOrder) {
61          this(theName, theDescription, intFrom(minStr), intFrom(maxStr), intFrom(defaultStr), theUIOrder);
62      }
63  
64      /**
65       * @param numberString String
66       * @return Integer
67       */
68      public static Integer intFrom(String numberString) {
69          return Integer.valueOf(numberString);
70      }
71  
72      /**
73       * @return Class
74       * @see net.sourceforge.pmd.PropertyDescriptor#type()
75       */
76      public Class<Integer> type() {
77          return Integer.class;
78      }
79  
80      /**
81       * @param value String
82       * @return Object
83       */
84      protected Object createFrom(String value) {
85          return intFrom(value);
86      }
87  }