KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > properties > CharacterProperty


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 JavaDoc theName, String JavaDoc theDescription, char theDefault, float theUIOrder) {
21         super(theName, theDescription, new Character JavaDoc(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 JavaDoc theName, String JavaDoc 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 JavaDoc theName, String JavaDoc theDescription, String JavaDoc 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 JavaDoc theName, String JavaDoc theDescription, Character JavaDoc[] 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 JavaDoc[] asCharacters(char[] chars) {
69         Character JavaDoc[] characters = new Character JavaDoc[chars.length];
70         for (int i=0; i<chars.length; i++) characters[i] = new Character JavaDoc(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 JavaDoc type() {
80         return Character JavaDoc.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 JavaDoc valueFrom(String JavaDoc valueString) throws IllegalArgumentException JavaDoc {
91         
92         if (maxValueCount() == 1) {
93             if (valueString.length() > 1) throw new IllegalArgumentException JavaDoc(valueString);
94             return new Character JavaDoc(valueString.charAt(0));
95         }
96         
97         String JavaDoc[] values = StringUtil.substringsOf(valueString, multiValueDelimiter);
98         
99         Character JavaDoc[] chars = new Character JavaDoc[values.length];
100         for (int i=0; i<values.length; i++) chars[i] = new Character JavaDoc(values[i].charAt(0));
101         return chars;
102     }
103 }
104
Popular Tags