1 package net.sourceforge.pmd.properties; 2 3 import net.sourceforge.pmd.util.StringUtil; 4 5 11 public class CharacterProperty extends AbstractPMDProperty { 12 13 20 public CharacterProperty(String theName, String theDescription, char theDefault, float theUIOrder) { 21 super(theName, theDescription, new Character (theDefault), theUIOrder); 22 } 23 24 32 public CharacterProperty(String theName, String theDescription, char[] theDefaults, float theUIOrder, char delimiter) { 33 this(theName, theDescription, asCharacters(theDefaults), theUIOrder, delimiter); 34 } 35 36 44 public CharacterProperty(String theName, String theDescription, String theDefaults, float theUIOrder, char delimiter) { 45 this(theName, theDescription, theDefaults.toCharArray(), theUIOrder, delimiter); 46 } 47 48 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 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] = new Character (chars[i]); 71 return characters; 72 } 73 74 79 public Class type() { 80 return Character .class; 81 } 82 83 90 public Object valueFrom(String valueString) throws IllegalArgumentException { 91 92 if (maxValueCount() == 1) { 93 if (valueString.length() > 1) throw new IllegalArgumentException (valueString); 94 return new Character (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] = new Character (values[i].charAt(0)); 101 return chars; 102 } 103 } 104 | Popular Tags |