/** * Version of String.replaceAll() for JDK1.3 * See below for another version which replaces strings rather than chars * * @param source * input string * @param search * char to look for (no regular expressions) * @param replace * string to replace the search string * @return the output string */ public static String replaceAllChars(String source, char search, String replace) { char[] chars = source.toCharArray(); StringBuilder sb = new StringBuilder(source.length()+20); for(char c : chars){ if (c == search){ sb.append(replace); } else { sb.append(c); } } return sb.toString(); }
private String encode(String value) { StringBuilder newValue = new StringBuilder(); char[] chars = value.toCharArray(); for (int i = 0; i < chars.length; i++) { if (chars[i] == '\\')//$NON-NLS-1$ { newValue.append("\\\\");//$NON-NLS-1$ } else { newValue.append(chars[i]); } } return newValue.toString(); }
Clone fragments detected by clone detection tool
File path: /apache-jmeter-2.11/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java File path: /apache-jmeter-2.11/src/protocol/http/org/apache/jmeter/protocol/http/sampler/AjpSampler.java
Method name: String replaceAllChars(String, char, String) Method name: String encode(String)
Number of AST nodes: 4 Number of AST nodes: 4
1
/**
1
private String encode(String value)  {
2
     * Version of String.replaceAll() for JDK1.3
2
        StringBuilder newValue = new StringBuilder();
3
     * See below for another version which replaces strings rather than chars
3
        char[] chars = value.toCharArray();
4
     *
4
        for (int i = 0; i < chars.length; i++)
5
     * @param source
5
        {
6
     *            input string
6
            if (chars[i] == '\\')//$NON-NLS-1$
7
     * @param search
7
            {
8
     *            char to look for (no regular expressions)
8
                newValue.append("\\\\");//$NON-NLS-1$
9
     * @param replace
9
            }
10
     *            string to replace the search string
10
            else
11
     * @return the output string
11
            {
12
     */
12
                newValue.append(chars[i]);
13
    public static String replaceAllChars(String source, char search, String replace) {
13
            }
14
        char[] chars = source.toCharArray();
14
        }
15
        StringBuilder sb = new StringBuilder(source.length()+20);
15
        return newValue.toString();
16
        for(char c : chars){
16
    }
17
            if (c == search){
18
                sb.append(replace);
19
            } else {
20
                sb.append(c);
21
            }
22
        }
23
        return sb.toString();
24
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements4
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.714
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    3
    for (char c : chars)
    3
    for (int i = 0; i < chars.length; i++)
    4
    if (c == search)
    4
    if (c == search)
    4
    if (chars[i] == '\\')
    Differences
    Expression1Expression2Difference
    cchars[i]TYPE_COMPATIBLE_REPLACEMENT
    search'\\'TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression c cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression chars[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4
    if (chars[i] == '\\')
    5
    sb.append(replace);
    5
    sb.append(replace);
    5
    newValue.append("\\\\");
    Differences
    Expression1Expression2Difference
    replace"\\\\"TYPE_COMPATIBLE_REPLACEMENT
    sbnewValueVARIABLE_NAME_MISMATCH
    5
    newValue.append("\\\\");
    else
    else
    6
    sb.append(c);
    6
    sb.append(c);
    6
    newValue.append(chars[i]);
    Differences
    Expression1Expression2Difference
    cchars[i]TYPE_COMPATIBLE_REPLACEMENT
    sbnewValueVARIABLE_NAME_MISMATCH
    Preondition Violations
    Expression c cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression chars[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6
    newValue.append(chars[i]);
    Precondition Violations (4)
    Row Violation
    1Expression c cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression chars[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression c cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression chars[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted