/** * Splits the string on every token into an array of strings. * * @param string the string * @param onToken the token * @return the resultant array */ private static String[] split(final String string, final String onToken) { final StringTokenizer tokenizer = new StringTokenizer(string, onToken); final String[] result = new String[ tokenizer.countTokens() ]; for (int i = 0; i < result.length; i++) { result[ i ] = tokenizer.nextToken(); } return result; }
/** * Convert a file path to an array of path components. * This uses File.sepatator to split the file path string. * @param thePath the file path string to convert * @return an array of path components */ public static String[] getPath(String thePath) { StringTokenizer tokenizer = new StringTokenizer(thePath, File.separator); String[] path = new String[ tokenizer.countTokens() ]; int i = 0; while (tokenizer.hasMoreTokens()) { path[i] = tokenizer.nextToken(); i++; } return path; }
Clone fragments detected by clone detection tool
File path: /apache-ant-1.7.0/src/org/apache/tools/ant/taskdefs/optional/extension/Extension.java File path: /apache-ant-1.7.0/src/org/apache/tools/ant/taskdefs/optional/ssh/Directory.java
Method name: String[] split(String, String) Method name: String[] getPath(String)
Number of AST nodes: 2 Number of AST nodes: 3
1
/**
1
/**
2
     * Splits the string on every token into an array of strings.
2
     * Convert a file path to an array of path components.
3
     *
3
     * This uses File.sepatator to split the file path string.
4
     * @param string the string
4
     * @param thePath the file path string to convert
5
     * @param onToken the token
5
     * @return an array of path components
6
     * @return the resultant array
6
     */
7
     */
7
    public static String[] getPath(String thePath) {
8
    private static String[] split(final String string,
8
        StringTokenizer tokenizer = new StringTokenizer(thePath,
9
                                        final String onToken) {
9
                File.separator);
10
        final StringTokenizer tokenizer = new StringTokenizer(string, onToken);
10
        String[] path = new String[ tokenizer.countTokens() ];
11
        final String[] result = new String[ tokenizer.countTokens() ];
11
12
12
        int i = 0;
13
        for (int i = 0; i < result.length; i++) {
13
        while (tokenizer.hasMoreTokens()) {
14
            result[ i ] = tokenizer.nextToken();
14
            path[i] = tokenizer.nextToken();
15
        }
15
            i++;
16
16
        }
17
        return result;
17
18
    }
18
        return path;
19
    }
  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 Score1.000
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    3
    for (int i = 0; i < result.length; i++)
    3
    for (int i = 0; i < result.length; i++)
    4
    while (tokenizer.hasMoreTokens())
    Differences
    Expression1Expression2Difference
    i < result.lengthtokenizer.hasMoreTokens()TYPE_COMPATIBLE_REPLACEMENT
    java.lang.String[]java.lang.StringVARIABLE_TYPE_MISMATCH
    java.lang.String[]java.lang.StringVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.lang.String[] of variable result does not match with type java.lang.String of variable thePath
    • Make classes java.lang.String[] and java.lang.String extend a common superclass
    Type java.lang.String[] of variable result does not match with type java.lang.String of variable thePath
    • Make classes java.lang.String[] and java.lang.String extend a common superclass
    4
    while (tokenizer.hasMoreTokens())
    4
    result[i] = tokenizer.nextToken();
    4
    result[i] = tokenizer.nextToken();
    5
    path[i] = tokenizer.nextToken();
    Differences
    Expression1Expression2Difference
    resultpathVARIABLE_NAME_MISMATCH
    5
    path[i] = tokenizer.nextToken();
                  
    6
    i++;
    Preondition Violations
    Unmatched statement i++; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6
    i++;
    Precondition Violations (3)
    Row Violation
    1Type java.lang.String[] of variable result does not match with type java.lang.String of variable thePath
    2Type java.lang.String[] of variable result does not match with type java.lang.String of variable thePath
    3Unmatched statement i++; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted