if (this.week != FIRST_WEEK_IN_YEAR) { result = new Week(this.week - 1, this.year); } else { // we need to work out if the previous year has 52 or 53 weeks... if (this.year > 1900) { int yy = this.year - 1; Calendar prevYearCalendar = Calendar.getInstance(); prevYearCalendar.set(yy, Calendar.DECEMBER, 31); result = new Week(prevYearCalendar.getActualMaximum( Calendar.WEEK_OF_YEAR), yy); } else { result = null; } }
Calendar calendar = Calendar.getInstance(); calendar.set(this.year, Calendar.DECEMBER, 31); int actualMaxWeek = calendar.getActualMaximum(Calendar.WEEK_OF_YEAR); if (this.week < actualMaxWeek) { result = new Week(this.week + 1, this.year); } else { if (this.year < 9999) { result = new Week(FIRST_WEEK_IN_YEAR, this.year + 1); } else { result = null; } }
Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/src/org/jfree/data/time/Week.java File path: /jfreechart-1.0.10/src/org/jfree/data/time/Week.java
Method name: RegularTimePeriod previous() Method name: RegularTimePeriod next()
Number of AST nodes: 8 Number of AST nodes: 8
1
if (this.week != FIRST_WEEK_IN_YEAR) {
2
            result = new Week(this.week - 1, this.year
1
Calendar calendar = Calendar.getInstance();
3
);
2
            calendar.set(this.year, Calendar.DECEMBER, 31);
4
        }
3
        
5
        else {
4
    
6
            // we need to work out if the previous year has 52 or 53 weeks...
5
int actualMaxWeek 
6
                = calendar.getActualMaximum(Calendar.WEEK_OF_YEAR);
7
            if (this.year &gt; 1900) {
7
            if (this.week &lt; actualMaxWeek) {
8
                int yy = this.year - 1;
8
                result = new Week(this.week + 1, this.year);
9
            
9
            }
10
    Calendar prevYearCalendar = Calendar.getInstance();
10
            else {
11
                prevYearCalendar.set(yy, Calendar.DECEMBER, 31);
11
                
12
                result = new Week(prevYearCalendar.getActualMaximum(
13
                        Calendar.
12
if (this.year < 9999) {
14
WEEK_OF_YEAR), yy);
13
                    result = new Week(FIRST_WEEK_IN_YEAR, 
14
this.year + 1);
15
            }
15
                }
16
            else {
16
                else {
17
                result = null;
17
                    result = null;
18
            }
18
            
19
    }
19
        }
20
            }
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)0.4
Clones locationClones are declared in the same class
Number of node comparisons22
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements5
    Number of unmapped statements in the first code fragment3
    Number of unmapped statements in the second code fragment3
    Time elapsed for statement mapping (ms)3.3
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
                                                                                            
    4
    Calendar calendar = Calendar.getInstance();
    Preondition Violations
    Unmatched statement Calendar calendar=Calendar.getInstance(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4
    Calendar calendar = Calendar.getInstance();
                                                                                                    
    5
    calendar.set(this.year, Calendar.DECEMBER, 31);
    Preondition Violations
    Unmatched statement calendar.set(this.year,Calendar.DECEMBER,31); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    5
    calendar.set(this.year, Calendar.DECEMBER, 31);
                                                                                                                                                
    6
    int actualMaxWeek = calendar.getActualMaximum(Calendar.WEEK_OF_YEAR);
    2
    if (this.week != FIRST_WEEK_IN_YEAR)
    2
    if (this.week != FIRST_WEEK_IN_YEAR)
    7
    if (this.week < actualMaxWeek)
    Differences
    Expression1Expression2Difference
    FIRST_WEEK_IN_YEARactualMaxWeekVARIABLE_NAME_MISMATCH
    !=<OPERATOR_MISMATCH
    Preondition Violations
    Expression actualMaxWeek cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression this.week < actualMaxWeek cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7
    if (this.week < actualMaxWeek)
    3
    result = new Week(this.week - 1, this.year);
    3
    result = new Week(this.week - 1, this.year);
    8
    result = new Week(this.week + 1, this.year);
    Differences
    Expression1Expression2Difference
    -+OPERATOR_MISMATCH
    Preondition Violations
    Expression this.week - 1 cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression this.week + 1 cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8
    result = new Week(this.week + 1, this.year);
    else
    else
    4
    if (this.year > 1900)
    4
    if (this.year > 1900)
    9
    if (this.year < 9999)
    Differences
    Expression1Expression2Difference
    19009999LITERAL_VALUE_MISMATCH
    ><OPERATOR_MISMATCH
    9
    if (this.year < 9999)
    5
    int yy = this.year - 1;
    5
    int yy = this.year - 1;
    Preondition Violations
    Unmatched statement int yy=this.year - 1; cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                    
    6
    Calendar prevYearCalendar = Calendar.getInstance();
    6
    Calendar prevYearCalendar = Calendar.getInstance();
    Preondition Violations
    Unmatched statement Calendar prevYearCalendar=Calendar.getInstance(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                                            
    7
    prevYearCalendar.set(yy, Calendar.DECEMBER, 31);
    7
    prevYearCalendar.set(yy, Calendar.DECEMBER, 31);
    Preondition Violations
    Unmatched statement prevYearCalendar.set(yy,Calendar.DECEMBER,31); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                                      
    8
    result = new Week(prevYearCalendar.getActualMaximum(Calendar.WEEK_OF_YEAR), yy);
    8
    result = new Week(prevYearCalendar.getActualMaximum(Calendar.WEEK_OF_YEAR), yy);
    10
    result = new Week(FIRST_WEEK_IN_YEAR, this.year + 1);
    Differences
    Expression1Expression2Difference
    prevYearCalendar.getActualMaximum(Calendar.WEEK_OF_YEAR)FIRST_WEEK_IN_YEARTYPE_COMPATIBLE_REPLACEMENT
    yythis.year + 1TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression prevYearCalendar.getActualMaximum(Calendar.WEEK_OF_YEAR) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression yy cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression this.year + 1 cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10
    result = new Week(FIRST_WEEK_IN_YEAR, this.year + 1);
    else
    else
    9
    result = null;
    11
    result = null;
    Precondition Violations (12)
    Row Violation
    1Unmatched statement Calendar calendar=Calendar.getInstance(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement calendar.set(this.year,Calendar.DECEMBER,31); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Expression actualMaxWeek cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression this.week < actualMaxWeek cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5Expression this.week - 1 cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression this.week + 1 cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Unmatched statement int yy=this.year - 1; cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    8Unmatched statement Calendar prevYearCalendar=Calendar.getInstance(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    9Unmatched statement prevYearCalendar.set(yy,Calendar.DECEMBER,31); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    10Expression prevYearCalendar.getActualMaximum(Calendar.WEEK_OF_YEAR) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression yy cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Expression this.year + 1 cannot be parameterized, because it has dependencies to/from statements that will be extracted