if (ignoreLinks) { // Do not take existing link tags into account return substituteEmailAddress(s); } // initialisation Matcher noLinkMatcher = EMAIL_PATTERN.matcher(s); Matcher withLinkMatcher = EMAIL_PATTERN_INC_LINK.matcher(s); int pos = 0; // current position in s int length = s.length(); StringBuffer buf = new StringBuffer(); while (pos < length) { if (noLinkMatcher.find(pos)) { // an email adress was found - check whether its already a link int s1 = noLinkMatcher.start(); int e1 = noLinkMatcher.end(); boolean insertLink; if (withLinkMatcher.find(pos)) { // found an email address with links - is it the same? int s2 = withLinkMatcher.start(); int e2 = withLinkMatcher.end(); if ((s2 < s1) && (e2 > e1)) { // same email adress - just append and continue buf.append(s.substring(pos, e2)); pos = e2; insertLink = false; // already handled } else { // not the same insertLink = true; }
if (ignoreLinks) { // Do not take existing link tags into account return substituteURL(s); } // initialisation Matcher noLinkMatcher = URL_PATTERN.matcher(s); Matcher withLinkMatcher = URL_PATTERN_INC_LINK.matcher(s); int pos = 0; // current position in s int length = s.length(); StringBuffer buf = new StringBuffer(); while (pos < length) { if (noLinkMatcher.find(pos)) { // an url - check whether its already a link int s1 = noLinkMatcher.start(); int e1 = noLinkMatcher.end(); boolean insertLink; if (withLinkMatcher.find(pos)) { // found an url with links - is it the same? int s2 = withLinkMatcher.start(); int e2 = withLinkMatcher.end(); if ((s2 < s1) && (e2 > e1)) { // same url - just append and continue buf.append(s.substring(pos, e2)); pos = e2; insertLink = false; // already handled } else { // not the same insertLink = true; }
Clone fragments detected by clone detection tool
File path: /columba-1.4-src/mail/src/main/java/org/columba/mail/parser/text/HtmlParser.java File path: /columba-1.4-src/mail/src/main/java/org/columba/mail/parser/text/HtmlParser.java
Method name: String substituteEmailAddress(String, boolean) Method name: String substituteURL(String, boolean)
Number of AST nodes: 17 Number of AST nodes: 17
1
if (ignoreLinks) {
1
if (ignoreLinks) {
2
            // Do not take existing link tags into account
2
            // Do not take existing link tags into account
3
            return substituteEmailAddress(s);
3
            return substituteURL(s);
4
        }
4
        }
5
        // initialisation
5
        // initialisation
6
        Matcher noLinkMatcher = EMAIL_PATTERN.matcher(s);
6
        Matcher noLinkMatcher = URL_PATTERN.matcher(s);
7
        Matcher withLinkMatcher = EMAIL_PATTERN_INC_LINK.matcher(s);
7
        Matcher withLinkMatcher = URL_PATTERN_INC_LINK.matcher(s);
8
        int pos = 0; // current position in s
8
        int pos = 0; // current position in s
9
        int length = s.length();
9
        int length = s.length();
10
        StringBuffer buf = new StringBuffer();
10
        StringBuffer buf = new StringBuffer();
11
        while (pos < length) {
11
        while (pos < length) {
12
            if (noLinkMatcher.find(pos)) {
12
            if (noLinkMatcher.find(pos)) {
13
                // an email adress was found - check whether its already a link
13
                // an url - check whether its already a link
14
                int s1 = noLinkMatcher.start();
14
                int s1 = noLinkMatcher.start();
15
                int e1 = noLinkMatcher.end();
15
                int e1 = noLinkMatcher.end();
16
                boolean insertLink;
16
                boolean insertLink;
17
                if (withLinkMatcher.find(pos)) {
17
                if (withLinkMatcher.find(pos)) {
18
                    // found an email address with links - is it the same?
18
                    // found an url with links - is it the same?
19
                    int s2 = withLinkMatcher.start();
19
                    int s2 = withLinkMatcher.start();
20
                    int e2 = withLinkMatcher.end();
20
                    int e2 = withLinkMatcher.end();
21
                    
22
                    if ((s2 < s1) && (e2 > e1)) {
21
                    if ((s2 < s1) && (e2 > e1)) {
23
                        // same email adress - just append and continue
22
                        // same url - just append and continue
24
                        buf.append(s.substring(pos, e2));
23
                        buf.append(s.substring(pos, e2));
25
                        pos = e2;
24
                        pos = e2;
26
                        insertLink = false; // already handled
25
                        insertLink = false; // already handled
27
                    } else {
26
                    } else {
28
                        // not the same
27
                        // not the same
29
                        insertLink = true;
28
                        insertLink = true;
30
                    }
29
                    }
Summary
Number of common nesting structure subtrees1
Number of refactorable cases1
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.1
Clones locationClones are declared in the same class
Number of node comparisons4
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements2
    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.7
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    if (ignoreLinks)
    1
    if (ignoreLinks)
    2
    return substituteEmailAddress(s);
    2
    return substituteEmailAddress(s);
    2
    return substituteURL(s);
    Differences
    Expression1Expression2Difference
    substituteEmailAddresssubstituteURLMETHOD_INVOCATION_NAME_MISMATCH
    2
    return substituteURL(s);
    Precondition Violations (0)
    Row Violation