AbstractScalarProperty xref
1 package net.sourceforge.pmd.properties;
2
3 import net.sourceforge.pmd.util.StringUtil;
4
5 /**
6 * No, subclasses are not necessarily scalar per se, they're just easy to parse without error.
7 * If you can come up with a better name...
8 *
9 * @author Brian Remedios
10 * @version $Revision$
11 */
12 public abstract class AbstractScalarProperty extends AbstractPMDProperty {
13
14 /**
15 * Constructor for AbstractScalarProperty.
16 * @param theName String
17 * @param theDescription String
18 * @param theDefault Object
19 * @param theUIOrder float
20 */
21 public AbstractScalarProperty(String theName, String theDescription, Object theDefault, float theUIOrder) {
22 super(theName, theDescription, theDefault, theUIOrder);
23 }
24
25 /**
26 * Method createFrom.
27 * @param value String
28 * @return Object
29 */
30 protected abstract Object createFrom(String value);
31
32 /**
33 * Method arrayFor.
34 * @param size int
35 * @return Object[]
36 */
37 protected abstract Object[] arrayFor(int size);
38
39 /**
40 * Method valueFrom.
41 * @param valueString String
42 * @return Object[]
43 * @throws IllegalArgumentException
44 * @see net.sourceforge.pmd.PropertyDescriptor#valueFrom(String)
45 */
46 public Object valueFrom(String valueString) throws IllegalArgumentException {
47
48 if (maxValueCount() == 1) return createFrom(valueString);
49
50 String[] strValues = StringUtil.substringsOf(valueString, multiValueDelimiter);
51
52 Object[] values = arrayFor(strValues.length);
53 for (int i=0; i<strValues.length; i++) values[i] = createFrom(strValues[i]);
54 return values;
55 }
56 }