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