1 package net.sourceforge.pmd.properties; 2 3 import net.sourceforge.pmd.util.StringUtil; 4 5 /** 6 * Defines a property type that supports Character values. 7 * 8 * @author Brian Remedios 9 * @version $Revision$ 10 */ 11 public class CharacterProperty extends AbstractPMDProperty { 12 13 /** 14 * Constructor for CharacterProperty. 15 * @param theName String 16 * @param theDescription String 17 * @param theDefault char 18 * @param theUIOrder float 19 */ 20 public CharacterProperty(String theName, String theDescription, char theDefault, float theUIOrder) { 21 super(theName, theDescription, Character.valueOf(theDefault), theUIOrder); 22 } 23 24 /** 25 * Constructor for CharacterProperty. 26 * @param theName String 27 * @param theDescription String 28 * @param theDefaults char[] 29 * @param theUIOrder float 30 * @param delimiter char 31 */ 32 public CharacterProperty(String theName, String theDescription, char[] theDefaults, float theUIOrder, char delimiter) { 33 this(theName, theDescription, asCharacters(theDefaults), theUIOrder, delimiter); 34 } 35 36 /** 37 * Constructor for CharacterProperty. 38 * @param theName String 39 * @param theDescription String 40 * @param theDefaults String 41 * @param theUIOrder float 42 * @param delimiter char 43 */ 44 public CharacterProperty(String theName, String theDescription, String theDefaults, float theUIOrder, char delimiter) { 45 this(theName, theDescription, theDefaults.toCharArray(), theUIOrder, delimiter); 46 } 47 48 /** 49 * Constructor for CharacterProperty. 50 * @param theName String 51 * @param theDescription String 52 * @param theDefaults char[] 53 * @param theUIOrder float 54 * @param delimiter char 55 */ 56 public CharacterProperty(String theName, String theDescription, Character[] theDefaults, float theUIOrder, char delimiter) { 57 super(theName, theDescription, theDefaults, theUIOrder); 58 59 multiValueDelimiter(delimiter); 60 maxValueCount(Integer.MAX_VALUE); 61 } 62 63 /** 64 * Method asCharacters. 65 * @param chars char[] 66 * @return Character[] 67 */ 68 private static final Character[] asCharacters(char[] chars) { 69 Character[] characters = new Character[chars.length]; 70 for (int i=0; i<chars.length; i++) characters[i] = Character.valueOf(chars[i]); 71 return characters; 72 } 73 74 /** 75 * Method type. 76 * @return Class 77 * @see net.sourceforge.pmd.PropertyDescriptor#type() 78 */ 79 public Class<Character> type() { 80 return Character.class; 81 } 82 83 /** 84 * Method valueFrom. 85 * @param valueString String 86 * @return Object 87 * @throws IllegalArgumentException 88 * @see net.sourceforge.pmd.PropertyDescriptor#valueFrom(String) 89 */ 90 public Object valueFrom(String valueString) throws IllegalArgumentException { 91 92 if (maxValueCount() == 1) { 93 if (valueString.length() > 1) throw new IllegalArgumentException(valueString); 94 return Character.valueOf(valueString.charAt(0)); 95 } 96 97 String[] values = StringUtil.substringsOf(valueString, multiValueDelimiter); 98 99 Character[] chars = new Character[values.length]; 100 for (int i=0; i<values.length; i++) chars[i] = Character.valueOf(values[i].charAt(0)); 101 return chars; 102 } 103 }