201-2-3

TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 28); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); Calendar expectedReverted = Calendar.getInstance(Locale.UK); expectedReverted.set(Calendar.YEAR, 2004); expectedReverted.set(Calendar.MONTH, Calendar.MARCH); expectedReverted.set(Calendar.DAY_OF_MONTH, 29); expectedReverted.set(Calendar.HOUR_OF_DAY, 9); expectedReverted.set(Calendar.MINUTE, 0); expectedReverted.set(Calendar.SECOND, 0); expectedReverted.set(Calendar.MILLISECOND, 0); assertTrue( "test6", value == (900000 * 34 * 2) && expectedReverted.getTime().getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone);
TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 29); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); Calendar expectedReverted = Calendar.getInstance(); expectedReverted.set(Calendar.YEAR, 2004); expectedReverted.set(Calendar.MONTH, Calendar.MARCH); expectedReverted.set(Calendar.DAY_OF_MONTH, 29); expectedReverted.set(Calendar.HOUR_OF_DAY, 9); expectedReverted.set(Calendar.MINUTE, 0); expectedReverted.set(Calendar.SECOND, 0); expectedReverted.set(Calendar.MILLISECOND, 0); assertTrue( "test7", value == (900000 * 34 * 2) && expectedReverted.getTime().getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone);

Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/tests/org/jfree/chart/axis/junit/SegmentedTimelineTests2.java |  | File path: /jfreechart-1.0.10/tests/org/jfree/chart/axis/junit/SegmentedTimelineTests2.java
Method name: `void test6()` |  | Method name: `void test7()`
Number of AST nodes: 27 |  | Number of AST nodes: 27

1

    TimeZone savedZone = TimeZone.getDefault();↵

1

    TimeZone savedZone = TimeZone.getDefault();↵

2

            TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));↵

2

            TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));↵

3

            Calendar cal = Calendar.getInstance(Locale.UK);↵

3

            Calendar cal = Calendar.getInstance(Locale.UK);↵

4

            cal.set(Calendar.YEAR, 2004);↵

4

            cal.set(Calendar.YEAR, 2004);↵

5

            cal.set(Calendar.MONTH, Calendar.MARCH);↵

5

            cal.set(Calendar.MONTH, Calendar.MARCH);↵

6

            cal.set(Calendar.DAY_OF_MONTH, 28);↵

6

            cal.set(Calendar.DAY_OF_MONTH, 29);↵

7

            cal.set(Calendar.HOUR_OF_DAY, 9);↵

7

            cal.set(Calendar.HOUR_OF_DAY, 9);↵

8

            cal.set(Calendar.MINUTE, 0);↵

8

            cal.set(Calendar.MINUTE, 0);↵

9

            cal.set(Calendar.SECOND, 0);↵

9

            cal.set(Calendar.SECOND, 0);↵

10

            cal.set(Calendar.MILLISECOND, 0);↵

10

            cal.set(Calendar.MILLISECOND, 0);↵

11

            Date date = cal.getTime();↵

11

            Date date = cal.getTime();↵

12

                      ↵

12

            SegmentedTimeline timeline = getTimeline();      ↵

13

            SegmentedTimeline timeline = getTimeline();↵

13

            long value = timeline.toTimelineValue(date);   ↵

14

            long value = timeline.toTimelineValue(date);   ↵

14

            long ms = timeline.toMillisecond(value);↵

15

            long ms = timeline.toMillisecond(value);↵

16

          ↵

15

            Calendar cal2 = Calendar.getInstance(Locale.UK);↵

17

            Calendar cal2 = Calendar.getInstance(Locale.UK);↵

16

            cal2.setTime(new Date(ms));↵

18

            cal2.setTime(new Date(ms));↵

17

            Date reverted = cal2.getTime();↵

19

            Date reverted = cal2.getTime();↵

18

          ↵

20

          ↵

19

            Calendar expectedReverted = Calendar.getInstance(Locale.UK);↵

21

            Calendar expectedReverted = Calendar.getInstance();↵

20

            expectedReverted.set(Calendar.YEAR, 2004);↵

22

            expectedReverted.set(Calendar.YEAR, 2004);↵

21

            expectedReverted.set(Calendar.MONTH, Calendar.MARCH);↵

23

            expectedReverted.set(Calendar.MONTH, Calendar.MARCH);↵

22

            expectedReverted.set(Calendar.DAY_OF_MONTH, 29);↵

24

            expectedReverted.set(Calendar.DAY_OF_MONTH, 29);↵

23

            expectedReverted.set(Calendar.HOUR_OF_DAY, 9);↵

25

            expectedReverted.set(Calendar.HOUR_OF_DAY, 9);↵

24

            expectedReverted.set(Calendar.MINUTE, 0);↵

26

            expectedReverted.set(Calendar.MINUTE, 0);↵

25

            expectedReverted.set(Calendar.SECOND, 0);↵

27

            expectedReverted.set(Calendar.SECOND, 0);↵

26

            expectedReverted.set(Calendar.MILLISECOND, 0);↵

28

            expectedReverted.set(Calendar.MILLISECOND, 0);↵

27

          ↵

29

          ↵

28

            assertTrue(↵

30

            assertTrue(↵

29

                "test6", value == (900000 * 34 * 2) ↵

31

                "test7", value == (900000 * 34 * 2) ↵

30

                && expectedReverted.getTime().getTime() == reverted.getTime()↵

32

                && expectedReverted.getTime().getTime() == reverted.getTime()↵

31

            );↵

33

            );↵

32

            TimeZone.setDefault(savedZone);

34

            TimeZone.setDefault(savedZone);

See real code fragment |  | See real code fragment

Summary
Number of common nesting structure subtrees | 1
Number of refactorable cases | 1
Number of non-refactorable cases | 0
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.0
Clones location | Clones are declared in the same class
Number of node comparisons | 377

1. {Refactorable}

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

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

   1

       TimeZone savedZone = TimeZone.getDefault();

   1

       TimeZone savedZone = TimeZone.getDefault();

   2

       TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));

   2

       TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));

   3

       Calendar cal = Calendar.getInstance(Locale.UK);

   3

       Calendar cal = Calendar.getInstance(Locale.UK);

   4

       cal.set(Calendar.YEAR, 2004);

   4

       cal.set(Calendar.YEAR, 2004);

   5

       cal.set(Calendar.MONTH, Calendar.MARCH);

   5

       cal.set(Calendar.MONTH, Calendar.MARCH);

   6

       cal.set(Calendar.DAY_OF_MONTH, 28);

   6 | cal.set(Calendar.DAY_OF_MONTH, 28);
   6 | cal.set(Calendar.DAY_OF_MONTH, 29);

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   28 | 29 | LITERAL_VALUE_MISMATCH

   6

       cal.set(Calendar.DAY_OF_MONTH, 29);

   7

       cal.set(Calendar.HOUR_OF_DAY, 9);

   7

       cal.set(Calendar.HOUR_OF_DAY, 9);

   8

       cal.set(Calendar.MINUTE, 0);

   8

       cal.set(Calendar.MINUTE, 0);

   9

       cal.set(Calendar.SECOND, 0);

   9

       cal.set(Calendar.SECOND, 0);

   10

       cal.set(Calendar.MILLISECOND, 0);

   10

       cal.set(Calendar.MILLISECOND, 0);

   11

       Date date = cal.getTime();

   11

       Date date = cal.getTime();

   12

       SegmentedTimeline timeline = getTimeline();

   12

       SegmentedTimeline timeline = getTimeline();

   13

       long value = timeline.toTimelineValue(date);

   13

       long value = timeline.toTimelineValue(date);

   14

       long ms = timeline.toMillisecond(value);

   14

       long ms = timeline.toMillisecond(value);

   15

       Calendar cal2 = Calendar.getInstance(Locale.UK);

   15

       Calendar cal2 = Calendar.getInstance(Locale.UK);

   16

       cal2.setTime(new Date(ms));

   16

       cal2.setTime(new Date(ms));

   17

       Date reverted = cal2.getTime();

   17

       Date reverted = cal2.getTime();

   18

       Calendar expectedReverted = Calendar.getInstance(Locale.UK);

   18 | Calendar expectedReverted = Calendar.getInstance(Locale.UK);
   18 | Calendar expectedReverted = Calendar.getInstance();

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   Calendar.getInstance(Locale.UK) | Calendar.getInstance() | ARGUMENT_NUMBER_MISMATCH

   18

       Calendar expectedReverted = Calendar.getInstance();

   19

       expectedReverted.set(Calendar.YEAR, 2004);

   19

       expectedReverted.set(Calendar.YEAR, 2004);

   20

       expectedReverted.set(Calendar.MONTH, Calendar.MARCH);

   20

       expectedReverted.set(Calendar.MONTH, Calendar.MARCH);

   21

       expectedReverted.set(Calendar.DAY_OF_MONTH, 29);

   21

       expectedReverted.set(Calendar.DAY_OF_MONTH, 29);

   22

       expectedReverted.set(Calendar.HOUR_OF_DAY, 9);

   22

       expectedReverted.set(Calendar.HOUR_OF_DAY, 9);

   23

       expectedReverted.set(Calendar.MINUTE, 0);

   23

       expectedReverted.set(Calendar.MINUTE, 0);

   24

       expectedReverted.set(Calendar.SECOND, 0);

   24

       expectedReverted.set(Calendar.SECOND, 0);

   25

       expectedReverted.set(Calendar.MILLISECOND, 0);

   25

       expectedReverted.set(Calendar.MILLISECOND, 0);

   26

       assertTrue("test6", value == (900000 * 34 * 2) && expectedReverted.getTime().getTime() == reverted.getTime());

   26 | assertTrue("test6", value == (900000 * 34 * 2) && expectedReverted.getTime().getTime() == reverted.getTime());
   26 | assertTrue("test7", value == (900000 * 34 * 2) && expectedReverted.getTime().getTime() == reverted.getTime());

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   "test6" | "test7" | LITERAL_VALUE_MISMATCH

   26

       assertTrue("test7", value == (900000 * 34 * 2) && expectedReverted.getTime().getTime() == reverted.getTime());

   27

       TimeZone.setDefault(savedZone);

   27

       TimeZone.setDefault(savedZone);

   Precondition Violations (0)
   Row | Violation
   --- | ---