Parent parent = new Parent( "p1" ); Child child = new Child( "c1" ); parent.getChildren().add( child ); child.setParent( parent ); Child otherChild = new Child( "c2" ); Session session = openSession(); session.beginTransaction(); session.save( parent ); session.flush(); // at this point, the set on parent has now been replaced with a PersistentSet... PersistentSet children = ( PersistentSet ) parent.getChildren(); assertFalse( children.add( child ) ); assertFalse( children.isDirty() ); assertFalse( children.remove( otherChild ) ); assertFalse( children.isDirty() ); HashSet otherSet = new HashSet(); otherSet.add( child ); assertFalse( children.addAll( otherSet ) ); assertFalse( children.isDirty() ); assertFalse( children.retainAll( otherSet ) ); assertFalse( children.isDirty() ); otherSet = new HashSet(); otherSet.add( otherChild ); assertFalse( children.removeAll( otherSet ) ); assertFalse( children.isDirty() ); assertTrue( children.retainAll( otherSet )); assertTrue( children.isDirty() ); assertTrue( children.isEmpty() ); children.clear(); session.delete( child ); assertTrue( children.isDirty() ); session.flush(); children.clear(); assertFalse( children.isDirty() ); session.delete( parent ); session.getTransaction().commit(); session.close();
Container container = new Container( "p1" ); Container.Content c1 = new Container.Content( "c1" ); container.getContents().add( c1 ); Container.Content c2 = new Container.Content( "c2" ); Session session = openSession(); session.beginTransaction(); session.save( container ); session.flush(); // at this point, the set on container has now been replaced with a PersistentSet... PersistentSet children = ( PersistentSet ) container.getContents(); assertFalse( children.add( c1 ) ); assertFalse( children.isDirty() ); assertFalse( children.remove( c2 ) ); assertFalse( children.isDirty() ); HashSet otherSet = new HashSet(); otherSet.add( c1 ); assertFalse( children.addAll( otherSet ) ); assertFalse( children.isDirty() ); assertFalse( children.retainAll( otherSet ) ); assertFalse( children.isDirty() ); otherSet = new HashSet(); otherSet.add( c2 ); assertFalse( children.removeAll( otherSet ) ); assertFalse( children.isDirty() ); assertTrue( children.retainAll( otherSet )); assertTrue( children.isDirty() ); assertTrue( children.isEmpty() ); children.clear(); assertTrue( children.isDirty() ); session.flush(); children.clear(); assertFalse( children.isDirty() ); session.delete( container ); session.getTransaction().commit(); session.close();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetTest.java
Method name: void testWriteMethodDirtying() Method name: void testCompositeElementWriteMethodDirtying()
Number of AST nodes: 36 Number of AST nodes: 34
1
Parent parent = new Parent( "p1" );
2
		Child child = new Child( "c1" );
3
		parent.getChildren
1
Container container = new Container( "p1" );
2
		Container.Content c1 = new Container.Content( "c1" );
4
().add( child );
3
		container.getContents().add( c1 );
5
		child.setParent( parent );
4
		
6
		Child otherChild = new Child( "c2" );
5
Container.Content c2 = new Container.Content( "c2" );
7
		Session session = openSession();
6
		Session session = openSession();
8
		session.beginTransaction();
7
		session.beginTransaction();
9
		session.save( parent );
8
		session.save( container );
10
		session.flush();
9
		session.flush();
11
		// at this point, the set on parent has now been replaced with a PersistentSet...
10
		// at this point, the set on container has now been replaced with a PersistentSet...
12
		PersistentSet children = ( PersistentSet ) parent.getChildren();
11
		PersistentSet children = ( PersistentSet ) container.getContents();
13
		assertFalse( children.add( child ) );
12
		assertFalse( children.add( c1 ) );
14
		assertFalse( children.isDirty() );
13
		assertFalse( children.isDirty() );
15
		assertFalse( children.remove( otherChild ) );
14
		assertFalse( children.remove( c2 ) );
16
		assertFalse( children.isDirty() );
15
		assertFalse( children.isDirty() );
17
		HashSet otherSet = new HashSet();
16
		HashSet otherSet = new HashSet();
18
		otherSet.add( child );
17
		otherSet.add( c1 );
19
		assertFalse( children.addAll( otherSet ) );
18
		assertFalse( children.addAll( otherSet ) );
20
		assertFalse( children.isDirty() );
19
		assertFalse( children.isDirty() );
21
		assertFalse( children.retainAll( otherSet ) );
20
		assertFalse( children.retainAll( otherSet ) );
22
		assertFalse( children.isDirty() );
21
		assertFalse( children.isDirty() );
23
		otherSet = new HashSet();
22
		otherSet = new HashSet();
24
		otherSet.add( otherChild );
23
		otherSet.add( c2 );
25
		assertFalse( children.removeAll( otherSet ) );
24
		assertFalse( children.removeAll( otherSet ) );
26
		assertFalse( children.isDirty() );
25
		assertFalse( children.isDirty() );
27
		assertTrue( children.retainAll( otherSet ));
26
		assertTrue( children.retainAll( otherSet ));
28
		assertTrue( children.isDirty() );
27
		assertTrue( children.isDirty() );
29
		assertTrue( children.isEmpty() );
28
		assertTrue( children.isEmpty() );
30
		children.clear();
29
		children.clear();
31
		session.delete( child );
30
		
32
		assertTrue( children.isDirty() );
31
assertTrue( children.isDirty() );
33
		session.flush();
32
		session.flush();
34
		children.clear();
33
		children.clear();
35
		assertFalse( children.isDirty() );
34
		assertFalse( children.isDirty() );
36
		session.delete( parent );
35
		session.delete( container );
37
		session.getTransaction().commit();
36
		session.getTransaction().commit();
38
		session.close();
37
		session.close();
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.0
Clones locationClones are declared in the same class
Number of node comparisons506
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements29
    Number of unmapped statements in the first code fragment7
    Number of unmapped statements in the second code fragment5
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
                                                                                          
    1
    Container container = new Container("p1");
    1
    Parent parent = new Parent("p1");
                                                                        
                                                                                                            
    2
    Container.Content c1 = new Container.Content("c1");
    2
    Child child = new Child("c1");
                                                                  
                                                                          
    3
    container.getContents().add(c1);
    3
    parent.getChildren().add(child);
                                                                          
                                                                                                            
    4
    Container.Content c2 = new Container.Content("c2");
    4
    child.setParent(parent);
                                                          
    5
    Child otherChild = new Child("c2");
                                                                            
    6
    Session session = openSession();
    5
    Session session = openSession();
    7
    session.beginTransaction();
    6
    session.beginTransaction();
    8
    session.save(parent);
    8
    session.save(parent);
    7
    session.save(container);
    Differences
    Expression1Expression2Difference
    parentcontainerVARIABLE_NAME_MISMATCH
    org.hibernate.test.collection.set.Parentorg.hibernate.test.collection.set.ContainerVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.collection.set.Parent of variable parent does not match with type org.hibernate.test.collection.set.Container of variable container
    • Make classes org.hibernate.test.collection.set.Parent and org.hibernate.test.collection.set.Container extend a common superclass
    7
    session.save(container);
    9
    session.flush();
    8
    session.flush();
                                                                                                                                      
    9
    PersistentSet children = (PersistentSet)container.getContents();
    10
    PersistentSet children = (PersistentSet)parent.getChildren();
                                                                                                                                  
    11
    assertFalse(children.add(child));
    11
    assertFalse(children.add(child));
    10
    assertFalse(children.add(c1));
    Differences
    Expression1Expression2Difference
    childc1VARIABLE_NAME_MISMATCH
    org.hibernate.test.collection.set.Childorg.hibernate.test.collection.set.Container.ContentVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.collection.set.Child of variable child does not match with type org.hibernate.test.collection.set.Container.Content of variable c1
    • Make classes org.hibernate.test.collection.set.Child and org.hibernate.test.collection.set.Container.Content extend a common superclass
    10
    assertFalse(children.add(c1));
    12
    assertFalse(children.isDirty());
    11
    assertFalse(children.isDirty());
    13
    assertFalse(children.remove(otherChild));
    13
    assertFalse(children.remove(otherChild));
    12
    assertFalse(children.remove(c2));
    Differences
    Expression1Expression2Difference
    otherChildc2VARIABLE_NAME_MISMATCH
    org.hibernate.test.collection.set.Childorg.hibernate.test.collection.set.Container.ContentVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.collection.set.Child of variable otherChild does not match with type org.hibernate.test.collection.set.Container.Content of variable c2
    • Make classes org.hibernate.test.collection.set.Child and org.hibernate.test.collection.set.Container.Content extend a common superclass
    12
    assertFalse(children.remove(c2));
    14
    assertFalse(children.isDirty());
    13
    assertFalse(children.isDirty());
    15
    HashSet otherSet = new HashSet();
    14
    HashSet otherSet = new HashSet();
    16
    otherSet.add(child);
    16
    otherSet.add(child);
    15
    otherSet.add(c1);
    Differences
    Expression1Expression2Difference
    childc1VARIABLE_NAME_MISMATCH
    org.hibernate.test.collection.set.Childorg.hibernate.test.collection.set.Container.ContentVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.collection.set.Child of variable child does not match with type org.hibernate.test.collection.set.Container.Content of variable c1
    • Make classes org.hibernate.test.collection.set.Child and org.hibernate.test.collection.set.Container.Content extend a common superclass
    15
    otherSet.add(c1);
    17
    assertFalse(children.addAll(otherSet));
    16
    assertFalse(children.addAll(otherSet));
    18
    assertFalse(children.isDirty());
    17
    assertFalse(children.isDirty());
    19
    assertFalse(children.retainAll(otherSet));
    18
    assertFalse(children.retainAll(otherSet));
    20
    assertFalse(children.isDirty());
    19
    assertFalse(children.isDirty());
    21
    otherSet = new HashSet();
    20
    otherSet = new HashSet();
    22
    otherSet.add(otherChild);
    22
    otherSet.add(otherChild);
    21
    otherSet.add(c2);
    Differences
    Expression1Expression2Difference
    otherChildc2VARIABLE_NAME_MISMATCH
    org.hibernate.test.collection.set.Childorg.hibernate.test.collection.set.Container.ContentVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.collection.set.Child of variable otherChild does not match with type org.hibernate.test.collection.set.Container.Content of variable c2
    • Make classes org.hibernate.test.collection.set.Child and org.hibernate.test.collection.set.Container.Content extend a common superclass
    21
    otherSet.add(c2);
    23
    assertFalse(children.removeAll(otherSet));
    22
    assertFalse(children.removeAll(otherSet));
    24
    assertFalse(children.isDirty());
    23
    assertFalse(children.isDirty());
    25
    assertTrue(children.retainAll(otherSet));
    24
    assertTrue(children.retainAll(otherSet));
    26
    assertTrue(children.isDirty());
    25
    assertTrue(children.isDirty());
    27
    assertTrue(children.isEmpty());
    26
    assertTrue(children.isEmpty());
    28
    children.clear();
    27
    children.clear();
    29
    session.delete(child);
                                                        
    30
    assertTrue(children.isDirty());
    28
    assertTrue(children.isDirty());
    31
    session.flush();
    29
    session.flush();
    32
    children.clear();
    30
    children.clear();
    33
    assertFalse(children.isDirty());
    31
    assertFalse(children.isDirty());
    34
    session.delete(parent);
    34
    session.delete(parent);
    32
    session.delete(container);
    Differences
    Expression1Expression2Difference
    parentcontainerVARIABLE_NAME_MISMATCH
    org.hibernate.test.collection.set.Parentorg.hibernate.test.collection.set.ContainerVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.collection.set.Parent of variable parent does not match with type org.hibernate.test.collection.set.Container of variable container
    • Make classes org.hibernate.test.collection.set.Parent and org.hibernate.test.collection.set.Container extend a common superclass
    32
    session.delete(container);
    35
    session.getTransaction().commit();
    33
    session.getTransaction().commit();
    36
    session.close();
    34
    session.close();
    Precondition Violations (7)
    Row Violation
    1Type org.hibernate.test.collection.set.Parent of variable parent does not match with type org.hibernate.test.collection.set.Container of variable container
    2Type org.hibernate.test.collection.set.Child of variable child does not match with type org.hibernate.test.collection.set.Container.Content of variable c1
    3Type org.hibernate.test.collection.set.Child of variable otherChild does not match with type org.hibernate.test.collection.set.Container.Content of variable c2
    4Type org.hibernate.test.collection.set.Child of variable child does not match with type org.hibernate.test.collection.set.Container.Content of variable c1
    5Type org.hibernate.test.collection.set.Child of variable otherChild does not match with type org.hibernate.test.collection.set.Container.Content of variable c2
    6Type org.hibernate.test.collection.set.Parent of variable parent does not match with type org.hibernate.test.collection.set.Container of variable container
    7Clone fragment #1 returns variables session , while Clone fragment #2 returns variables