Skip to content

Commit

Permalink
Fix expansion of lambdas in assertTimeout scenarios
Browse files Browse the repository at this point in the history
async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutorTest.java
iluwatar/java-design-patterns@6694d74
  • Loading branch information
tsantalis committed Jan 17, 2025
1 parent c33a4aa commit 2df6c3e
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ public UMLOperationBodyMapper(UMLOperationBodyMapper mapper1, UMLOperation added
}
}

private static boolean containsAll(LambdaExpressionObject bigLambda, List<LambdaExpressionObject> small) {
int count = 0;
for(LambdaExpressionObject lambda : small) {
for(LambdaExpressionObject nestedLambda : bigLambda.getAllLambdas()) {
if(nestedLambda.getString().equals(lambda.getString())) {
count++;
break;
}
}
}
return count == small.size();
}

public UMLOperationBodyMapper(UMLOperation operation1, UMLOperation operation2, UMLAbstractClassDiff classDiff) throws RefactoringMinerTimedOutException {
this.classDiff = classDiff;
this.modelDiff = classDiff != null ? classDiff.getModelDiff() : null;
Expand Down Expand Up @@ -478,7 +491,7 @@ else if(statement1.getString().equals(list2.get(i))) {
expandAnonymousAndLambdas(anonymousFragment, leaves1, innerNodes1, new LinkedHashSet<>(), new LinkedHashSet<>(), anonymousClassList1(), codeFragmentOperationMap1, operation1, true);
}
}
else if(lambdas1.size() == 1 && anonymous2.size() == 0 && lambdas2.size() == 0) {
else if(anonymous2.size() == 0 && ((lambdas1.size() == 1 && lambdas2.size() == 0) || (lambdas1.size() == 1 && containsAll(lambdas1.get(0), lambdas2)))) {
AbstractCodeFragment lambdaFragment = null;
for(AbstractCodeFragment leaf1 : leaves1) {
if(leaf1.getLambdas().size() > 0) {
Expand All @@ -505,7 +518,7 @@ else if((anonymous1.size() == 0 && anonymous2.size() == 1) ||
expandAnonymousAndLambdas(anonymousFragment, leaves2, innerNodes2, new LinkedHashSet<>(), new LinkedHashSet<>(), anonymousClassList2(), codeFragmentOperationMap2, operation2, true);
}
}
else if(anonymous1.size() == 0 && lambdas1.size() == 0 && lambdas2.size() == 1) {
else if(anonymous1.size() == 0 && ((lambdas1.size() == 0 && lambdas2.size() == 1) || (lambdas2.size() == 1 && containsAll(lambdas2.get(0), lambdas1)))) {
AbstractCodeFragment lambdaFragment = null;
for(AbstractCodeFragment leaf2 : leaves2) {
if(leaf2.getLambdas().size() > 0) {
Expand Down

0 comments on commit 2df6c3e

Please sign in to comment.