CharacterProperty.java
01 /**
02  * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03  */
04 package net.sourceforge.pmd.lang.rule.properties;
05 
06 
07 /**
08  * Defines a property type that supports single Character values.
09  
10  @author Brian Remedios
11  */
12 public class CharacterProperty extends AbstractProperty<Character> {
13 
14   /**
15    * Constructor for CharacterProperty.
16    @param theName String
17    @param theDescription String
18    @param theDefault Character
19    @param theUIOrder float
20    */
21   public CharacterProperty(String theName, String theDescription, Character theDefault, float theUIOrder) {
22     super(theName, theDescription, theDefault, theUIOrder);
23   }
24   
25   /**
26      * Constructor for CharacterProperty.
27      @param theName String
28      @param theDescription String
29      @param defaultStr String
30      @param theUIOrder float
31      @throws IllegalArgumentException
32      */
33     public CharacterProperty(String theName, String theDescription, String defaultStr, float theUIOrder) {
34         this(theName, theDescription, charFrom(defaultStr), theUIOrder);
35     }
36   
37     /**
38      @param charStr String
39      @return Character
40      */
41     public static Character charFrom(String charStr) {
42         
43         if (charStr == null || charStr.length() != 1) {
44             throw new IllegalArgumentException("missing/invalid character value");
45         }
46         return charStr.charAt(0);
47     }
48     
49   /**
50    @return Class
51    @see net.sourceforge.pmd.PropertyDescriptor#type()
52    */
53   public Class<Character> type() {
54     return Character.class;
55   }
56   
57   /**
58    @param valueString String
59    @return Object
60    @throws IllegalArgumentException
61    @see net.sourceforge.pmd.PropertyDescriptor#valueFrom(String)
62    */
63   public Character valueFrom(String valueStringthrows IllegalArgumentException {
64     return charFrom(valueString);
65   }
66   
67     /**
68      * Method defaultAsString.
69      @return String
70      */
71     protected String defaultAsString() {
72         return Character.toString(defaultValue());
73     }
74 }