343-1-2

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, 26); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 15); 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(); assertTrue( "test2", value == (900000 * 34 + 900000) && date.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, 26); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 30); 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(); assertTrue( "test2", value == (900000 * 34 + 900000 * 2) && date.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 test2()` |  | Method name: `void test3()`
Number of AST nodes: 19 |  | Number of AST nodes: 19

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, 26);↵

6

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

7

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

7

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

8

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

8

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

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

                     ↵

13

            SegmentedTimeline timeline = getTimeline();      ↵

13

            SegmentedTimeline timeline = getTimeline();      ↵

14

            long value = timeline.toTimelineValue(date);   ↵

14

            long value = timeline.toTimelineValue(date);   ↵

15

            long ms = timeline.toMillisecond(value);↵

15

            long ms = timeline.toMillisecond(value);↵

16

          ↵

16

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

17

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

17

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

18

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

18

            Date reverted = cal2.getTime();↵

19

            Date reverted = cal2.getTime();↵

19

            assertTrue(↵

20

            assertTrue(↵

20

                "test2", value == (900000 * 34 + 900000) ↵

21

                "test2", value == (900000 * 34 + 900000 * 2) ↵

21

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

22

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

22

            );↵

23

            );↵

23

            TimeZone.setDefault(savedZone);

24

            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 | 186

1. {Refactorable}

   Mapping Summary
   Number of mapped statements | 19
   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, 26);

   6

       cal.set(Calendar.DAY_OF_MONTH, 26);

   7

       cal.set(Calendar.HOUR_OF_DAY, 9);

   7

       cal.set(Calendar.HOUR_OF_DAY, 9);

   8

       cal.set(Calendar.MINUTE, 15);

   8 | cal.set(Calendar.MINUTE, 15);
   8 | cal.set(Calendar.MINUTE, 30);

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   15 | 30 | LITERAL_VALUE_MISMATCH

   8

       cal.set(Calendar.MINUTE, 30);

   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

       assertTrue("test2", value == (900000 * 34 + 900000) && date.getTime() == reverted.getTime());

   18 | assertTrue("test2", value == (900000 * 34 + 900000) && date.getTime() == reverted.getTime());
   18 | assertTrue("test2", value == (900000 * 34 + 900000 * 2) && date.getTime() == reverted.getTime());

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   900000 | 900000 * 2 | INFIX_RIGHT_OPERAND_MISMATCH

   18

       assertTrue("test2", value == (900000 * 34 + 900000 * 2) && date.getTime() == reverted.getTime());

   19

       TimeZone.setDefault(savedZone);

   19

       TimeZone.setDefault(savedZone);

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