Skip to content

Commit

Permalink
minor: refactor to use 'ToIntFunction' interface
Browse files Browse the repository at this point in the history
  • Loading branch information
nrmancuso authored and romani committed Nov 23, 2022
1 parent f6e1a8c commit 3c1c029
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.ToIntFunction;

import com.puppycrawl.tools.checkstyle.FileStatefulCheck;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
Expand Down Expand Up @@ -271,7 +272,7 @@ private void registerNestedSubclassToOuterSuperClasses(String qualifiedClassName
ClassDesc currentClass) {
final String superClassName = getSuperClassName(currentClass.getTypeDeclarationAst());
if (superClassName != null) {
final Function<ClassDesc, Integer> nestedClassCountProvider = classDesc -> {
final ToIntFunction<ClassDesc> nestedClassCountProvider = classDesc -> {
return CheckUtil.typeDeclarationNameMatchingCount(qualifiedClassName,
classDesc.getQualifiedName());
};
Expand All @@ -294,7 +295,7 @@ private void registerAnonymousInnerClassToSuperClass(DetailAST literalNewAst,
String outerTypeDeclName) {
final String superClassName = CheckUtil.getShortNameOfAnonInnerClass(literalNewAst);

final Function<ClassDesc, Integer> anonClassCountProvider = classDesc -> {
final ToIntFunction<ClassDesc> anonClassCountProvider = classDesc -> {
return getAnonSuperTypeMatchingCount(outerTypeDeclName, classDesc.getQualifiedName());
};
getNearestClassWithSameName(superClassName, anonClassCountProvider)
Expand Down Expand Up @@ -342,9 +343,9 @@ private void registerAnonymousInnerClassToSuperClass(DetailAST literalNewAst,
* pitest to fail
*/
private Optional<ClassDesc> getNearestClassWithSameName(String className,
Function<ClassDesc, Integer> countProvider) {
ToIntFunction<ClassDesc> countProvider) {
final String dotAndClassName = PACKAGE_SEPARATOR.concat(className);
final Comparator<ClassDesc> longestMatch = Comparator.comparingInt(countProvider::apply);
final Comparator<ClassDesc> longestMatch = Comparator.comparingInt(countProvider);
return innerClasses.entrySet().stream()
.filter(entry -> entry.getKey().endsWith(dotAndClassName))
.map(Map.Entry::getValue)
Expand Down

0 comments on commit 3c1c029

Please sign in to comment.