From 386cd26dab558f2a1e013d2ff4e32c464c92a54f Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Sat, 14 Mar 2009 16:29:28 +0000 Subject: [PATCH] Removing deprecated evaluateSet and translate methods [LANG-438] git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@754482 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/lang/CharSetUtils.java | 87 ------------------- .../apache/commons/lang/CharSetUtilsTest.java | 48 ---------- 2 files changed, 135 deletions(-) diff --git a/src/java/org/apache/commons/lang/CharSetUtils.java b/src/java/org/apache/commons/lang/CharSetUtils.java index dadf4a85d..46a1093cb 100644 --- a/src/java/org/apache/commons/lang/CharSetUtils.java +++ b/src/java/org/apache/commons/lang/CharSetUtils.java @@ -43,36 +43,6 @@ public class CharSetUtils { super(); } - // Factory - //----------------------------------------------------------------------- - /** - *

Creates a CharSet instance which allows a certain amount of - * set logic to be performed.

- *

The syntax is:

- * - * - *
-     * CharSetUtils.evaluateSet(null)    = null
-     * CharSetUtils.evaluateSet([])      = CharSet matching nothing
-     * CharSetUtils.evaluateSet(["a-e"]) = CharSet matching a,b,c,d,e
-     * 
- * - * @param set the set, may be null - * @return a CharSet instance, null if null input - * @deprecated Use {@link CharSet#getInstance(String[])}. - * Method will be removed in Commons Lang 3.0. - */ - public static CharSet evaluateSet(String[] set) { - if (set == null) { - return null; - } - return new CharSet(set); - } - // Squeeze //----------------------------------------------------------------------- /** @@ -330,61 +300,4 @@ public class CharSetUtils { return buffer.toString(); } - // Translate - //----------------------------------------------------------------------- - /** - *

Translate characters in a String. - * This is a multi character search and replace routine.

- * - *

An example is:

- * - * - *

If the length of characters to search for is greater than the - * length of characters to replace, then the last character is - * used.

- * - *
-     * CharSetUtils.translate(null, *, *) = null
-     * CharSetUtils.translate("", *, *)   = ""
-     * 
- * - * @param str String to replace characters in, may be null - * @param searchChars a set of characters to search for, must not be null - * @param replaceChars a set of characters to replace, must not be null or empty ("") - * @return translated String, null if null string input - * @throws NullPointerException if searchChars or replaceChars - * is null - * @throws ArrayIndexOutOfBoundsException if replaceChars is empty ("") - * @deprecated Use {@link StringUtils#replaceChars(String, String, String)}. - * Method will be removed in Commons Lang 3.0. - * NOTE: StringUtils#replaceChars behaves differently when 'searchChars' is longer - * than 'replaceChars'. CharSetUtils#translate will use the last char of the replacement - * string whereas StringUtils#replaceChars will delete - */ - public static String translate(String str, String searchChars, String replaceChars) { - if (StringUtils.isEmpty(str)) { - return str; - } - StringBuffer buffer = new StringBuffer(str.length()); - char[] chrs = str.toCharArray(); - char[] withChrs = replaceChars.toCharArray(); - int sz = chrs.length; - int withMax = replaceChars.length() - 1; - for(int i=0; i withMax) { - idx = withMax; - } - buffer.append(withChrs[idx]); - } else { - buffer.append(chrs[i]); - } - } - return buffer.toString(); - } - } diff --git a/src/test/org/apache/commons/lang/CharSetUtilsTest.java b/src/test/org/apache/commons/lang/CharSetUtilsTest.java index 44cdf1e3c..880feaaf9 100644 --- a/src/test/org/apache/commons/lang/CharSetUtilsTest.java +++ b/src/test/org/apache/commons/lang/CharSetUtilsTest.java @@ -68,14 +68,6 @@ public class CharSetUtilsTest extends TestCase { assertEquals(false, Modifier.isFinal(CharSetUtils.class.getModifiers())); } - //----------------------------------------------------------------------- - public void testEvaluateSet_Stringarray() { - assertEquals(null, CharSetUtils.evaluateSet((String[]) null)); - assertEquals("[]", CharSetUtils.evaluateSet(new String[0]).toString()); - assertEquals("[]", CharSetUtils.evaluateSet(new String[] {null}).toString()); - assertEquals("[a-e]", CharSetUtils.evaluateSet(new String[] {"a-e"}).toString()); - } - //----------------------------------------------------------------------- public void testSqueeze_StringString() { assertEquals(null, CharSetUtils.squeeze(null, (String) null)); @@ -235,44 +227,4 @@ public class CharSetUtilsTest extends TestCase { assertEquals("heo", CharSetUtils.delete("hello", new String[] { "l" })); } - - public void testTranslate() { - assertEquals(null, CharSetUtils.translate(null, null, null)); - assertEquals("", CharSetUtils.translate("", "a", "b")); - assertEquals("jelly", CharSetUtils.translate("hello", "ho", "jy")); - assertEquals("jellj", CharSetUtils.translate("hello", "ho", "j")); - assertEquals("jelly", CharSetUtils.translate("hello", "ho", "jyx")); - assertEquals("\rhello\r", CharSetUtils.translate("\nhello\n", "\n", "\r")); - assertEquals("hello", CharSetUtils.translate("hello", "", "x")); - assertEquals("hello", CharSetUtils.translate("hello", "", "")); - assertEquals("hello", CharSetUtils.translate("hello", "", "")); - // From http://issues.apache.org/bugzilla/show_bug.cgi?id=25454 - assertEquals("q651.506bera", CharSetUtils.translate("d216.102oren", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789", - "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM567891234")); - } - - public void testTranslateNullPointerException() { - try { - CharSetUtils.translate("hello", null, null); - fail("Expecting NullPointerException"); - } catch (NullPointerException ex) { - } - try { - CharSetUtils.translate("hello", "h", null); - fail("Expecting NullPointerException"); - } catch (NullPointerException ex) { - } - try { - CharSetUtils.translate("hello", null, "a"); - fail("Expecting NullPointerException"); - } catch (NullPointerException ex) { - } - try { - CharSetUtils.translate("hello", "h", ""); - fail("Expecting ArrayIndexOutOfBoundsException"); - } catch (ArrayIndexOutOfBoundsException ex) { - } - } - - }