312-3-6

DefaultPieDataset d = new DefaultPieDataset(); d.setValue("A", 1.0); d.setValue("B", 2.0); assertEquals("A", d.getKey(0)); assertEquals("B", d.getKey(1)); boolean pass = false; try { d.getKey(-1); } catch (IndexOutOfBoundsException e) { pass = true; } assertTrue(pass); pass = false; try { d.getKey(2); } catch (IndexOutOfBoundsException e) { pass = true; } assertTrue(pass);
KeyedObjects2D data = new KeyedObjects2D(); data.setObject("Obj1", "R1", "C1"); data.setObject("Obj2", "R2", "C2"); data.removeRow("R2"); assertEquals(1, data.getRowCount()); assertEquals("Obj1", data.getObject(0, 0)); // try unknown row key boolean pass = false; try { data.removeRow("XXX"); } catch (UnknownKeyException e) { pass = true; } assertTrue(pass); // try null row key pass = false; try { data.removeRow(null); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass);

Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/tests/org/jfree/data/general/junit/DefaultPieDatasetTests.java |  | File path: /jfreechart-1.0.10/tests/org/jfree/data/junit/KeyedObjects2DTests.java
Method name: `void testGetKey()` |  | Method name: `void testRemoveRowByKey()`
Number of AST nodes: 13 |  | Number of AST nodes: 14

1

    DefaultPieDataset d = new DefaultPieDataset();↵

1

    KeyedObjects2D data = new KeyedObjects2D();↵

2

            d.setValue("A", 1.0);↵

2

            data.setObject("Obj1", "R1", "C1");↵

3

            d.setValue("B", 2.0↵

3

            data.setObject("Obj2", "R2", "C2");↵

4

    );↵

4

            data.removeRow("R2");↵

5

            assertEquals("A", d.getKey(0));↵

5

            assertEquals(1, data.getRowCount());↵

6

            assertEquals("B", d.getKey(1));↵

6

            assertEquals("Obj1", data.getObject(0, 0));↵

7

            ↵

7

            ↵

8

            // try unknown row key↵

8

            boolean pass = false;↵

9

            boolean pass = false;↵

9

            try {↵

10

            try {↵

10

                d.getKey(-1);↵

11

                data.removeRow("XXX");↵

11

            }↵

12

            }↵

12

            catch (IndexOutOfBoundsException e) {↵

13

            catch (UnknownKeyException e) {↵

13

                pass = true;↵

14

                pass = true;↵

14

            }↵

15

            }↵

15

            assertTrue(pass);↵

16

            assertTrue(pass);↵

16

            ↵

17

            ↵

18

            // try null row key↵

17

            pass = false;↵

19

            pass = false;↵

18

            try {↵

20

            try {↵

19

                d.getKey(2);↵

21

                data.removeRow(null);↵

20

            }↵

22

            }↵

21

            catch (IndexOutOfBoundsException e) {↵

23

            catch (IllegalArgumentException e) {↵

22

                pass = true;↵

24

                pass = true;↵

23

            }↵

25

            }↵

24

            assertTrue(pass);

26

            assertTrue(pass);

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.3
Clones location | Clones are in different classes having the same super class
Number of node comparisons | 73

1. {Non-refactorable}

   Mapping Summary
   Number of mapped statements | 8
   Number of unmapped statements in the first code fragment | 5
   Number of unmapped statements in the second code fragment | 6
   Time elapsed for statement mapping (ms) | 8.6
   Clone type | Type 3

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

   1

       KeyedObjects2D data = new KeyedObjects2D();

   1

       DefaultPieDataset d = new DefaultPieDataset();

   2

       d.setValue("A", 1.0);

   3

       d.setValue("B", 2.0);

   4

       assertEquals("A", d.getKey(0));

   4 | assertEquals("A", d.getKey(0));
   3 | data.setObject("Obj2", "R2", "C2");

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   assertEquals | setObject | METHOD_INVOCATION_NAME_MISMATCH
   assertEquals("A",d.getKey(0)) | data.setObject("Obj2","R2","C2") | ARGUMENT_NUMBER_MISMATCH
   | data | MISSING_METHOD_INVOCATION_EXPRESSION

   Preondition Violations
   Expression data.setObject("Obj2","R2","C2") cannot be parameterized, because it has dependencies to/from statements that will be extracted
   Expression assertEquals("A",d.getKey(0)) is a void method call, and thus it cannot be parameterized
   Expression data.setObject("Obj2","R2","C2") is a void method call, and thus it cannot be parameterized
   Expression data.setObject("Obj2","R2","C2") cannot be parameterized, because it has dependencies to/from statements that will be extracted
   Expression assertEquals("A",d.getKey(0)) is a void method call, and thus it cannot be parameterized
   Expression data.setObject("Obj2","R2","C2") is a void method call, and thus it cannot be parameterized

   3

       data.setObject("Obj2", "R2", "C2");

   5

       assertEquals("B", d.getKey(1));

   5 | assertEquals("B", d.getKey(1));
   2 | data.setObject("Obj1", "R1", "C1");

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   assertEquals | setObject | METHOD_INVOCATION_NAME_MISMATCH
   assertEquals("B",d.getKey(1)) | data.setObject("Obj1","R1","C1") | ARGUMENT_NUMBER_MISMATCH
   | data | MISSING_METHOD_INVOCATION_EXPRESSION

   Preondition Violations
   Expression assertEquals("B",d.getKey(1)) is a void method call, and thus it cannot be parameterized
   Expression data.setObject("Obj1","R1","C1") is a void method call, and thus it cannot be parameterized
   Expression assertEquals("B",d.getKey(1)) is a void method call, and thus it cannot be parameterized
   Expression data.setObject("Obj1","R1","C1") is a void method call, and thus it cannot be parameterized

   2

       data.setObject("Obj1", "R1", "C1");

   4 | data.removeRow("R2");

   Preondition Violations
   Unmatched statement data.removeRow("R2"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted

   4

       data.removeRow("R2");

   5

       assertEquals(1, data.getRowCount());

   6 | assertEquals("Obj1", data.getObject(0, 0));

   Preondition Violations
   Unmatched statement assertEquals("Obj1",data.getObject(0,0)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted

   6

       assertEquals("Obj1", data.getObject(0, 0));

   6

       boolean pass = false;

   7

       boolean pass = false;

   7

       try

   7 | try
   8 | try

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   java.lang.IndexOutOfBoundsException | org.jfree.data.UnknownKeyException | SUBCLASS_TYPE_MISMATCH
   java.lang.IndexOutOfBoundsException | org.jfree.data.UnknownKeyException | SUBCLASS_TYPE_MISMATCH

   8

       try

   8

       d.getKey(-1);

   9

       data.removeRow("XXX");

   9

       assertTrue(pass);

   10

       assertTrue(pass);

   10

       pass = false;

   11

       pass = false;

   11

       try

   11 | try
   12 | try

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   java.lang.IndexOutOfBoundsException | java.lang.IllegalArgumentException | SUBCLASS_TYPE_MISMATCH
   java.lang.IndexOutOfBoundsException | java.lang.IllegalArgumentException | SUBCLASS_TYPE_MISMATCH

   12

       try

   12

       d.getKey(2);

   13

       data.removeRow(null);

   13

       assertTrue(pass);

   14

       assertTrue(pass);

   Precondition Violations (12)
   Row | Violation
   --- | ---
   1 | Expression data.setObject("Obj2","R2","C2") cannot be parameterized, because it has dependencies to/from statements that will be extracted
   2 | Expression assertEquals("A",d.getKey(0)) is a void method call, and thus it cannot be parameterized
   3 | Expression data.setObject("Obj2","R2","C2") is a void method call, and thus it cannot be parameterized
   4 | Expression data.setObject("Obj2","R2","C2") cannot be parameterized, because it has dependencies to/from statements that will be extracted
   5 | Expression assertEquals("A",d.getKey(0)) is a void method call, and thus it cannot be parameterized
   6 | Expression data.setObject("Obj2","R2","C2") is a void method call, and thus it cannot be parameterized
   7 | Expression assertEquals("B",d.getKey(1)) is a void method call, and thus it cannot be parameterized
   8 | Expression data.setObject("Obj1","R1","C1") is a void method call, and thus it cannot be parameterized
   9 | Expression assertEquals("B",d.getKey(1)) is a void method call, and thus it cannot be parameterized
   10 | Expression data.setObject("Obj1","R1","C1") is a void method call, and thus it cannot be parameterized
   11 | Unmatched statement data.removeRow("R2"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   12 | Unmatched statement assertEquals("Obj1",data.getObject(0,0)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted