final Ruby runtime = context.getRuntime(); final IRubyObject result[] = new IRubyObject[] { null }; final ThreadContext localContext = context; if (block.isGiven()) { callEach(runtime, context, self, new BlockCallback() { public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) { IRubyObject larg = checkArgs(runtime, largs); checkContext(localContext, ctx, "max{}"); if (result[0] == null || RubyComparable.cmpint(ctx, block.yield(ctx, runtime.newArray(larg, result[0]), null, null, true), larg, result[0]) > 0) { result[0] = larg; } return runtime.getNil(); } }); } else { callEach(runtime, context, self, new BlockCallback() { public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) { IRubyObject larg = checkArgs(runtime, largs); synchronized (result) { if (result[0] == null || RubyComparable.cmpint(ctx, larg.callMethod(ctx, "<=>", result[0]), larg, result[0]) > 0) { result[0] = larg; } } return runtime.getNil(); } }); } return result[0] == null ? runtime.getNil() : result[0];
final Ruby runtime = context.getRuntime(); final IRubyObject result[] = new IRubyObject[] { null }; final ThreadContext localContext = context; if (block.isGiven()) { callEach(runtime, context, self, new BlockCallback() { public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) { IRubyObject larg = checkArgs(runtime, largs); checkContext(localContext, ctx, "min{}"); if (result[0] == null || RubyComparable.cmpint(ctx, block.yield(ctx, runtime.newArray(larg, result[0])), larg, result[0]) < 0) { result[0] = larg; } return runtime.getNil(); } }); } else { callEach(runtime, context, self, new BlockCallback() { public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) { IRubyObject larg = checkArgs(runtime, largs); synchronized (result) { if (result[0] == null || RubyComparable.cmpint(ctx, larg.callMethod(ctx, "<=>", result[0]), larg, result[0]) < 0) { result[0] = larg; } } return runtime.getNil(); } }); } return result[0] == null ? runtime.getNil() : result[0];
Clone fragments detected by clone detection tool
File path: /jruby-1.4.0/src/org/jruby/RubyEnumerable.java File path: /jruby-1.4.0/src/org/jruby/RubyEnumerable.java
Method name: IRubyObject max(ThreadContext, IRubyObject, Block) Method name: IRubyObject min(ThreadContext, IRubyObject, Block)
Number of AST nodes: 7 Number of AST nodes: 7
1
final Ruby runtime = context.getRuntime();
1
final Ruby runtime = context.getRuntime();
2
        final IRubyObject result[] = new IRubyObject[] { null };
2
        final IRubyObject result[] = new IRubyObject[] { null };
3
        final ThreadContext localContext = context;
3
        final ThreadContext localContext = context;
4
        if (block.isGiven()) {
4
        if (block.isGiven()) {
5
            callEach(runtime, context, self, new BlockCallback() {
5
            callEach(runtime, context, self, new BlockCallback() {
6
                public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
6
                public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
7
                    IRubyObject larg = checkArgs(runtime, largs);
7
                    IRubyObject larg = checkArgs(runtime, largs);
8
                    checkContext(localContext, ctx, "max{}");
8
                    checkContext(localContext, ctx, "min{}");
9
                    if (result[0] == null || RubyComparable.cmpint(ctx, block.yield(ctx, 
9
                    if (result[0] == null || RubyComparable.cmpint(ctx, block.yield(ctx, 
10
                            runtime.newArray(larg, result[0]), null, null, true), larg, result[0]) &gt; 0) {
10
                            runtime.newArray(larg, result[0])), larg, result[0]) &lt; 0) {
11
                        result[0] = larg;
11
                        result[0] = larg;
12
                    }
12
                    }
13
                    return runtime.getNil();
13
                    return runtime.getNil();
14
                }
14
                }
15
            });
15
            });
16
        } else {
16
        } else {
17
            callEach(runtime, context, self, new BlockCallback() {
17
            callEach(runtime, context, self, new BlockCallback() {
18
                public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
18
                public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
19
                    IRubyObject larg = checkArgs(runtime, largs);
19
                    IRubyObject larg = checkArgs(runtime, largs);
20
                    synchronized (result) {
20
                    synchronized (result) {
21
                        if (result[0] == null || RubyComparable.cmpint(ctx, larg.callMethod(ctx, "<=>", result[0]), larg, result[0]) &gt; 0) {
21
                        if (result[0] == null || RubyComparable.cmpint(ctx, larg.callMethod(ctx, "<=>", result[0]), larg, result[0]) &lt; 0) {
22
                            result[0] = larg;
22
                            result[0] = larg;
23
                        }
23
                        }
24
                    }
24
                    }
25
                    return runtime.getNil();
25
                    return runtime.getNil();
26
                }
26
                }
27
            });
27
            });
28
        }
28
        }
29
        return result[0] == null ? runtime.getNil() : result[0];
29
        return result[0] == null ? runtime.getNil() : result[0];
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.3
Clones locationClones are declared in the same class
Number of node comparisons25
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements5
    Number of unmapped statements in the first code fragment2
    Number of unmapped statements in the second code fragment2
    Time elapsed for statement mapping (ms)36.8
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    final Ruby runtime = context.getRuntime();
    1
    final Ruby runtime = context.getRuntime();
    2
    final IRubyObject result[] = new IRubyObject[] {null};
    2
    final IRubyObject result[] = new IRubyObject[] {null};
    3
    final ThreadContext localContext = context;
    3
    final ThreadContext localContext = context;
    4
    if (block.isGiven())
    4
    if (block.isGiven())
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
    5
    callEach(runtime, context, self, new BlockCallback() {...});
    Preondition Violations
    Unmatched statement callEach(runtime,context,self,new BlockCallback(){ public IRubyObject call( ThreadContext ctx, IRubyObject[] largs, Block blk){ IRubyObject larg=checkArgs(runtime,largs); checkContext(localContext,ctx,"min{}"); if (result[0] == null || RubyComparable.cmpint(ctx,block.yield(ctx,runtime.newArray(larg,result[0])),larg,result[0]) < 0) { result[0]=larg; } return runtime.getNil(); } } ); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5
    callEach(runtime, context, self, new BlockCallback() {...});
    5
    callEach(runtime, context, self, new BlockCallback() {...});
    5
    callEach(runtime, context, self, new BlockCallback() {...});
    Preondition Violations
    Unmatched statement callEach(runtime,context,self,new BlockCallback(){ public IRubyObject call( ThreadContext ctx, IRubyObject[] largs, Block blk){ IRubyObject larg=checkArgs(runtime,largs); checkContext(localContext,ctx,"max{}"); if (result[0] == null || RubyComparable.cmpint(ctx,block.yield(ctx,runtime.newArray(larg,result[0]),null,null,true),larg,result[0]) > 0) { result[0]=larg; } return runtime.getNil(); } } ); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
    else
            
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    6
    callEach(runtime, context, self, new BlockCallback() {...});
    Preondition Violations
    Unmatched statement callEach(runtime,context,self,new BlockCallback(){ public IRubyObject call( ThreadContext ctx, IRubyObject[] largs, Block blk){ IRubyObject larg=checkArgs(runtime,largs); synchronized (result) { if (result[0] == null || RubyComparable.cmpint(ctx,larg.callMethod(ctx,"<=>",result[0]),larg,result[0]) < 0) { result[0]=larg; } } return runtime.getNil(); } } ); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6
    callEach(runtime, context, self, new BlockCallback() {...});
    6
    callEach(runtime, context, self, new BlockCallback() {...});
    6
    callEach(runtime, context, self, new BlockCallback() {...});
    Preondition Violations
    Unmatched statement callEach(runtime,context,self,new BlockCallback(){ public IRubyObject call( ThreadContext ctx, IRubyObject[] largs, Block blk){ IRubyObject larg=checkArgs(runtime,largs); synchronized (result) { if (result[0] == null || RubyComparable.cmpint(ctx,larg.callMethod(ctx,"<=>",result[0]),larg,result[0]) > 0) { result[0]=larg; } } return runtime.getNil(); } } ); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    7
    return result[0] == null ? runtime.getNil() : result[0];
    7
    return result[0] == null ? runtime.getNil() : result[0];
    Precondition Violations (5)
    Row Violation
    1Unmatched statement callEach(runtime,context,self,new BlockCallback(){ public IRubyObject call( ThreadContext ctx, IRubyObject[] largs, Block blk){ IRubyObject larg=checkArgs(runtime,largs); checkContext(localContext,ctx,"min{}"); if (result[0] == null || RubyComparable.cmpint(ctx,block.yield(ctx,runtime.newArray(larg,result[0])),larg,result[0]) < 0) { result[0]=larg; } return runtime.getNil(); } } ); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement callEach(runtime,context,self,new BlockCallback(){ public IRubyObject call( ThreadContext ctx, IRubyObject[] largs, Block blk){ IRubyObject larg=checkArgs(runtime,largs); checkContext(localContext,ctx,"max{}"); if (result[0] == null || RubyComparable.cmpint(ctx,block.yield(ctx,runtime.newArray(larg,result[0]),null,null,true),larg,result[0]) > 0) { result[0]=larg; } return runtime.getNil(); } } ); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched statement callEach(runtime,context,self,new BlockCallback(){ public IRubyObject call( ThreadContext ctx, IRubyObject[] largs, Block blk){ IRubyObject larg=checkArgs(runtime,largs); synchronized (result) { if (result[0] == null || RubyComparable.cmpint(ctx,larg.callMethod(ctx,"<=>",result[0]),larg,result[0]) < 0) { result[0]=larg; } } return runtime.getNil(); } } ); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched statement callEach(runtime,context,self,new BlockCallback(){ public IRubyObject call( ThreadContext ctx, IRubyObject[] largs, Block blk){ IRubyObject larg=checkArgs(runtime,largs); synchronized (result) { if (result[0] == null || RubyComparable.cmpint(ctx,larg.callMethod(ctx,"<=>",result[0]),larg,result[0]) > 0) { result[0]=larg; } } return runtime.getNil(); } } ); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Clone fragment #1 returns variables runtime, result, localContext , while Clone fragment #2 returns variables runtime, result, localContext