Package cloud.opencode.base.functional.pattern
package cloud.opencode.base.functional.pattern
Pattern Matching - Enhanced pattern matching utilities
模式匹配 - 增强的模式匹配工具
Provides pattern matching utilities that complement JDK 25's native pattern matching with additional features for complex matching scenarios.
提供补充 JDK 25 原生模式匹配的工具,支持复杂匹配场景的附加功能。
Features | 主要功能:
Usage Examples | 使用示例:
// Type matching
String result = OpenMatch.of(value)
.caseOf(String.class, s -> "String: " + s)
.caseOf(Integer.class, n -> "Number: " + n)
.when(Objects::isNull, o -> "null")
.orElse(o -> "Unknown");
// With JDK 25 native pattern matching
double area = switch (shape) {
case Circle(var r) -> Math.PI * r * r;
case Rectangle(var w, var h) -> w * h;
};
JDK 25 Integration | JDK 25 集成:
Works alongside JDK 25's pattern matching for switch and instanceof.
与 JDK 25 的 switch 和 instanceof 模式匹配协同工作。
- Since:
- JDK 25, opencode-base-functional V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
ClassDescriptionCase<T,
R> Case - Match case definition combining pattern and action Case - 组合模式和动作的匹配分支定义OpenMatch - Pattern matching entry point OpenMatch - 模式匹配入口Matcher - Fluent pattern matching builder Matcher - 流式模式匹配构建器Pattern<T,R> Pattern - Pattern interface for matching values Pattern - 用于匹配值的模式接口