11-1-2

if (!getInitialized()) { initialize(); setInitialized(true); } int ch = -1; if (line != null) { ch = line.charAt(0); if (line.length() == 1) { line = null; } else { line = line.substring(1); } } else { final int regexpsSize = regexps.size(); for (line = readLine(); line != null; line = readLine()) { boolean matches = true; for (int i = 0; matches && i < regexpsSize; i++) { RegularExpression regexp = (RegularExpression) regexps.elementAt(i); Regexp re = regexp.getRegexp(getProject()); matches = re.matches(line); } if (matches ^ isNegated()) { break; } } if (line != null) { return read(); } } return ch;
if (!getInitialized()) { initialize(); setInitialized(true); } int ch = -1; if (line != null) { ch = line.charAt(0); if (line.length() == 1) { line = null; } else { line = line.substring(1); } } else { final int containsSize = contains.size(); for (line = readLine(); line != null; line = readLine()) { boolean matches = true; for (int i = 0; matches && i < containsSize; i++) { String containsStr = (String) contains.elementAt(i); matches = line.indexOf(containsStr) >= 0; } if (matches ^ isNegated()) { break; } } if (line != null) { return read(); } } return ch;

Clone fragments detected by clone detection tool
File path: /apache-ant-1.7.0/src/org/apache/tools/ant/filters/LineContainsRegExp.java |  | File path: /apache-ant-1.7.0/src/org/apache/tools/ant/filters/LineContains.java
Method name: `int read()` |  | Method name: `int read()`
Number of AST nodes: 21 |  | Number of AST nodes: 20

1

    if (!getInitialized()) {↵

1

    if (!getInitialized()) {↵

2

                initialize();↵

2

                initialize();↵

3

                setInitialized(true);↵

3

                setInitialized(true);↵

4

            }↵

4

            }↵

5

            int ch = -1;↵

5

            int ch = -1;↵

6

            if (line != null) {↵

6

            if (line != null) {↵

7

                ch = line.charAt(0);↵

7

                ch = line.charAt(0);↵

8

                if (line.length() == 1) {↵

8

                if (line.length() == 1) {↵

9

                    line = null;↵

9

                    line = null;↵

10

                } else {↵

10

                } else {↵

11

                    line = line.substring(1);↵

11

                    line = line.substring(1);↵

12

                }↵

12

                }↵

13

            } else {↵

13

            } else {↵

14

                final int regexpsSize = regexps.size();↵

14

                final int containsSize = contains.size();↵

15

                for (line = readLine(); line != null; line = readLine()) {↵

15

                for (line = readLine(); line != null; line = readLine()) {↵

16

                    boolean matches = true;↵

16

                    boolean matches = true;↵

17

                    for (int i = 0; matches && i < regexpsSize; i++) {↵

17

                    for (int i = 0; matches && i < containsSize; i++) {↵

18

                        RegularExpression regexp↵

18

                        ↵

19

                            = (RegularExpression) regexps.elementAt(i);↵

20

                        Regexp re = regexp.getRegexp(getProject());↵

21

                        matches = re.matches(line)↵

19

    String containsStr = (String) contains.elementAt(i);↵

22

    ;↵

20

                        matches = line.indexOf(containsStr) >= 0;↵

23

                    }↵

21

                    }↵

24

                    if (matches ^ isNegated()) {↵

22

                    if (matches ^ isNegated()) {↵

25

                        break;↵

23

                        break;↵

26

                    }↵

24

                    }↵

27

                }↵

25

                }↵

28

                if (line != null) {↵

26

                if (line != null) {↵

29

                    return read();↵

27

                    return read();↵

30

                }↵

28

                }↵

31

            }↵

29

            }↵

32

            return ch;

30

            return ch;

See real code fragment |  | See real code fragment

Summary
Number of common nesting structure subtrees | 1
Number of refactorable cases | 0
Number of non-refactorable cases | 1
Time elapsed for finding largest common nesting structure subtrees (ms) | 1.4
Clones location | Clones are in different classes having the same super class
Number of node comparisons | 77

1. {Non-refactorable}

   Mapping Summary
   Number of mapped statements | 19
   Number of unmapped statements in the first code fragment | 2
   Number of unmapped statements in the second code fragment | 1
   Time elapsed for statement mapping (ms) | 7.1
   Clone type | Type 3

   Mapped Statements
   ID | Statement |  | ID | Statement
   --- | --- | --- | --- | ---

   1

       if (!getInitialized())

   1

       if (!getInitialized())

   2

       initialize();

   2

       initialize();

   3

       setInitialized(true);

   3

       setInitialized(true);

   4

       int ch = -1;

   4

       int ch = -1;

   5

       if (line != null)

   5

       if (line != null)

   6

       ch = line.charAt(0);

   6

       ch = line.charAt(0);

   7

       if (line.length() == 1)

   7

       if (line.length() == 1)

   8

       line = null;

   8

       line = null;

       else

       else

   9

       line = line.substring(1);

   9

       line = line.substring(1);

       else

       else

   10

       final int regexpsSize = regexps.size();

   10 | final int regexpsSize = regexps.size();
   10 | final int containsSize = contains.size();

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   regexpsSize | containsSize | VARIABLE_NAME_MISMATCH
   regexps | contains | VARIABLE_NAME_MISMATCH

   10

       final int containsSize = contains.size();

   11

       for (line = readLine(); line != null; line = readLine())

   11

       for (line = readLine(); line != null; line = readLine())

   12

       boolean matches = true;

   12

       boolean matches = true;

   13

       for (int i = 0; matches && i < regexpsSize; i++)

   13 | for (int i = 0; matches && i < regexpsSize; i++)
   13 | for (int i = 0; matches && i < containsSize; i++)

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   regexpsSize | containsSize | VARIABLE_NAME_MISMATCH

   13

       for (int i = 0; matches && i < containsSize; i++)

   14 | String containsStr = (String)contains.elementAt(i);

   Preondition Violations
   Unmatched statement String containsStr=(String)contains.elementAt(i); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted

   14

       String containsStr = (String)contains.elementAt(i);

   14

       RegularExpression regexp = (RegularExpression)regexps.elementAt(i);

   14 | RegularExpression regexp = (RegularExpression)regexps.elementAt(i);

   Preondition Violations
   Unmatched statement RegularExpression regexp=(RegularExpression)regexps.elementAt(i); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted

   15

       Regexp re = regexp.getRegexp(getProject());

   15 | Regexp re = regexp.getRegexp(getProject());

   Preondition Violations
   Unmatched statement Regexp re=regexp.getRegexp(getProject()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted

   16

       matches = re.matches(line);

   16 | matches = re.matches(line);
   15 | matches = line.indexOf(containsStr) >= 0;

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   re.matches(line) | line.indexOf(containsStr) >= 0 | TYPE_COMPATIBLE_REPLACEMENT

   Preondition Violations
   Expression re.matches(line) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   Expression line.indexOf(containsStr) >= 0 cannot be parameterized, because it has dependencies to/from statements that will be extracted

   15

       matches = line.indexOf(containsStr) >= 0;

   17

       if (matches ^ isNegated())

   16

       if (matches ^ isNegated())

   18

       break;

   17

       break;

   19

       if (line != null)

   18

       if (line != null)

   20

       return read();

   19

       return read();

   21

       return ch;

   20

       return ch;

   Precondition Violations (5)
   Row | Violation
   --- | ---
   1 | Unmatched statement String containsStr=(String)contains.elementAt(i); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   2 | Unmatched statement RegularExpression regexp=(RegularExpression)regexps.elementAt(i); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   3 | Unmatched statement Regexp re=regexp.getRegexp(getProject()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   4 | Expression re.matches(line) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   5 | Expression line.indexOf(containsStr) >= 0 cannot be parameterized, because it has dependencies to/from statements that will be extracted