Interface ScanFilter
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Scan Filter - Filter interface for class scanning
扫描过滤器 - 类扫描的过滤器接口
Functional interface for filtering classes during scanning.
用于在扫描期间过滤类的函数式接口。
Features | 主要功能:
- Predefined filters - 预定义过滤器
- Combinable with and/or/not - 可使用 and/or/not 组合
- Custom filter support - 自定义过滤器支持
Usage Examples | 使用示例:
ScanFilter filter = ScanFilter.and(
ScanFilter.isConcrete(),
ScanFilter.hasAnnotation(Service.class),
ScanFilter.not(ScanFilter.nameEndsWith("Test"))
);
Set<Class<?>> classes = scanner.scan(filter);
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是 (无状态)
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-classloader V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic ScanFilterall()Filter that accepts all classes 接受所有类的过滤器default ScanFilterand(ScanFilter other) AND combination AND 组合static ScanFilterand(ScanFilter... filters) AND combination of multiple filters 多个过滤器的 AND 组合static ScanFilterhasAllAnnotations(Class<? extends Annotation>... annotations) Filter for classes with all specified annotations 过滤带所有指定注解的类static ScanFilterhasAnnotation(Class<? extends Annotation> annotation) Filter for classes with specified annotation 过滤带指定注解的类static ScanFilterhasAnyAnnotation(Class<? extends Annotation>... annotations) Filter for classes with any of specified annotations 过滤带任意指定注解的类static ScanFilterhasConstructorWithParameterCount(int count) Filter for classes that have a constructor with the specified parameter count 过滤具有指定参数数量构造器的类static ScanFilterhasMethodWithParameterCount(int count) Filter for classes that have a method with the specified parameter count 过滤具有指定参数数量方法的类static ScanFilterhasMethodWithReturnType(Class<?> returnType) Filter for classes that have a method with the specified return type 过滤具有指定返回类型方法的类static ScanFilterhasModifier(int modifier) Filter by modifier 按修饰符过滤static ScanFilterFilter for sealed classes that have permitted subclasses 过滤有许可子类的密封类static ScanFilterimplementsInterface(Class<?> interfaceType) Filter for classes implementing specified interface 过滤实现指定接口的类static ScanFilterFilter for classes in specified package 过滤指定包中的类static ScanFilterFilter for abstract classes 过滤抽象类static ScanFilterFilter for annotations 过滤注解static ScanFilterFilter for concrete classes (not abstract, not interface) 过滤具体类(非抽象、非接口)static ScanFilterisEnum()Filter for enums 过滤枚举static ScanFilterisFinal()Filter for final classes 过滤 final 类static ScanFilterFilter for inner classes 过滤内部类static ScanFilterFilter for interfaces 过滤接口static ScanFilterisPublic()Filter for public classes 过滤 public 类static ScanFilterisRecord()Filter for records 过滤 Recordstatic ScanFilterisSealed()Filter for sealed classes 过滤密封类static ScanFilterisSubTypeOf(Class<?> superType) Filter for subtypes of specified class 过滤指定类的子类型static ScanFilterFilter for non-inner classes 过滤非内部类static ScanFilternameEndsWith(String suffix) Filter by name suffix 按名称后缀过滤static ScanFilternameMatches(String regex) Filter by name regex pattern 按名称正则模式过滤static ScanFilternameStartsWith(String prefix) Filter by name prefix 按名称前缀过滤default ScanFilternegate()Negate filter 取反过滤器static ScanFilternone()Filter that rejects all classes 拒绝所有类的过滤器static ScanFilternot(ScanFilter filter) Negate a filter 对过滤器取反default ScanFilteror(ScanFilter other) OR combination OR 组合static ScanFilteror(ScanFilter... filters) OR combination of multiple filters 多个过滤器的 OR 组合default booleanPre-filter by class name before loading the class (performance optimization) 在加载类之前按类名预过滤(性能优化)static ScanFiltersimpleNameEndsWith(String suffix) Filter by simple name suffix 按简单名称后缀过滤booleanTest if class matches filter 测试类是否匹配过滤器
-
Method Details
-
test
Test if class matches filter 测试类是否匹配过滤器- Parameters:
clazz- class to test | 要测试的类- Returns:
- true if matches | 匹配返回 true
-
preTest
Pre-filter by class name before loading the class (performance optimization) 在加载类之前按类名预过滤(性能优化)If this method returns false, the class will not be loaded via Class.forName, saving expensive class loading operations. Default returns true (no pre-filtering).
如果此方法返回 false,则不会通过 Class.forName 加载该类, 从而节省昂贵的类加载操作。默认返回 true(不预过滤)。
- Parameters:
className- fully qualified class name | 全限定类名- Returns:
- true if class should proceed to loading | 需要继续加载返回 true
-
and
AND combination AND 组合- Parameters:
other- other filter | 其他过滤器- Returns:
- combined filter | 组合后的过滤器
-
or
OR combination OR 组合- Parameters:
other- other filter | 其他过滤器- Returns:
- combined filter | 组合后的过滤器
-
negate
-
and
AND combination of multiple filters 多个过滤器的 AND 组合- Parameters:
filters- filters to combine | 要组合的过滤器- Returns:
- combined filter | 组合后的过滤器
-
or
OR combination of multiple filters 多个过滤器的 OR 组合- Parameters:
filters- filters to combine | 要组合的过滤器- Returns:
- combined filter | 组合后的过滤器
-
not
Negate a filter 对过滤器取反- Parameters:
filter- filter to negate | 要取反的过滤器- Returns:
- negated filter | 取反后的过滤器
-
isConcrete
Filter for concrete classes (not abstract, not interface) 过滤具体类(非抽象、非接口)- Returns:
- filter | 过滤器
-
isInterface
-
isAbstract
-
isEnum
-
isRecord
-
isAnnotation
-
hasAnnotation
Filter for classes with specified annotation 过滤带指定注解的类- Parameters:
annotation- annotation class | 注解类- Returns:
- filter | 过滤器
-
hasAnyAnnotation
Filter for classes with any of specified annotations 过滤带任意指定注解的类- Parameters:
annotations- annotation classes | 注解类数组- Returns:
- filter | 过滤器
-
hasAllAnnotations
Filter for classes with all specified annotations 过滤带所有指定注解的类- Parameters:
annotations- annotation classes | 注解类数组- Returns:
- filter | 过滤器
-
isSubTypeOf
Filter for subtypes of specified class 过滤指定类的子类型- Parameters:
superType- super type | 父类型- Returns:
- filter | 过滤器
-
implementsInterface
Filter for classes implementing specified interface 过滤实现指定接口的类- Parameters:
interfaceType- interface type | 接口类型- Returns:
- filter | 过滤器
-
nameStartsWith
Filter by name prefix 按名称前缀过滤- Parameters:
prefix- name prefix | 名称前缀- Returns:
- filter | 过滤器
-
nameEndsWith
Filter by name suffix 按名称后缀过滤- Parameters:
suffix- name suffix | 名称后缀- Returns:
- filter | 过滤器
-
simpleNameEndsWith
Filter by simple name suffix 按简单名称后缀过滤- Parameters:
suffix- simple name suffix | 简单名称后缀- Returns:
- filter | 过滤器
-
nameMatches
Filter by name regex pattern 按名称正则模式过滤- Parameters:
regex- regex pattern | 正则模式- Returns:
- filter | 过滤器
-
inPackage
Filter for classes in specified package 过滤指定包中的类- Parameters:
packageName- package name | 包名- Returns:
- filter | 过滤器
-
hasModifier
Filter by modifier 按修饰符过滤- Parameters:
modifier- modifier flag | 修饰符标志- Returns:
- filter | 过滤器
-
isPublic
-
isFinal
-
isSealed
-
hasPermittedSubclass
Filter for sealed classes that have permitted subclasses 过滤有许可子类的密封类- Returns:
- filter | 过滤器
-
hasConstructorWithParameterCount
Filter for classes that have a constructor with the specified parameter count 过滤具有指定参数数量构造器的类- Parameters:
count- parameter count | 参数数量- Returns:
- filter | 过滤器
-
hasMethodWithReturnType
Filter for classes that have a method with the specified return type 过滤具有指定返回类型方法的类- Parameters:
returnType- return type | 返回类型- Returns:
- filter | 过滤器
-
hasMethodWithParameterCount
Filter for classes that have a method with the specified parameter count 过滤具有指定参数数量方法的类- Parameters:
count- parameter count | 参数数量- Returns:
- filter | 过滤器
-
all
-
none
-
isTopLevel
-
isInnerClass
-