Class SealedUtil
java.lang.Object
cloud.opencode.base.reflect.sealed.SealedUtil
Sealed Class Utility Class
密封类工具类
Provides low-level sealed class operation utilities with caching.
提供带缓存的底层密封类操作工具。
Features | 主要功能:
- Sealed class detection - 密封类检测
- Permitted subclasses discovery with caching - 带缓存的许可子类发现
- Recursive subclass resolution - 递归子类解析
Usage Examples | 使用示例:
boolean isSealed = SealedUtil.isSealed(Shape.class);
Class<?>[] permitted = SealedUtil.getPermittedSubclasses(Shape.class);
Security | 安全性:
- Thread-safe: Yes (uses ConcurrentHashMap for caching) - 线程安全: 是(使用ConcurrentHashMap缓存)
- Null-safe: No (caller must ensure non-null arguments) - 空值安全: 否(调用方须确保非空参数)
Performance | 性能特性:
- Time complexity: O(1) for cached lookups; O(p) for first access where p is the number of permitted subclasses - 时间复杂度: 缓存命中时 O(1);首次访问为 O(p),p为许可子类数量
- Space complexity: O(p) for the cached permitted subclasses per sealed class - 空间复杂度: O(p),每个密封类缓存许可子类
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidClears all caches 清除所有缓存static voidclearCache(Class<?> clazz) Clears cache for specific class 清除特定类的缓存getAllSubclassesRecursive(Class<?> sealedClass) Gets all subclasses recursively (cached) 递归获取所有子类(缓存)getConcreteTypes(Class<?> sealedClass) Gets all concrete (instantiable) types 获取所有具体(可实例化)类型static intgetHierarchyDepth(Class<?> sealedClass) Gets the depth of the sealed hierarchy 获取密封层次结构的深度getLeafClasses(Class<?> sealedClass) Gets all leaf classes (final or non-sealed) 获取所有叶类(final或非密封)getNonExhaustiveLeaves(Class<?> sealedClass) Gets non-exhaustive leaf classes 获取非穷尽叶类static intgetPermittedSubclassCount(Class<?> sealedClass) Gets permitted subclasses count 获取许可子类数量static Class<?>[]getPermittedSubclasses(Class<?> sealedClass) Gets permitted subclasses (cached) 获取许可子类(缓存)getPermittedSubclassList(Class<?> sealedClass) Gets permitted subclasses as list 获取许可子类列表getSealedInterfaces(Class<?> clazz) Gets all sealed interfaces implemented by a class 获取类实现的所有密封接口getSealedParent(Class<?> clazz) Gets the sealed parent class 获取密封父类static intgetTotalTypeCount(Class<?> sealedClass) Gets the total number of types in the hierarchy 获取层次结构中的类型总数static booleanhasSealedInterface(Class<?> clazz) Checks if class implements a sealed interface 检查类是否实现密封接口static booleanhasSealedParent(Class<?> clazz) Checks if class has a sealed parent 检查类是否有密封父类static booleanisExhaustive(Class<?> sealedClass) Checks if the sealed hierarchy is exhaustive 检查密封层次结构是否穷尽static booleanisNonSealed(Class<?> clazz) Checks if a class is a non-sealed subclass 检查类是否为非密封子类static booleanisPermittedSubclass(Class<?> sealedClass, Class<?> subclass) Checks if a class is a permitted subclass 检查类是否为许可子类static booleanChecks if a class is sealed 检查类是否为密封类static booleanisSealedClass(Object obj) Checks if an object's class is sealed 检查对象的类是否为密封类static voidrequireSealed(Class<?> clazz) Requires class to be sealed 要求类为密封类static booleanvalidateHierarchy(Class<?> sealedClass) Validates that all permitted subclasses extend the sealed class 验证所有许可子类都继承密封类
-
Method Details
-
isSealed
Checks if a class is sealed 检查类是否为密封类- Parameters:
clazz- the class | 类- Returns:
- true if sealed | 如果是密封类返回true
-
isSealedClass
Checks if an object's class is sealed 检查对象的类是否为密封类- Parameters:
obj- the object | 对象- Returns:
- true if sealed | 如果是密封类返回true
-
requireSealed
Requires class to be sealed 要求类为密封类- Parameters:
clazz- the class | 类- Throws:
IllegalArgumentException- if not sealed | 如果不是密封类
-
isNonSealed
Checks if a class is a non-sealed subclass 检查类是否为非密封子类- Parameters:
clazz- the class | 类- Returns:
- true if non-sealed | 如果是非密封返回true
-
getPermittedSubclasses
-
getPermittedSubclassList
-
getPermittedSubclassCount
Gets permitted subclasses count 获取许可子类数量- Parameters:
sealedClass- the sealed class | 密封类- Returns:
- the count | 数量
-
isPermittedSubclass
-
getAllSubclassesRecursive
-
getLeafClasses
-
getConcreteTypes
-
hasSealedParent
Checks if class has a sealed parent 检查类是否有密封父类- Parameters:
clazz- the class | 类- Returns:
- true if has sealed parent | 如果有密封父类返回true
-
getSealedParent
-
hasSealedInterface
Checks if class implements a sealed interface 检查类是否实现密封接口- Parameters:
clazz- the class | 类- Returns:
- true if implements sealed interface | 如果实现密封接口返回true
-
getSealedInterfaces
-
validateHierarchy
Validates that all permitted subclasses extend the sealed class 验证所有许可子类都继承密封类- Parameters:
sealedClass- the sealed class | 密封类- Returns:
- true if valid | 如果有效返回true
-
isExhaustive
Checks if the sealed hierarchy is exhaustive 检查密封层次结构是否穷尽- Parameters:
sealedClass- the sealed class | 密封类- Returns:
- true if exhaustive | 如果穷尽返回true
-
getNonExhaustiveLeaves
-
getHierarchyDepth
Gets the depth of the sealed hierarchy 获取密封层次结构的深度- Parameters:
sealedClass- the sealed class | 密封类- Returns:
- the depth | 深度
-
getTotalTypeCount
Gets the total number of types in the hierarchy 获取层次结构中的类型总数- Parameters:
sealedClass- the sealed class | 密封类- Returns:
- the total count | 总数
-
clearCache
public static void clearCache()Clears all caches 清除所有缓存 -
clearCache
Clears cache for specific class 清除特定类的缓存- Parameters:
clazz- the class | 类
-