if ( args.size() == 1 ) { // we have the form: trim(trimSource) // so we trim leading and trailing spaces return resolveBothSpaceTrimFunction().render( args, factory ); // EARLY EXIT!!!! } else if ( "from".equalsIgnoreCase( ( String ) args.get( 0 ) ) ) { // we have the form: trim(from trimSource). // This is functionally equivalent to trim(trimSource) return resolveBothSpaceTrimFromFunction().render( args, factory ); // EARLY EXIT!!!! } else { // otherwise, a trim-specification and/or a trim-character // have been specified; we need to decide which options // are present and "do the right thing" boolean leading = true; // should leading trim-characters be trimmed? boolean trailing = true; // should trailing trim-characters be trimmed? String trimCharacter; // the trim-character (what is to be trimmed off?) String trimSource; // the trim-source (from where should it be trimmed?) // potentialTrimCharacterArgIndex = 1 assumes that a // trim-specification has been specified. we handle the // exception to that explicitly int potentialTrimCharacterArgIndex = 1; String firstArg = ( String ) args.get( 0 ); if ( "leading".equalsIgnoreCase( firstArg ) ) { trailing = false; } else if ( "trailing".equalsIgnoreCase( firstArg ) ) { leading = false; } else if ( "both".equalsIgnoreCase( firstArg ) ) { } else { potentialTrimCharacterArgIndex = 0; } String potentialTrimCharacter = ( String ) args.get( potentialTrimCharacterArgIndex ); if ( "from".equalsIgnoreCase( potentialTrimCharacter ) ) { trimCharacter = "' '"; trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 ); } else if ( potentialTrimCharacterArgIndex + 1 >= args.size() ) { trimCharacter = "' '"; trimSource = potentialTrimCharacter; } else { trimCharacter = potentialTrimCharacter; if ( "from".equalsIgnoreCase( ( String ) args.get( potentialTrimCharacterArgIndex + 1 ) ) ) { trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 2 ); } else { trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 ); } } List argsToUse = new ArrayList(); argsToUse.add( trimSource ); argsToUse.add( trimCharacter ); if ( trimCharacter.equals( "' '" ) ) { if ( leading && trailing ) { return resolveBothSpaceTrimFunction().render( argsToUse, factory ); } else if ( leading ) { return resolveLeadingSpaceTrimFunction().render( argsToUse, factory ); } else { return resolveTrailingSpaceTrimFunction().render( argsToUse, factory ); } } else { if ( leading && trailing ) { return resolveBothTrimFunction().render( argsToUse, factory ); } else if ( leading ) { return resolveLeadingTrimFunction().render( argsToUse, factory ); } else { return resolveTrailingTrimFunction().render( argsToUse, factory ); } } }
if ( args.size() == 1 ) { // we have the form: trim(trimSource) // so we trim leading and trailing spaces return BOTH_SPACE_TRIM.render( args, factory ); } else if ( "from".equalsIgnoreCase( ( String ) args.get( 0 ) ) ) { // we have the form: trim(from trimSource). // This is functionally equivalent to trim(trimSource) return BOTH_SPACE_TRIM_FROM.render( args, factory ); } else { // otherwise, a trim-specification and/or a trim-character // have been specified; we need to decide which options // are present and "do the right thing" boolean leading = true; // should leading trim-characters be trimmed? boolean trailing = true; // should trailing trim-characters be trimmed? String trimCharacter; // the trim-character String trimSource; // the trim-source // potentialTrimCharacterArgIndex = 1 assumes that a // trim-specification has been specified. we handle the // exception to that explicitly int potentialTrimCharacterArgIndex = 1; String firstArg = ( String ) args.get( 0 ); if ( "leading".equalsIgnoreCase( firstArg ) ) { trailing = false; } else if ( "trailing".equalsIgnoreCase( firstArg ) ) { leading = false; } else if ( "both".equalsIgnoreCase( firstArg ) ) { } else { potentialTrimCharacterArgIndex = 0; } String potentialTrimCharacter = ( String ) args.get( potentialTrimCharacterArgIndex ); if ( "from".equalsIgnoreCase( potentialTrimCharacter ) ) { trimCharacter = "' '"; trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 ); } else if ( potentialTrimCharacterArgIndex + 1 >= args.size() ) { trimCharacter = "' '"; trimSource = potentialTrimCharacter; } else { trimCharacter = potentialTrimCharacter; if ( "from".equalsIgnoreCase( ( String ) args.get( potentialTrimCharacterArgIndex + 1 ) ) ) { trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 2 ); } else { trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 ); } } List argsToUse = new ArrayList(); argsToUse.add( trimSource ); argsToUse.add( trimCharacter ); if ( trimCharacter.equals( "' '" ) ) { if ( leading && trailing ) { return BOTH_SPACE_TRIM.render( argsToUse, factory ); } else if ( leading ) { return LEADING_SPACE_TRIM.render( argsToUse, factory ); } else { return TRAILING_SPACE_TRIM.render( argsToUse, factory ); } } else { throw new HibernateException( "cannot specify trim character when using Derby as Derby does not support the ANSI trim function, not does it support a replace function to properly emmulate it" ); } }
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/dialect/function/AbstractAnsiTrimEmulationFunction.java File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/dialect/DerbyDialect.java
Method name: String render(List, SessionFactoryImplementor) Method name: String render(List, SessionFactoryImplementor)
Number of AST nodes: 41 Number of AST nodes: 37
1
if ( args.size() == 1 ) {
1
if ( args.size() == 1 ) {
2
			// we have the form: trim(trimSource)
2
				// we have the form: trim(trimSource)
3
			//      so we trim leading and trailing spaces
3
				//      so we trim leading and trailing spaces
4
			return resolveBothSpaceTrimFunction().render( args, factory );
4
				return BOTH_SPACE_TRIM.render( args, factory );
5
			// EARLY EXIT!!!!
5
			
6
		}
6
}
7
		else if ( "from".equalsIgnoreCase( ( String ) args.get( 0 ) ) ) {
7
			else if ( "from".equalsIgnoreCase( ( String ) args.get( 0 ) ) ) {
8
			// we have the form: trim(from trimSource).
8
				// we have the form: trim(from trimSource).
9
			//      This is functionally equivalent to trim(trimSource)
9
				//      This is functionally equivalent to trim(trimSource)
10
			return resolveBothSpaceTrimFromFunction().render( args, factory );  		// EARLY EXIT!!!!
10
				return BOTH_SPACE_TRIM_FROM.render( args, factory );
11
		}
11
			}
12
		else {
12
			else {
13
			// otherwise, a trim-specification and/or a trim-character
13
				// otherwise, a trim-specification and/or a trim-character
14
			// have been specified;  we need to decide which options
14
				// have been specified;  we need to decide which options
15
			// are present and "do the right thing"
15
				// are present and "do the right thing"
16
			boolean leading = true;         // should leading trim-characters be trimmed?
16
				boolean leading = true;         // should leading trim-characters be trimmed?
17
			boolean trailing = true;        // should trailing trim-characters be trimmed?
17
				boolean trailing = true;        // should trailing trim-characters be trimmed?
18
			String trimCharacter;    		// the trim-character (what is to be trimmed off?)
18
				String trimCharacter;    		// the trim-character
19
			String trimSource;       		// the trim-source (from where should it be trimmed?)
19
				String trimSource;       		// the trim-source
20
			// potentialTrimCharacterArgIndex = 1 assumes that a
20
				// potentialTrimCharacterArgIndex = 1 assumes that a
21
			// trim-specification has been specified.  we handle the
21
				// trim-specification has been specified.  we handle the
22
			// exception to that explicitly
22
				// exception to that explicitly
23
			int potentialTrimCharacterArgIndex = 1;
23
				int potentialTrimCharacterArgIndex = 1;
24
			String firstArg = ( String ) args.get( 0 );
24
				String firstArg = ( String ) args.get( 0 );
25
			if ( "leading".equalsIgnoreCase( firstArg ) ) {
25
				if ( "leading".equalsIgnoreCase( firstArg ) ) {
26
				trailing = false;
26
					trailing = false;
27
			}
27
				}
28
			else if ( "trailing".equalsIgnoreCase( firstArg ) ) {
28
				else if ( "trailing".equalsIgnoreCase( firstArg ) ) {
29
				leading = false;
29
					leading = false;
30
			}
30
				}
31
			else if ( "both".equalsIgnoreCase( firstArg ) ) {
31
				else if ( "both".equalsIgnoreCase( firstArg ) ) {
32
			}
32
				}
33
			else {
33
				else {
34
				potentialTrimCharacterArgIndex = 0;
34
					potentialTrimCharacterArgIndex = 0;
35
			}
35
				}
36
			String potentialTrimCharacter = ( String ) args.get( potentialTrimCharacterArgIndex );
36
				String potentialTrimCharacter = ( String ) args.get( potentialTrimCharacterArgIndex );
37
			if ( "from".equalsIgnoreCase( potentialTrimCharacter ) ) { 
37
				if ( "from".equalsIgnoreCase( potentialTrimCharacter ) ) {
38
				trimCharacter = "' '";
38
					trimCharacter = "' '";
39
				trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );
39
					trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );
40
			}
40
				}
41
			else if ( potentialTrimCharacterArgIndex + 1 >= args.size() ) {
41
				else if ( potentialTrimCharacterArgIndex + 1 >= args.size() ) {
42
				trimCharacter = "' '";
42
					trimCharacter = "' '";
43
				trimSource = potentialTrimCharacter;
43
					trimSource = potentialTrimCharacter;
44
			}
44
				}
45
			else {
45
				else {
46
				trimCharacter = potentialTrimCharacter;
46
					trimCharacter = potentialTrimCharacter;
47
				if ( "from".equalsIgnoreCase( ( String ) args.get( potentialTrimCharacterArgIndex + 1 ) ) ) {
47
					if ( "from".equalsIgnoreCase( ( String ) args.get( potentialTrimCharacterArgIndex + 1 ) ) ) {
48
					trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 2 );
48
						trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 2 );
49
				}
49
					}
50
				else {
50
					else {
51
					trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );
51
						trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );
52
				}
52
					}
53
			}
53
				}
54
			List argsToUse = new ArrayList();
54
				List argsToUse = new ArrayList();
55
			argsToUse.add( trimSource );
55
				argsToUse.add( trimSource );
56
			argsToUse.add( trimCharacter );
56
				argsToUse.add( trimCharacter );
57
			if ( trimCharacter.equals( "' '" ) ) {
57
				if ( trimCharacter.equals( "' '" ) ) {
58
				if ( leading && trailing ) {
58
					if ( leading && trailing ) {
59
					return resolveBothSpaceTrimFunction().render( argsToUse, factory );
59
						return BOTH_SPACE_TRIM.render( argsToUse, factory );
60
				}
60
					}
61
				else if ( leading ) {
61
					else if ( leading ) {
62
					return resolveLeadingSpaceTrimFunction().render( argsToUse, factory );
62
						return LEADING_SPACE_TRIM.render( argsToUse, factory );
63
				}
63
					}
64
				else {
64
					else {
65
					return resolveTrailingSpaceTrimFunction().render( argsToUse, factory );
65
						return TRAILING_SPACE_TRIM.render( argsToUse, factory );
66
				}
66
					}
67
			}
67
				}
68
			else {
68
				else {
69
				if ( leading && trailing ) {
69
					
70
					return resolveBothTrimFunction().render( argsToUse, factory );
71
				}
72
				else if ( leading ) {
73
					return resolveLeadingTrimFunction().render( argsToUse, factory );
70
throw new HibernateException( "cannot specify trim character when using Derby as Derby does not support the ANSI trim function
74
				}
75
				else {
76
					return resolveTrailingTrimFunction().render( argsToUse, factory );
71
, not does it support a replace function to properly emmulate it" );
77
				}
72
				}
78
			}
73
			}
79
		}
Summary
Number of common nesting structure subtrees2
Number of refactorable cases1
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)4.9
Clones locationClones are in different classes
Number of node comparisons364
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements5
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)3.1
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    37
    if (leading && trailing)
    32
    if (leading && trailing)
    38
    return resolveBothTrimFunction().render(argsToUse, factory);
    38
    return resolveBothTrimFunction().render(argsToUse, factory);
    33
    return BOTH_SPACE_TRIM.render(argsToUse, factory);
    Differences
    Expression1Expression2Difference
    resolveBothTrimFunction()BOTH_SPACE_TRIMTYPE_COMPATIBLE_REPLACEMENT
    33
    return BOTH_SPACE_TRIM.render(argsToUse, factory);
    39
    else if (leading)
    34
    else if (leading)
    40
    return resolveLeadingTrimFunction().render(argsToUse, factory);
    40
    return resolveLeadingTrimFunction().render(argsToUse, factory);
    35
    return LEADING_SPACE_TRIM.render(argsToUse, factory);
    Differences
    Expression1Expression2Difference
    resolveLeadingTrimFunction()LEADING_SPACE_TRIMTYPE_COMPATIBLE_REPLACEMENT
    35
    return LEADING_SPACE_TRIM.render(argsToUse, factory);
    else
    else
    41
    return resolveTrailingTrimFunction().render(argsToUse, factory);
    41
    return resolveTrailingTrimFunction().render(argsToUse, factory);
    36
    return TRAILING_SPACE_TRIM.render(argsToUse, factory);
    Differences
    Expression1Expression2Difference
    resolveTrailingTrimFunction()TRAILING_SPACE_TRIMTYPE_COMPATIBLE_REPLACEMENT
    36
    return TRAILING_SPACE_TRIM.render(argsToUse, factory);
    Precondition Violations (0)
    Row Violation
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements36
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)35.2
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    if (args.size() == 1)
    1
    if (args.size() == 1)
    2
    return resolveBothSpaceTrimFunction().render(args, factory);
    2
    return resolveBothSpaceTrimFunction().render(args, factory);
    2
    return BOTH_SPACE_TRIM.render(args, factory);
    Differences
    Expression1Expression2Difference
    resolveBothSpaceTrimFunction()BOTH_SPACE_TRIMTYPE_COMPATIBLE_REPLACEMENT
    2
    return BOTH_SPACE_TRIM.render(args, factory);
    3
    else if ("from".equalsIgnoreCase((String)args.get(0)))
    3
    else if ("from".equalsIgnoreCase((String)args.get(0)))
    4
    return resolveBothSpaceTrimFromFunction().render(args, factory);
    4
    return resolveBothSpaceTrimFromFunction().render(args, factory);
    4
    return BOTH_SPACE_TRIM_FROM.render(args, factory);
    Differences
    Expression1Expression2Difference
    resolveBothSpaceTrimFromFunction()BOTH_SPACE_TRIM_FROMTYPE_COMPATIBLE_REPLACEMENT
    4
    return BOTH_SPACE_TRIM_FROM.render(args, factory);
    else
    else
    5
    boolean leading = true;
    5
    boolean leading = true;
    6
    boolean trailing = true;
    6
    boolean trailing = true;
    7
    String trimCharacter;
    7
    String trimCharacter;
    8
    String trimSource;
    8
    String trimSource;
    9
    int potentialTrimCharacterArgIndex = 1;
    9
    int potentialTrimCharacterArgIndex = 1;
    10
    String firstArg = (String)args.get(0);
    10
    String firstArg = (String)args.get(0);
    11
    if ("leading".equalsIgnoreCase(firstArg))
    11
    if ("leading".equalsIgnoreCase(firstArg))
    12
    trailing = false;
    12
    trailing = false;
    13
    else if ("trailing".equalsIgnoreCase(firstArg))
    13
    else if ("trailing".equalsIgnoreCase(firstArg))
    14
    leading = false;
    14
    leading = false;
    15
    else if ("both".equalsIgnoreCase(firstArg))
    15
    else if ("both".equalsIgnoreCase(firstArg))
    else
    else
    16
    potentialTrimCharacterArgIndex = 0;
    16
    potentialTrimCharacterArgIndex = 0;
    17
    String potentialTrimCharacter = (String)args.get(potentialTrimCharacterArgIndex);
    17
    String potentialTrimCharacter = (String)args.get(potentialTrimCharacterArgIndex);
    18
    if ("from".equalsIgnoreCase(potentialTrimCharacter))
    18
    if ("from".equalsIgnoreCase(potentialTrimCharacter))
    19
    trimCharacter = "' '";
    19
    trimCharacter = "' '";
    20
    trimSource = (String)args.get(potentialTrimCharacterArgIndex + 1);
    20
    trimSource = (String)args.get(potentialTrimCharacterArgIndex + 1);
    21
    else if (potentialTrimCharacterArgIndex + 1 >= args.size())
    21
    else if (potentialTrimCharacterArgIndex + 1 >= args.size())
    22
    trimCharacter = "' '";
    22
    trimCharacter = "' '";
    23
    trimSource = potentialTrimCharacter;
    23
    trimSource = potentialTrimCharacter;
    else
    else
    24
    trimCharacter = potentialTrimCharacter;
    24
    trimCharacter = potentialTrimCharacter;
    25
    if ("from".equalsIgnoreCase((String)args.get(potentialTrimCharacterArgIndex + 1)))
    25
    if ("from".equalsIgnoreCase((String)args.get(potentialTrimCharacterArgIndex + 1)))
    26
    trimSource = (String)args.get(potentialTrimCharacterArgIndex + 2);
    26
    trimSource = (String)args.get(potentialTrimCharacterArgIndex + 2);
    else
    else
    27
    trimSource = (String)args.get(potentialTrimCharacterArgIndex + 1);
    27
    trimSource = (String)args.get(potentialTrimCharacterArgIndex + 1);
    28
    List argsToUse = new ArrayList();
    28
    List argsToUse = new ArrayList();
    29
    argsToUse.add(trimSource);
    29
    argsToUse.add(trimSource);
    30
    argsToUse.add(trimCharacter);
    30
    argsToUse.add(trimCharacter);
    31
    if (trimCharacter.equals("' '"))
    31
    if (trimCharacter.equals("' '"))
    32
    if (leading && trailing)
    32
    if (leading && trailing)
    33
    return resolveBothSpaceTrimFunction().render(argsToUse, factory);
    33
    return resolveBothSpaceTrimFunction().render(argsToUse, factory);
    33
    return BOTH_SPACE_TRIM.render(argsToUse, factory);
    Differences
    Expression1Expression2Difference
    resolveBothSpaceTrimFunction()BOTH_SPACE_TRIMTYPE_COMPATIBLE_REPLACEMENT
    33
    return BOTH_SPACE_TRIM.render(argsToUse, factory);
    34
    else if (leading)
    34
    else if (leading)
    35
    return resolveLeadingSpaceTrimFunction().render(argsToUse, factory);
    35
    return resolveLeadingSpaceTrimFunction().render(argsToUse, factory);
    35
    return LEADING_SPACE_TRIM.render(argsToUse, factory);
    Differences
    Expression1Expression2Difference
    resolveLeadingSpaceTrimFunction()LEADING_SPACE_TRIMTYPE_COMPATIBLE_REPLACEMENT
    35
    return LEADING_SPACE_TRIM.render(argsToUse, factory);
    else
    else
    36
    return resolveTrailingSpaceTrimFunction().render(argsToUse, factory);
    36
    return resolveTrailingSpaceTrimFunction().render(argsToUse, factory);
    36
    return TRAILING_SPACE_TRIM.render(argsToUse, factory);
    Differences
    Expression1Expression2Difference
    resolveTrailingSpaceTrimFunction()TRAILING_SPACE_TRIMTYPE_COMPATIBLE_REPLACEMENT
    36
    return TRAILING_SPACE_TRIM.render(argsToUse, factory);
            
    else
                                                                                                                                                                                                                                                                                                                                                                                                            
    37
    throw new HibernateException("cannot specify trim character when using Derby as Derby does not support the ANSI trim function, not does it support a replace function to properly emmulate it");
    Preondition Violations
    Unmatched throw new HibernateException("cannot specify trim character when using Derby as Derby does not support the ANSI trim function, not does it support a replace function to properly emmulate it");
    37
    throw new HibernateException("cannot specify trim character when using Derby as Derby does not support the ANSI trim function, not does it support a replace function to properly emmulate it");
    Precondition Violations (2)
    Row Violation
    1Unmatched throw new HibernateException("cannot specify trim character when using Derby as Derby does not support the ANSI trim function, not does it support a replace function to properly emmulate it");
    2Clone fragment #1 returns variables leading, trailing, argsToUse , while Clone fragment #2 returns variables