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