11/*
2- * Copyright 2002-2012 the original author or authors.
2+ * Copyright 2002-2014 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -57,11 +57,10 @@ public class CharacterEditor extends PropertyEditorSupport {
5757
5858 /**
5959 * 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.
6564 * @param allowEmpty if empty strings are to be allowed
6665 */
6766 public CharacterEditor (boolean allowEmpty ) {
@@ -81,12 +80,12 @@ else if (text == null) {
8180 else if (isUnicodeCharacterSequence (text )) {
8281 setAsUnicode (text );
8382 }
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 )));
8785 }
8886 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" );
9089 }
9190 }
9291
@@ -103,7 +102,7 @@ private boolean isUnicodeCharacterSequence(String sequence) {
103102
104103 private void setAsUnicode (String text ) {
105104 int code = Integer .parseInt (text .substring (UNICODE_PREFIX .length ()), 16 );
106- setValue (new Character ((char ) code ));
105+ setValue (Character . valueOf ((char ) code ));
107106 }
108107
109108}
0 commit comments