public String toStatementString() { StringBuffer buf = new StringBuffer( columns.size()*15 + tableName.length() + 10 ); if ( comment != null ) { buf.append( "/* " ).append( comment ).append( " */ " ); } buf.append("insert into ") .append(tableName); if ( columns.size()==0 ) { buf.append(' ').append( dialect.getNoColumnsInsertString() ); } else { buf.append(" ("); Iterator iter = columns.keySet().iterator(); while ( iter.hasNext() ) { buf.append( iter.next() ); if ( iter.hasNext() ) { buf.append( ", " ); } } buf.append(") values ("); iter = columns.values().iterator(); while ( iter.hasNext() ) { buf.append( iter.next() ); if ( iter.hasNext() ) { buf.append( ", " ); } } buf.append(')'); } return buf.toString(); }
private String getErrorString() { StringBuffer buf = new StringBuffer(); for ( Iterator iterator = errorList.iterator(); iterator.hasNext(); ) { buf.append( ( String ) iterator.next() ); if ( iterator.hasNext() ) buf.append( "\n" ); } return buf.toString(); }
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/sql/Insert.java File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/hql/ast/ErrorCounter.java
Method name: String toStatementString() Method name: String getErrorString()
Number of AST nodes: 4 Number of AST nodes: 4
1
public String toStatementString() {
1
private String getErrorString() {
2
		StringBuffer buf = new StringBuffer( columns.size()*15 + tableName.length() + 10 );
2
		StringBuffer buf = new StringBuffer();
3
		if ( comment != null ) {
3
		for ( Iterator iterator = errorList.iterator(); iterator.hasNext(); ) {
4
			buf.append( "/* " ).append( comment ).append( " */ " );
4
			buf.append( ( String ) iterator.next() );
5
		}
5
			if ( iterator.hasNext() ) buf.append( "\n" );
6
		buf.append("insert into ")
6
7
			.append(tableName);
7
		}
8
		if ( columns.size()==0 ) {
8
		return buf.toString();
9
			buf.append(' ').append( dialect.getNoColumnsInsertString() );
9
	}
10
		}
11
		else {
12
			buf.append(" (");
13
			Iterator iter = columns.keySet().iterator();
14
			while ( iter.hasNext() ) {
15
				buf.append( iter.next() );
16
				if ( iter.hasNext() ) {
17
					buf.append( ", " );
18
				}
19
			}
20
			buf.append(") values (");
21
			iter = columns.values().iterator();
22
			while ( iter.hasNext() ) {
23
				buf.append( iter.next() );
24
				if ( iter.hasNext() ) {
25
					buf.append( ", " );
26
				}
27
			}
28
			buf.append(')');
29
		}
30
		return buf.toString();
31
	}
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements4
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.800
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    15
    while (iter.hasNext())
    15
    while (iter.hasNext())
    2
    for (Iterator iterator = errorList.iterator(); iterator.hasNext(); )
    Differences
    Expression1Expression2Difference
    iteriteratorVARIABLE_NAME_MISMATCH
    java.util.Collectionjava.util.ListVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.util.Collection of variable columns.values() does not match with type java.util.List of variable errorList
    • Make classes java.util.Collection and java.util.List extend a common superclass
    2
    for (Iterator iterator = errorList.iterator(); iterator.hasNext(); )
                                                                                  
    3
    buf.append((String)iterator.next());
    Preondition Violations
    Unmatched statement buf.append((String)iterator.next()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3
    buf.append((String)iterator.next());
    16
    buf.append(iter.next());
                                                            
    17
    if (iter.hasNext())
    17
    if (iter.hasNext())
    4
    if (iterator.hasNext())
    Differences
    Expression1Expression2Difference
    iteriteratorVARIABLE_NAME_MISMATCH
    4
    if (iterator.hasNext())
    18
    buf.append(", ");
    18
    buf.append(", ");
    5
    buf.append("\n");
    Differences
    Expression1Expression2Difference
    ", ""\n"LITERAL_VALUE_MISMATCH
    5
    buf.append("\n");
    Precondition Violations (3)
    Row Violation
    1Type java.util.Collection of variable columns.values() does not match with type java.util.List of variable errorList
    2Unmatched statement buf.append((String)iterator.next()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Clone fragment #1 returns variables , while Clone fragment #2 returns variables iterator