From ad5b9b01497834d0710eb9fa00a4372c3ceb60ec Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Tue, 2 Aug 2011 18:04:51 +0000 Subject: [PATCH] [LANG-734] The CHAR_ARRAY cache in CharUtils duplicates the cache in java.lang.Character. [LANG-735] Deprecate CharUtils.toCharacterObject(char) in favor of java.lang.Character.valueOf(char). git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1153229 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/java/org/apache/commons/lang3/CharUtils.java | 11 ++++------- src/site/changes/changes.xml | 2 ++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/CharUtils.java b/src/main/java/org/apache/commons/lang3/CharUtils.java index 8008136e9..2241c0d32 100644 --- a/src/main/java/org/apache/commons/lang3/CharUtils.java +++ b/src/main/java/org/apache/commons/lang3/CharUtils.java @@ -48,7 +48,6 @@ public class CharUtils { "\u0078\u0079\u007a\u007b\u007c\u007d\u007e\u007f"; private static final String[] CHAR_STRING_ARRAY = new String[128]; - private static final Character[] CHAR_ARRAY = new Character[128]; /** * {@code \u000a} linefeed LF ('\n'). @@ -72,7 +71,6 @@ public class CharUtils { static { for (int i = 127; i >= 0; i--) { CHAR_STRING_ARRAY[i] = CHAR_STRING.substring(i, i + 1); - CHAR_ARRAY[i] = new Character((char) i); } } @@ -99,14 +97,13 @@ public class CharUtils { * CharUtils.toCharacterObject('A') = 'A' * * + * @deprecated Java 5 introduced {@link Character#valueOf(char)} which caches chars 0 through 127. * @param ch the character to convert * @return a Character of the specified character */ + @Deprecated public static Character toCharacterObject(char ch) { - if (ch < CHAR_ARRAY.length) { - return CHAR_ARRAY[ch]; - } - return new Character(ch); + return Character.valueOf(ch); } /** @@ -130,7 +127,7 @@ public class CharUtils { if (StringUtils.isEmpty(str)) { return null; } - return toCharacterObject(str.charAt(0)); + return Character.valueOf(str.charAt(0)); } //----------------------------------------------------------------------- diff --git a/src/site/changes/changes.xml b/src/site/changes/changes.xml index 0f3c964f2..2b4bcc0a4 100644 --- a/src/site/changes/changes.xml +++ b/src/site/changes/changes.xml @@ -33,6 +33,8 @@ Add mode and median Comparable... methods to ObjectUtils Add BooleanUtils.and + or varargs methods EnumSet -> bit vector + The CHAR_ARRAY cache in CharUtils duplicates the cache in java.lang.Character + Deprecate CharUtils.toCharacterObject(char) in favor of java.lang.Character.valueOf(char)