Clover coverage report - PMD - 3.9
Coverage timestamp: Tue Dec 19 2006 09:38:44 EST
file stats: LOC: 121   Methods: 9
NCLOC: 49   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
StringProperty.java 80% 84.6% 77.8% 82.2%
coverage coverage
 1    package net.sourceforge.pmd.properties;
 2   
 3    import net.sourceforge.pmd.util.StringUtil;
 4   
 5    /**
 6    * Defines a datatype that supports String values.
 7    * When capturing multiple values, all strings must be filtered by the delimiter character.
 8    *
 9    * @author Brian Remedios
 10    * @version $Revision$
 11    */
 12    public class StringProperty extends AbstractPMDProperty {
 13   
 14    private int preferredRowCount;
 15   
 16    public static final char defaultDelimiter = '|';
 17   
 18    /**
 19    * Constructor for StringProperty.
 20    * @param theName String
 21    * @param theDescription String
 22    * @param theDefaultValue String
 23    * @param theUIOrder float
 24    */
 25  95 public StringProperty(String theName, String theDescription, String theDefaultValue, float theUIOrder) {
 26  95 this(theName, theDescription, theDefaultValue, theUIOrder, defaultDelimiter);
 27   
 28  95 maxValueCount(1);
 29    }
 30   
 31    /**
 32    * Constructor for StringProperty.
 33    * @param theName String
 34    * @param theDescription String
 35    * @param theValues String[]
 36    * @param theUIOrder float
 37    * @param aMultiValueDelimiter String
 38    */
 39  75 public StringProperty(String theName, String theDescription, String[] theValues, float theUIOrder, char aMultiValueDelimiter) {
 40  75 super(theName, theDescription, theValues, theUIOrder);
 41   
 42  75 maxValueCount(Integer.MAX_VALUE);
 43  75 multiValueDelimiter(aMultiValueDelimiter);
 44    }
 45   
 46    /**
 47    * Constructor for StringProperty.
 48    * @param theName String
 49    * @param theDescription String
 50    * @param theDefaultValue Object
 51    * @param theUIOrder float
 52    * @param aMultiValueDelimiter String
 53    */
 54  102 protected StringProperty(String theName, String theDescription, Object theDefaultValue, float theUIOrder, char aMultiValueDelimiter) {
 55  102 super(theName, theDescription, theDefaultValue, theUIOrder);
 56   
 57  102 maxValueCount(Integer.MAX_VALUE);
 58  102 multiValueDelimiter(aMultiValueDelimiter);
 59    }
 60   
 61    /**
 62    * Method type.
 63    * @return Class
 64    * @see net.sourceforge.pmd.PropertyDescriptor#type()
 65    */
 66  3 public Class type() {
 67  3 return String.class;
 68    }
 69   
 70    /**
 71    * Method valueFrom.
 72    * @param valueString String
 73    * @return Object
 74    * @see net.sourceforge.pmd.PropertyDescriptor#valueFrom(String)
 75    */
 76  21 public Object valueFrom(String valueString) {
 77   
 78  16 if (maxValueCount() == 1) return valueString;
 79   
 80  5 return StringUtil.substringsOf(valueString, multiValueDelimiter);
 81    }
 82   
 83    /**
 84    * Method containsDelimiter.
 85    * @param value String
 86    * @return boolean
 87    */
 88  11 private boolean containsDelimiter(String value) {
 89  11 return value.indexOf(multiValueDelimiter) >= 0;
 90    }
 91   
 92  0 private final String illegalCharMsg() {
 93  0 return "Value cannot contain the \"" + multiValueDelimiter + "\" character";
 94    }
 95   
 96    /**
 97    *
 98    * @param value Object
 99    * @return String
 100    */
 101  2 protected String valueErrorFor(Object value) {
 102   
 103  2 if (maxValueCount() == 1) {
 104  1 String testValue = (String)value;
 105  1 if (!containsDelimiter(testValue)) return null;
 106  0 return illegalCharMsg();
 107    }
 108   
 109  1 String[] values = (String[])value;
 110  1 for (int i=0; i<values.length; i++) {
 111  10 if (!containsDelimiter(values[i])) continue;
 112  0 return illegalCharMsg();
 113    }
 114   
 115  1 return null;
 116    }
 117   
 118  0 public int preferredRowCount() {
 119  0 return preferredRowCount;
 120    }
 121    }