1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -57,11 +57,10 @@ public class CharacterEditor extends PropertyEditorSupport {
57
57
58
58
/**
59
59
* Create a new CharacterEditor instance.
60
- * <p>The "allowEmpty" parameter controls whether an empty String is
61
- * to be allowed in parsing, i.e. be interpreted as the {@code null}
62
- * value when {@link #setAsText(String) text is being converted}. If
63
- * {@code false}, an {@link IllegalArgumentException} will be thrown
64
- * at that time.
60
+ * <p>The "allowEmpty" parameter controls whether an empty String is to be
61
+ * allowed in parsing, i.e. be interpreted as the {@code null} value when
62
+ * {@link #setAsText(String) text is being converted}. If {@code false},
63
+ * an {@link IllegalArgumentException} will be thrown at that time.
65
64
* @param allowEmpty if empty strings are to be allowed
66
65
*/
67
66
public CharacterEditor (boolean allowEmpty ) {
@@ -81,12 +80,12 @@ else if (text == null) {
81
80
else if (isUnicodeCharacterSequence (text )) {
82
81
setAsUnicode (text );
83
82
}
84
- else if (text .length () != 1 ) {
85
- throw new IllegalArgumentException ("String [" + text + "] with length " +
86
- text .length () + " cannot be converted to char type" );
83
+ else if (text .length () == 1 ) {
84
+ setValue (Character .valueOf (text .charAt (0 )));
87
85
}
88
86
else {
89
- setValue (new Character (text .charAt (0 )));
87
+ throw new IllegalArgumentException ("String [" + text + "] with length " +
88
+ text .length () + " cannot be converted to char type: neither Unicode nor single character" );
90
89
}
91
90
}
92
91
@@ -103,7 +102,7 @@ private boolean isUnicodeCharacterSequence(String sequence) {
103
102
104
103
private void setAsUnicode (String text ) {
105
104
int code = Integer .parseInt (text .substring (UNICODE_PREFIX .length ()), 16 );
106
- setValue (new Character ((char ) code ));
105
+ setValue (Character . valueOf ((char ) code ));
107
106
}
108
107
109
108
}
0 commit comments