s = s.trim(); int i = Month.findSeparator(s); if (i != -1) { String s1 = s.substring(0, i).trim(); String s2 = s.substring(i + 1, s.length()).trim(); Year year = Month.evaluateAsYear(s1); int month; if (year != null) { month = SerialDate.stringToMonthCode(s2); if (month == -1) { throw new TimePeriodFormatException( "Can't evaluate the month." ); } result = new Month(month, year); } else { year = Month.evaluateAsYear(s2); if (year != null) { month = SerialDate.stringToMonthCode(s1); if (month == -1) { throw new TimePeriodFormatException( "Can't evaluate the month." ); } result = new Month(month, year); } else { throw new TimePeriodFormatException( "Can't evaluate the year." ); } } } else { throw new TimePeriodFormatException( "Could not find separator." ); }
s = s.trim(); int i = Week.findSeparator(s); if (i != -1) { String s1 = s.substring(0, i).trim(); String s2 = s.substring(i + 1, s.length()).trim(); Year y = Week.evaluateAsYear(s1); int w; if (y != null) { w = Week.stringToWeek(s2); if (w == -1) { throw new TimePeriodFormatException( "Can't evaluate the week."); } result = new Week(w, y); } else { y = Week.evaluateAsYear(s2); if (y != null) { w = Week.stringToWeek(s1); if (w == -1) { throw new TimePeriodFormatException( "Can't evaluate the week."); } result = new Week(w, y); } else { throw new TimePeriodFormatException( "Can't evaluate the year."); } } } else { throw new TimePeriodFormatException( "Could not find separator."); }
Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/src/org/jfree/data/time/Month.java File path: /jfreechart-1.0.10/src/org/jfree/data/time/Week.java
Method name: Month parseMonth(String) Method name: Week parseWeek(String)
Number of AST nodes: 20 Number of AST nodes: 20
1
s = s.trim();
1
s = s.trim();
2
            int i = Month.findSeparator(s);
2
            int i = Week.findSeparator(s);
3
            if (i != -1) {
3
            if (i != -1) {
4
                String s1 = s.substring(0, i).trim();
4
                String s1 = s.substring(0, i).trim();
5
                String s2 = s.substring(i + 1, s.length()).trim();
5
                String s2 = s.substring(i + 1, s.length()).trim();
6
                Year year = Month.evaluateAsYear(s1);
6
                Year y = Week.evaluateAsYear(s1);
7
                int month;
7
                int w;
8
                if (year != null) {
8
                if (y != null) {
9
                    month = SerialDate.stringToMonthCode(s2);
9
                    w = Week.stringToWeek(s2);
10
                    if (month == -1) {
10
                    if (w == -1) {
11
                        throw new TimePeriodFormatException(
11
                        throw new TimePeriodFormatException(
12
                            "Can't evaluate the month."
12
                                "Can't evaluate the 
13
                        );
13
week.");
14
                    }
14
                    }
15
                    result = new Month(month, year);
15
                    result = new Week(w, y);
16
                }
16
                }
17
                else {
17
                else {
18
                    year = Month.evaluateAsYear(s2);
18
                    y = Week.evaluateAsYear(s2);
19
                    if (year != null) {
19
                    if (y != null) {
20
                        month = SerialDate.stringToMonthCode(s1);
20
                        w = Week.stringToWeek(s1);
21
                        if (month == -1) {
21
                        if (w == -1) {
22
                            throw new TimePeriodFormatException(
22
                            throw new TimePeriodFormatException(
23
                                "Can't evaluate the month."
23
                                    "Can't evaluate the 
24
                            );
24
week.");
25
                        }
25
                        }
26
                        result = new Month(month, year);
26
                        result = new Week(w, y);
27
                    }
27
                    }
28
                    else {
28
                    else {
29
                        throw new TimePeriodFormatException(
29
                        throw new TimePeriodFormatException(
30
                            "Can't evaluate the year."
30
                                "Can't evaluate the year."
31
                        );
31
);
32
                    }
32
                    }
33
                }
33
                }
34
            }
34
            }
35
            else {
35
            else {
36
                throw new TimePeriodFormatException(
36
                throw new TimePeriodFormatException(
37
                    "Could not find separator."
37
                        "Could not find separator."
38
                );
38
);
39
            }
39
            }
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)1.3
Clones locationClones are in different classes having the same super class
Number of node comparisons84
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements18
    Number of unmapped statements in the first code fragment2
    Number of unmapped statements in the second code fragment2
    Time elapsed for statement mapping (ms)9.1
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    3
    s = s.trim();
    3
    s = s.trim();
    4
    int i = Month.findSeparator(s);
    4
    int i = Month.findSeparator(s);
    4
    int i = Week.findSeparator(s);
    Differences
    Expression1Expression2Difference
    org.jfree.data.time.Monthorg.jfree.data.time.WeekSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression Month cannot be unified with expression Week , because common superclass org.jfree.data.time.RegularTimePeriod does not declare member(s) private static int findSeparator(java.lang.String)
    4
    int i = Week.findSeparator(s);
    5
    if (i != -1)
    5
    if (i != -1)
    6
    String s1 = s.substring(0, i).trim();
    6
    String s1 = s.substring(0, i).trim();
    7
    String s2 = s.substring(i + 1, s.length()).trim();
    7
    String s2 = s.substring(i + 1, s.length()).trim();
    8
    Year year = Month.evaluateAsYear(s1);
    8
    Year year = Month.evaluateAsYear(s1);
    8
    Year y = Week.evaluateAsYear(s1);
    Differences
    Expression1Expression2Difference
    yearyVARIABLE_NAME_MISMATCH
    org.jfree.data.time.Monthorg.jfree.data.time.WeekSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression Month cannot be unified with expression Week , because common superclass org.jfree.data.time.RegularTimePeriod does not declare member(s) private static org.jfree.data.time.Year evaluateAsYear(java.lang.String)
    8
    Year y = Week.evaluateAsYear(s1);
    9
    int month;
    9
    int month;
    9
    int w;
    Differences
    Expression1Expression2Difference
    monthwVARIABLE_NAME_MISMATCH
    9
    int w;
    10
    if (year != null)
    10
    if (year != null)
    10
    if (y != null)
    Differences
    Expression1Expression2Difference
    yearyVARIABLE_NAME_MISMATCH
    10
    if (y != null)
                                                            
    11
    w = Week.stringToWeek(s2);
    Preondition Violations
    Unmatched statement w=Week.stringToWeek(s2); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11
    w = Week.stringToWeek(s2);
    11
    month = SerialDate.stringToMonthCode(s2);
    11
    month = SerialDate.stringToMonthCode(s2);
    Preondition Violations
    Unmatched statement month=SerialDate.stringToMonthCode(s2); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                          
    12
    if (month == -1)
    12
    if (month == -1)
    12
    if (w == -1)
    Differences
    Expression1Expression2Difference
    monthwVARIABLE_NAME_MISMATCH
    12
    if (w == -1)
    13
    throw new TimePeriodFormatException("Can't evaluate the month.");
    13
    throw new TimePeriodFormatException("Can't evaluate the month.");
    13
    throw new TimePeriodFormatException("Can't evaluate the week.");
    Differences
    Expression1Expression2Difference
    "Can't evaluate the month.""Can't evaluate the week."LITERAL_VALUE_MISMATCH
    13
    throw new TimePeriodFormatException("Can't evaluate the week.");
    14
    result = new Month(month, year);
    14
    result = new Month(month, year);
    14
    result = new Week(w, y);
    Differences
    Expression1Expression2Difference
    org.jfree.data.time.Monthorg.jfree.data.time.WeekSUBCLASS_TYPE_MISMATCH
    org.jfree.data.time.Monthorg.jfree.data.time.WeekSUBCLASS_TYPE_MISMATCH
    monthwVARIABLE_NAME_MISMATCH
    yearyVARIABLE_NAME_MISMATCH
    Preondition Violations
    Expression new Month(month,year) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression new Week(w,y) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14
    result = new Week(w, y);
    else
    else
    15
    year = Month.evaluateAsYear(s2);
    15
    year = Month.evaluateAsYear(s2);
    15
    y = Week.evaluateAsYear(s2);
    Differences
    Expression1Expression2Difference
    yearyVARIABLE_NAME_MISMATCH
    org.jfree.data.time.Monthorg.jfree.data.time.WeekSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression Month cannot be unified with expression Week , because common superclass org.jfree.data.time.RegularTimePeriod does not declare member(s) private static org.jfree.data.time.Year evaluateAsYear(java.lang.String)
    15
    y = Week.evaluateAsYear(s2);
    16
    if (year != null)
    16
    if (year != null)
    16
    if (y != null)
    Differences
    Expression1Expression2Difference
    yearyVARIABLE_NAME_MISMATCH
    16
    if (y != null)
                                                            
    17
    w = Week.stringToWeek(s1);
    Preondition Violations
    Unmatched statement w=Week.stringToWeek(s1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    17
    w = Week.stringToWeek(s1);
    17
    month = SerialDate.stringToMonthCode(s1);
    17
    month = SerialDate.stringToMonthCode(s1);
    Preondition Violations
    Unmatched statement month=SerialDate.stringToMonthCode(s1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                          
    18
    if (month == -1)
    18
    if (month == -1)
    18
    if (w == -1)
    Differences
    Expression1Expression2Difference
    monthwVARIABLE_NAME_MISMATCH
    18
    if (w == -1)
    19
    throw new TimePeriodFormatException("Can't evaluate the month.");
    19
    throw new TimePeriodFormatException("Can't evaluate the month.");
    19
    throw new TimePeriodFormatException("Can't evaluate the week.");
    Differences
    Expression1Expression2Difference
    "Can't evaluate the month.""Can't evaluate the week."LITERAL_VALUE_MISMATCH
    19
    throw new TimePeriodFormatException("Can't evaluate the week.");
    20
    result = new Month(month, year);
    20
    result = new Month(month, year);
    20
    result = new Week(w, y);
    Differences
    Expression1Expression2Difference
    org.jfree.data.time.Monthorg.jfree.data.time.WeekSUBCLASS_TYPE_MISMATCH
    org.jfree.data.time.Monthorg.jfree.data.time.WeekSUBCLASS_TYPE_MISMATCH
    monthwVARIABLE_NAME_MISMATCH
    yearyVARIABLE_NAME_MISMATCH
    Preondition Violations
    Expression new Month(month,year) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression new Week(w,y) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    20
    result = new Week(w, y);
    else
    else
    21
    throw new TimePeriodFormatException("Can't evaluate the year.");
    21
    throw new TimePeriodFormatException("Can't evaluate the year.");
    else
    else
    22
    throw new TimePeriodFormatException("Could not find separator.");
    22
    throw new TimePeriodFormatException("Could not find separator.");
    Precondition Violations (12)
    Row Violation
    1Expression Month cannot be unified with expression Week , because common superclass org.jfree.data.time.RegularTimePeriod does not declare member(s) private static int findSeparator(java.lang.String)
    2Expression Month cannot be unified with expression Week , because common superclass org.jfree.data.time.RegularTimePeriod does not declare member(s) private static org.jfree.data.time.Year evaluateAsYear(java.lang.String)
    3Unmatched statement w=Week.stringToWeek(s2); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched statement month=SerialDate.stringToMonthCode(s2); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Expression new Month(month,year) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression new Week(w,y) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression Month cannot be unified with expression Week , because common superclass org.jfree.data.time.RegularTimePeriod does not declare member(s) private static org.jfree.data.time.Year evaluateAsYear(java.lang.String)
    8Unmatched statement w=Week.stringToWeek(s1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9Unmatched statement month=SerialDate.stringToMonthCode(s1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10Expression new Month(month,year) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression new Week(w,y) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Clone fragment #1 returns variables s2, month, s1, result , while Clone fragment #2 returns variables s2, w, s1, result