From 43b8ed7033b1bb90373fedef0bedf6204692aede Mon Sep 17 00:00:00 2001 From: KamTo Hung Date: Thu, 20 Apr 2023 16:24:35 +0800 Subject: [PATCH 1/2] optimize code --- .../configuration/StreamClassPathScanner.java | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/stream-plugin/stream-plugin-mybatis-plus/src/main/java/org/dromara/streamquery/stream/plugin/mybatisplus/engine/configuration/StreamClassPathScanner.java b/stream-plugin/stream-plugin-mybatis-plus/src/main/java/org/dromara/streamquery/stream/plugin/mybatisplus/engine/configuration/StreamClassPathScanner.java index 26dea63c..d392d6e5 100644 --- a/stream-plugin/stream-plugin-mybatis-plus/src/main/java/org/dromara/streamquery/stream/plugin/mybatisplus/engine/configuration/StreamClassPathScanner.java +++ b/stream-plugin/stream-plugin-mybatis-plus/src/main/java/org/dromara/streamquery/stream/plugin/mybatisplus/engine/configuration/StreamClassPathScanner.java @@ -18,7 +18,9 @@ package org.dromara.streamquery.stream.plugin.mybatisplus.engine.configuration; import org.apache.ibatis.logging.Log; import org.apache.ibatis.logging.LogFactory; +import org.dromara.streamquery.stream.core.lambda.function.SerPred; import org.dromara.streamquery.stream.core.reflect.ReflectHelper; +import org.dromara.streamquery.stream.core.stream.Steam; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; import org.springframework.core.type.ClassMetadata; @@ -27,11 +29,8 @@ import org.springframework.core.type.filter.AssignableTypeFilter; import org.springframework.util.CollectionUtils; import java.lang.annotation.Annotation; -import java.util.Collection; import java.util.Collections; -import java.util.Objects; import java.util.Set; -import java.util.stream.Collectors; /** * stream class path scanner @@ -71,13 +70,13 @@ public class StreamClassPathScanner extends ClassPathScanningCandidateComponentP if (this.interfaceClass != null) { addIncludeFilter( - new AssignableTypeFilter(this.interfaceClass) { - // remove parent entity - @Override - protected boolean matchClassName(String className) { - return false; - } - }); + new AssignableTypeFilter(this.interfaceClass) { + // remove parent entity + @Override + protected boolean matchClassName(String className) { + return false; + } + }); acceptAllInterfaces = false; } @@ -88,12 +87,12 @@ public class StreamClassPathScanner extends ClassPathScanningCandidateComponentP // exclude package-info.java addExcludeFilter( - (metadataReader, metadataReaderFactory) -> { - ClassMetadata classMetadata = metadataReader.getClassMetadata(); - return classMetadata.getClassName().endsWith("package-info") - || classMetadata.isInterface() - || classMetadata.isAbstract(); - }); + (metadataReader, metadataReaderFactory) -> { + ClassMetadata classMetadata = metadataReader.getClassMetadata(); + return classMetadata.getClassName().endsWith("package-info") + || classMetadata.isInterface() + || classMetadata.isAbstract(); + }); } public Set> scan(Set basePackages) { @@ -101,13 +100,12 @@ public class StreamClassPathScanner extends ClassPathScanningCandidateComponentP LOG.warn("basePackages is empty"); return Collections.emptySet(); } - return basePackages.stream() - .map(this::findCandidateComponents) - .flatMap(Collection::stream) - .map(BeanDefinition::getBeanClassName) - .filter(Objects::nonNull) - .map(ReflectHelper::forClassName) - .filter(o -> !(o.isMemberClass() || o.isAnonymousClass() || o.isLocalClass())) - .collect(Collectors.toSet()); + return Steam.of(basePackages) + .flat(this::findCandidateComponents) + .map(BeanDefinition::getBeanClassName) + .nonNull() + .>map(ReflectHelper::forClassName) + .filter(SerPred.>multiOr(Class::isMemberClass, Class::isAnonymousClass, Class::isLocalClass).negate()) + .toSet(); } } -- Gitee From 0a0a9bb81f9208a6e0f44557be8d97c8e595e54a Mon Sep 17 00:00:00 2001 From: KamTo Hung Date: Thu, 20 Apr 2023 16:25:17 +0800 Subject: [PATCH 2/2] optimize code --- .../configuration/StreamClassPathScanner.java | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/stream-plugin/stream-plugin-mybatis-plus/src/main/java/org/dromara/streamquery/stream/plugin/mybatisplus/engine/configuration/StreamClassPathScanner.java b/stream-plugin/stream-plugin-mybatis-plus/src/main/java/org/dromara/streamquery/stream/plugin/mybatisplus/engine/configuration/StreamClassPathScanner.java index d392d6e5..628c04f4 100644 --- a/stream-plugin/stream-plugin-mybatis-plus/src/main/java/org/dromara/streamquery/stream/plugin/mybatisplus/engine/configuration/StreamClassPathScanner.java +++ b/stream-plugin/stream-plugin-mybatis-plus/src/main/java/org/dromara/streamquery/stream/plugin/mybatisplus/engine/configuration/StreamClassPathScanner.java @@ -70,13 +70,13 @@ public class StreamClassPathScanner extends ClassPathScanningCandidateComponentP if (this.interfaceClass != null) { addIncludeFilter( - new AssignableTypeFilter(this.interfaceClass) { - // remove parent entity - @Override - protected boolean matchClassName(String className) { - return false; - } - }); + new AssignableTypeFilter(this.interfaceClass) { + // remove parent entity + @Override + protected boolean matchClassName(String className) { + return false; + } + }); acceptAllInterfaces = false; } @@ -87,12 +87,12 @@ public class StreamClassPathScanner extends ClassPathScanningCandidateComponentP // exclude package-info.java addExcludeFilter( - (metadataReader, metadataReaderFactory) -> { - ClassMetadata classMetadata = metadataReader.getClassMetadata(); - return classMetadata.getClassName().endsWith("package-info") - || classMetadata.isInterface() - || classMetadata.isAbstract(); - }); + (metadataReader, metadataReaderFactory) -> { + ClassMetadata classMetadata = metadataReader.getClassMetadata(); + return classMetadata.getClassName().endsWith("package-info") + || classMetadata.isInterface() + || classMetadata.isAbstract(); + }); } public Set> scan(Set basePackages) { @@ -101,11 +101,14 @@ public class StreamClassPathScanner extends ClassPathScanningCandidateComponentP return Collections.emptySet(); } return Steam.of(basePackages) - .flat(this::findCandidateComponents) - .map(BeanDefinition::getBeanClassName) - .nonNull() - .>map(ReflectHelper::forClassName) - .filter(SerPred.>multiOr(Class::isMemberClass, Class::isAnonymousClass, Class::isLocalClass).negate()) - .toSet(); + .flat(this::findCandidateComponents) + .map(BeanDefinition::getBeanClassName) + .nonNull() + .>map(ReflectHelper::forClassName) + .filter( + SerPred.>multiOr( + Class::isMemberClass, Class::isAnonymousClass, Class::isLocalClass) + .negate()) + .toSet(); } } -- Gitee