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