/** * 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(); }
protected static String encodeBackSlashes(String value) { StringBuilder newValue = new StringBuilder(); for (int i = 0; i < value.length(); i++) { char charAt = value.charAt(i); if (charAt == '\\') { // $NON-NLS-1$ newValue.append("\\\\"); // $NON-NLS-1$ } else { newValue.append(charAt); } } 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/HTTPSamplerBase.java
Method name: String replaceAllChars(String, char, String) Method name: String encodeBackSlashes(String)
Number of AST nodes: 4 Number of AST nodes: 5
1
/**
1
protected static String encodeBackSlashes(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
        for (int i = 0; i < value.length(); i++) {
4
     *
4
            char charAt = value.charAt(i);
5
     * @param source
5
            if (charAt == '\\') { // $NON-NLS-1$
6
     *            input string
6
                newValue.append("\\\\"); // $NON-NLS-1$
7
     * @param search
7
            } else {
8
     *            char to look for (no regular expressions)
8
                newValue.append(charAt);
9
     * @param replace
9
            }
10
     *            string to replace the search string
10
        }
11
     * @return the output string
11
        return newValue.toString();
12
     */
12
    }
13
    public static String replaceAllChars(String source, char search, String replace) {
14
        char[] chars = source.toCharArray();
15
        StringBuilder sb = new StringBuilder(source.length()+20);
16
        for(char c : chars){
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 fragment1
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.714
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    3
    for (char c : chars)
    3
    for (char c : chars)
    2
    for (int i = 0; i < value.length(); i++)
    Differences
    Expression1Expression2Difference
    charsvalueVARIABLE_NAME_MISMATCH
    char[]java.lang.StringVARIABLE_TYPE_MISMATCH
    charsvalueVARIABLE_NAME_MISMATCH
    char[]java.lang.StringVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type char[] of variable chars does not match with type java.lang.String of variable value
    • Make classes char[] and java.lang.String extend a common superclass
    Type char[] of variable chars does not match with type java.lang.String of variable value
    • Make classes char[] and java.lang.String extend a common superclass
    2
    for (int i = 0; i < value.length(); i++)
                                                                  
    3
    char charAt = value.charAt(i);
    Preondition Violations
    Unmatched statement char charAt=value.charAt(i); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3
    char charAt = value.charAt(i);
    4
    if (c == search)
    4
    if (c == search)
    4
    if (charAt == '\\')
    Differences
    Expression1Expression2Difference
    ccharAtVARIABLE_NAME_MISMATCH
    search'\\'TYPE_COMPATIBLE_REPLACEMENT
    4
    if (charAt == '\\')
    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(charAt);
    Differences
    Expression1Expression2Difference
    ccharAtVARIABLE_NAME_MISMATCH
    sbnewValueVARIABLE_NAME_MISMATCH
    6
    newValue.append(charAt);
    Precondition Violations (4)
    Row Violation
    1Type char[] of variable chars does not match with type java.lang.String of variable value
    2Type char[] of variable chars does not match with type java.lang.String of variable value
    3Unmatched statement char charAt=value.charAt(i); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Clone fragment #1 returns variables , while Clone fragment #2 returns variables i