33-1-2

Month result = null; if (s != null) { // trim whitespace from either end of the string 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." ); } } return result;
Week result = null; if (s != null) { // trim whitespace from either end of the string 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."); } } return result;

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: 23 |  | Number of AST nodes: 23

1

    Month result = null;↵

1

    Week result = null;↵

2

            if (s != null) {↵

2

            if (s != null) {↵

3

                // trim whitespace from either end of the string↵

3

                // trim whitespace from either end of the string↵

4

                s = s.trim();↵

4

                s = s.trim();↵

5

                int i = Month.findSeparator(s);↵

5

                int i = Week.findSeparator(s);↵

6

                if (i != -1) {↵

6

                if (i != -1) {↵

7

                    String s1 = s.substring(0, i).trim();↵

7

                    String s1 = s.substring(0, i).trim();↵

8

                    String s2 = s.substring(i + 1, s.length()).trim();↵

8

                    String s2 = s.substring(i + 1, s.length()).trim();↵

9

                    Year year = Month.evaluateAsYear(s1);↵

9

                    Year y = Week.evaluateAsYear(s1);↵

10

                    int month;↵

10

                    int w;↵

11

                    if (year != null) {↵

11

                    if (y != null) {↵

12

                        month = SerialDate.stringToMonthCode(s2);↵

12

                        w = Week.stringToWeek(s2);↵

13

                        if (month == -1) {↵

13

                        if (w == -1) {↵

14

                            throw new TimePeriodFormatException(↵

14

                            throw new TimePeriodFormatException(↵

15

                                "Can't evaluate the month."↵

15

                                    "Can't evaluate the ↵

16

                            );↵

16

    week.");↵

17

                        }↵

17

                        }↵

18

                        result = new Month(month, year);↵

18

                        result = new Week(w, y);↵

19

                    }↵

19

                    }↵

20

                    else {↵

20

                    else {↵

21

                        year = Month.evaluateAsYear(s2);↵

21

                        y = Week.evaluateAsYear(s2);↵

22

                        if (year != null) {↵

22

                        if (y != null) {↵

23

                            month = SerialDate.stringToMonthCode(s1);↵

23

                            w = Week.stringToWeek(s1);↵

24

                            if (month == -1) {↵

24

                            if (w == -1) {↵

25

                                throw new TimePeriodFormatException(↵

25

                                throw new TimePeriodFormatException(↵

26

                                    "Can't evaluate the month."↵

26

                                        "Can't evaluate the ↵

27

                                );↵

27

    week.");↵

28

                            }↵

28

                            }↵

29

                            result = new Month(month, year);↵

29

                            result = new Week(w, y);↵

30

                        }↵

30

                        }↵

31

                        else {↵

31

                        else {↵

32

                            throw new TimePeriodFormatException(↵

32

                            throw new TimePeriodFormatException(↵

33

                                "Can't evaluate the year."↵

33

                                    "Can't evaluate the year."↵

34

                            );↵

34

    );↵

35

                        }↵

35

                        }↵

36

                    }↵

36

                    }↵

37

                }↵

37

                }↵

38

                else {↵

38

                else {↵

39

                    throw new TimePeriodFormatException(↵

39

                    throw new TimePeriodFormatException(↵

40

                        "Could not find separator."↵

40

                            "Could not find separator."↵

41

                    );↵

41

    );↵

42

                }↵

42

                }↵

43

            }↵

43

            }↵

44

            return result;

44

            return result;

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) | 0.7
Clones location | Clones are in different classes having the same super class
Number of node comparisons | 92

1. {Non-refactorable}

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

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

   1

       Month result = null;

   1 | Month result = null;
   1 | Week result = null;

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   org.jfree.data.time.Month | org.jfree.data.time.Week | SUBCLASS_TYPE_MISMATCH
   org.jfree.data.time.Month | org.jfree.data.time.Week | SUBCLASS_TYPE_MISMATCH

   1

       Week result = null;

   2

       if (s != null)

   2

       if (s != null)

   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
   Expression1 | Expression2 | Difference
   --- | --- | ---
   org.jfree.data.time.Month | org.jfree.data.time.Week | SUBCLASS_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
   Expression1 | Expression2 | Difference
   --- | --- | ---
   year | y | VARIABLE_NAME_MISMATCH
   org.jfree.data.time.Month | org.jfree.data.time.Week | SUBCLASS_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
   Expression1 | Expression2 | Difference
   --- | --- | ---
   month | w | VARIABLE_NAME_MISMATCH

   9

       int w;

   10

       if (year != null)

   10 | if (year != null)
   10 | if (y != null)

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   year | y | VARIABLE_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
   Expression1 | Expression2 | Difference
   --- | --- | ---
   month | w | VARIABLE_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
   Expression1 | Expression2 | Difference
   --- | --- | ---
   "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
   Expression1 | Expression2 | Difference
   --- | --- | ---
   org.jfree.data.time.Month | org.jfree.data.time.Week | SUBCLASS_TYPE_MISMATCH
   org.jfree.data.time.Month | org.jfree.data.time.Week | SUBCLASS_TYPE_MISMATCH
   month | w | VARIABLE_NAME_MISMATCH
   year | y | VARIABLE_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
   Expression1 | Expression2 | Difference
   --- | --- | ---
   year | y | VARIABLE_NAME_MISMATCH
   org.jfree.data.time.Month | org.jfree.data.time.Week | SUBCLASS_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
   Expression1 | Expression2 | Difference
   --- | --- | ---
   year | y | VARIABLE_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
   Expression1 | Expression2 | Difference
   --- | --- | ---
   month | w | VARIABLE_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
   Expression1 | Expression2 | Difference
   --- | --- | ---
   "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
   Expression1 | Expression2 | Difference
   --- | --- | ---
   org.jfree.data.time.Month | org.jfree.data.time.Week | SUBCLASS_TYPE_MISMATCH
   org.jfree.data.time.Month | org.jfree.data.time.Week | SUBCLASS_TYPE_MISMATCH
   month | w | VARIABLE_NAME_MISMATCH
   year | y | VARIABLE_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.");

   23

       return result;

   23 | return result;
   23 | return result;

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   org.jfree.data.time.Month | org.jfree.data.time.Week | SUBCLASS_TYPE_MISMATCH

   23

       return result;

   Precondition Violations (12)
   Row | Violation
   --- | ---
   1 | 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)
   2 | 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)
   3 | 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
   4 | 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
   5 | Expression new Month(month,year) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   6 | Expression new Week(w,y) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   7 | 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 | 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
   9 | 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
   10 | Expression new Month(month,year) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   11 | Expression new Week(w,y) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   12 | Clone fragment #1 returns variables s2, month, s1 , while Clone fragment #2 returns variables s2, w, s1