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
This commit is contained in:
Henri Yandell 2009-03-14 16:29:28 +00:00
parent dc08c40f60
commit 386cd26dab
2 changed files with 0 additions and 135 deletions

View File

@ -43,36 +43,6 @@ public class CharSetUtils {
super();
}
// Factory
//-----------------------------------------------------------------------
/**
* <p>Creates a <code>CharSet</code> instance which allows a certain amount of
* set logic to be performed.</p>
* <p>The syntax is:</p>
* <ul>
* <li>&quot;aeio&quot; which implies 'a','e',..</li>
* <li>&quot;^e&quot; implies not e.</li>
* <li>&quot;ej-m&quot; implies e,j-&gt;m. e,j,k,l,m.</li>
* </ul>
*
* <pre>
* CharSetUtils.evaluateSet(null) = null
* CharSetUtils.evaluateSet([]) = CharSet matching nothing
* CharSetUtils.evaluateSet(["a-e"]) = CharSet matching a,b,c,d,e
* </pre>
*
* @param set the set, may be null
* @return a CharSet instance, <code>null</code> 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
//-----------------------------------------------------------------------
/**
* <p>Translate characters in a String.
* This is a multi character search and replace routine.</p>
*
* <p>An example is:</p>
* <ul>
* <li>translate(&quot;hello&quot;, &quot;ho&quot;, &quot;jy&quot;)
* =&gt; jelly</li>
* </ul>
*
* <p>If the length of characters to search for is greater than the
* length of characters to replace, then the last character is
* used.</p>
*
* <pre>
* CharSetUtils.translate(null, *, *) = null
* CharSetUtils.translate("", *, *) = ""
* </pre>
*
* @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 (&quot;&quot;)
* @return translated String, <code>null</code> if null string input
* @throws NullPointerException if <code>searchChars</code> or <code>replaceChars</code>
* is <code>null</code>
* @throws ArrayIndexOutOfBoundsException if <code>replaceChars</code> is empty (&quot;&quot;)
* @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<sz; i++) {
int idx = searchChars.indexOf(chrs[i]);
if(idx != -1) {
if(idx > withMax) {
idx = withMax;
}
buffer.append(withChrs[idx]);
} else {
buffer.append(chrs[i]);
}
}
return buffer.toString();
}
}

View File

@ -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) {
}
}
}