Class OpenSealed
java.lang.Object
cloud.opencode.base.reflect.sealed.OpenSealed
Sealed Class Facade Entry Class
密封类门面入口类
Provides common sealed class operations API.
提供常用密封类操作API。
Features | 主要功能:
- Sealed class detection - 密封类检测
- Permitted subclasses access - 许可子类访问
- Hierarchy navigation - 层次结构导航
Usage Examples | 使用示例:
boolean isSealed = OpenSealed.isSealed(Shape.class);
List<Class<?>> subclasses = OpenSealed.getPermittedSubclasses(Shape.class);
PermittedSubclasses permitted = OpenSealed.permitted(Shape.class);
Security | 安全性:
- Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
- Null-safe: Partially (null class returns false for isSealed) - 空值安全: 部分(null类在isSealed中返回false)
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringgenerateSwitchTemplate(Class<?> sealedClass, String variableName) Generates a switch expression pattern matching template (as string) 生成switch表达式模式匹配模板(作为字符串)getAllSubclassesRecursive(Class<?> sealedClass) Gets all subclasses recursively 递归获取所有子类getConcreteTypes(Class<?> sealedClass) Gets all concrete types for pattern matching 获取模式匹配的所有具体类型getHierarchy(Class<?> sealedClass) Gets the hierarchy tree 获取层次结构树getLeafClasses(Class<?> sealedClass) Gets all leaf (non-sealed, non-abstract) classes 获取所有叶(非密封、非抽象)类static intgetPermittedSubclassCount(Class<?> sealedClass) Gets the number of permitted subclasses 获取许可子类数量static PermittedSubclassesgetPermittedSubclasses(Class<?> sealedClass) Gets permitted subclasses 获取许可子类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 of a class (if any) 获取类的密封父类(如果有)static booleanisExhaustive(Class<?> sealedClass) Checks if the sealed hierarchy is exhaustive (all cases handled) 检查密封层次结构是否穷尽(所有情况都已处理)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 <T> Class<T> requireSealed(Class<T> 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 要求类为密封类- Type Parameters:
T- the type | 类型- Parameters:
clazz- the class | 类- Returns:
- the class | 类
- Throws:
IllegalArgumentException- if not sealed | 如果不是密封类
-
getPermittedSubclasses
Gets permitted subclasses 获取许可子类- Parameters:
sealedClass- the sealed class | 密封类- Returns:
- the PermittedSubclasses collection | PermittedSubclasses集合
-
getPermittedSubclassList
-
getPermittedSubclassCount
Gets the number of permitted subclasses 获取许可子类数量- Parameters:
sealedClass- the sealed class | 密封类- Returns:
- the count | 数量
-
isPermittedSubclass
-
getAllSubclassesRecursive
-
getLeafClasses
-
getHierarchy
Gets the hierarchy tree 获取层次结构树- Parameters:
sealedClass- the sealed class | 密封类- Returns:
- the hierarchy node | 层次结构节点
-
getSealedParent
-
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 (all cases handled) 检查密封层次结构是否穷尽(所有情况都已处理)- Parameters:
sealedClass- the sealed class | 密封类- Returns:
- true if exhaustive | 如果穷尽返回true
-
getConcreteTypes
-
generateSwitchTemplate
Generates a switch expression pattern matching template (as string) 生成switch表达式模式匹配模板(作为字符串)- Parameters:
sealedClass- the sealed class | 密封类variableName- the variable name | 变量名- Returns:
- the template string | 模板字符串
-