final Ruby runtime = context.getRuntime();
if (!block.isGiven()) return enumeratorize(runtime, self, "min_by");
final IRubyObject result[] = new IRubyObject[] { runtime.getNil() };
final ThreadContext localContext = context;
callEach(runtime, context, self, new BlockCallback() {
IRubyObject memo = null;
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
IRubyObject larg = checkArgs(runtime, largs);
checkContext(localContext, ctx, "min_by");
IRubyObject v = block.yield(ctx, larg);
if (memo == null || RubyComparable.cmpint(ctx, v.callMethod(ctx, "<=>", memo), v, memo) < 0) {
memo = v;
result[0] = larg;
}
return runtime.getNil();
}
});
return result[0];
final Ruby runtime = context.getRuntime();
if (!block.isGiven()) return enumeratorize(runtime, self, "max_by");
final IRubyObject result[] = new IRubyObject[] { runtime.getNil() };
final ThreadContext localContext = context;
callEach(runtime, context, self, new BlockCallback() {
IRubyObject memo = null;
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
IRubyObject larg = checkArgs(runtime, largs);
checkContext(localContext, ctx, "max_by");
IRubyObject v = block.yield(ctx, larg);
if (memo == null || RubyComparable.cmpint(ctx, v.callMethod(ctx, "<=>", memo), v, memo) > 0) {
memo = v;
result[0] = larg;
}
return runtime.getNil();
}
});
return 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 min_by(ThreadContext, IRubyObject, Block)
|
|
Method name: IRubyObject max_by(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 | if (!block.isGiven()) return enumeratorize(runtime, self, "min_by");↵ | | 2 | if (!block.isGiven()) return enumeratorize(runtime, self, "max_by");↵
|
|
3 | final IRubyObject result[] = new IRubyObject[] { runtime.getNil() };↵ | | 3 | final IRubyObject result[] = new IRubyObject[] { runtime.getNil() };↵
|
4 | final ThreadContext localContext = context;↵ | | 4 | final ThreadContext localContext = context;↵
|
|
5 | callEach(runtime, context, self, new BlockCallback() {↵ | | 5 | callEach(runtime, context, self, new BlockCallback() {↵
|
6 | IRubyObject memo = null;↵ | | 6 | IRubyObject memo = null;↵
|
7 | public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {↵ | | 7 | public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {↵
|
8 | IRubyObject larg = checkArgs(runtime, largs);↵ | | 8 | IRubyObject larg = checkArgs(runtime, largs);↵
|
9 | checkContext(localContext, ctx, "min_by");↵ | | 9 | checkContext(localContext, ctx, "max_by");↵
|
10 | IRubyObject v = block.yield(ctx, larg);↵ | | 10 | IRubyObject v = block.yield(ctx, larg);↵
|
|
11 | if (memo == null || RubyComparable.cmpint(ctx, v.callMethod(ctx, "<=>", memo), v, memo) < 0) {↵ | | 11 | if (memo == null || RubyComparable.cmpint(ctx, v.callMethod(ctx, "<=>", memo), v, memo) > 0) {↵
|
12 | memo = v;↵ | | 12 | memo = v;↵
|
13 | result[0] = larg;↵ | | 13 | result[0] = larg;↵
|
14 | }↵ | | 14 | }↵
|
15 | return runtime.getNil();↵ | | 15 | return runtime.getNil();↵
|
16 | }↵ | | 16 | }↵
|
17 | });↵ | | 17 | });↵
|
18 | return result[0]; | | 18 | return result[0];
|
See real code fragment |
|
See real code fragment |
Summary
Number of common nesting structure subtrees | 1 |
Number of refactorable cases | 0 |
Number of non-refactorable cases | 1 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.1 |
Clones location | Clones are declared in the same class |
Number of node comparisons | 23 |
-
{Non-refactorable}
Mapping Summary
Number of mapped statements | 6 |
Number of unmapped statements in the first code fragment | 1 |
Number of unmapped statements in the second code fragment | 1 |
Time elapsed for statement mapping (ms) | 3.0 |
Clone type | Type 2 |
Mapped Statements
ID |
Statement |
|
ID |
Statement |
1 | final Ruby runtime = context.getRuntime(); | | 1 | final Ruby runtime = context.getRuntime(); |
2 | if (!block.isGiven()) | | 2 | if (!block.isGiven()) |
3 | return enumeratorize(runtime, self, "min_by"); | | 3 | return enumeratorize(runtime, self, "max_by"); |
4 | final IRubyObject result[] = new IRubyObject[] {runtime.getNil()}; | | 4 | final IRubyObject result[] = new IRubyObject[] {runtime.getNil()}; |
5 | final ThreadContext localContext = context; | | 5 | final ThreadContext localContext = context; |
| | | 6 | callEach(runtime, context, self, new BlockCallback() {...}); |
6 | callEach(runtime, context, self, new BlockCallback() {...}); | | | |
7 | return result[0]; | | 7 | return result[0]; |
Precondition Violations (3)
Row |
Violation |
1 | Unmatched statement callEach(runtime,context,self,new BlockCallback(){
IRubyObject memo=null;
public IRubyObject call( ThreadContext ctx, IRubyObject[] largs, Block blk){
IRubyObject larg=checkArgs(runtime,largs);
checkContext(localContext,ctx,"max_by");
IRubyObject v=block.yield(ctx,larg);
if (memo == null || RubyComparable.cmpint(ctx,v.callMethod(ctx,"<=>",memo),v,memo) > 0) {
memo=v;
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 |
2 | Unmatched statement callEach(runtime,context,self,new BlockCallback(){
IRubyObject memo=null;
public IRubyObject call( ThreadContext ctx, IRubyObject[] largs, Block blk){
IRubyObject larg=checkArgs(runtime,largs);
checkContext(localContext,ctx,"min_by");
IRubyObject v=block.yield(ctx,larg);
if (memo == null || RubyComparable.cmpint(ctx,v.callMethod(ctx,"<=>",memo),v,memo) < 0) {
memo=v;
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 |
3 | Clone fragment #1 returns variables runtime, result, localContext , while Clone fragment #2 returns variables runtime, result, localContext |