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