Class Pipeline<T,R>
java.lang.Object
cloud.opencode.base.functional.pipeline.Pipeline<T,R>
- Type Parameters:
T- input type - 输入类型R- output type - 输出类型
Pipeline - Composable data transformation pipeline
Pipeline - 可组合的数据转换管道
A fluent API for building transformation pipelines that process data through a series of stages. Supports filtering, mapping, flat-mapping, and error handling.
用于构建转换管道的流式 API,通过一系列阶段处理数据。支持过滤、映射、 扁平映射和错误处理。
Features | 主要功能:
- Fluent chainable operations - 流式可链接操作
- Type-safe transformations - 类型安全转换
- Error handling integration - 错误处理集成
- Lazy evaluation option - 惰性求值选项
- Collection processing - 集合处理
Usage Examples | 使用示例:
// Simple transformation pipeline
String result = Pipeline.of(" hello world ")
.map(String::trim)
.map(String::toUpperCase)
.filter(s -> s.length() > 0)
.execute();
// Pipeline with error handling
Try<Integer> parsed = Pipeline.of(userInput)
.map(String::trim)
.filter(s -> !s.isEmpty())
.mapTry(Integer::parseInt)
.executeTry();
// Collection pipeline
List<String> names = Pipeline.ofCollection(users)
.filter(User::isActive)
.map(User::getName)
.map(String::toUpperCase)
.toList();
// Pipeline composition
Pipeline<String, Integer> parseAndValidate = Pipeline.<String>identity()
.map(String::trim)
.mapTry(Integer::parseInt);
Performance | 性能特性:
- Each stage is O(1) to add - 每个阶段添加为 O(1)
- Execution is O(n) for n stages - 执行为 O(n) n 个阶段
- Memory: proportional to pipeline length - 内存: 与管道长度成正比
Security | 安全性:
- Thread-safe: No (not designed for concurrent modification) - 线程安全: 否
- Null-safe: Configurable null handling - 空值安全: 可配置空值处理
- Since:
- JDK 25, opencode-base-functional V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classCollectionPipeline - Pipeline for processing collections CollectionPipeline - 用于处理集合的管道static final classPipelineBuilder - Fluent builder for single-value pipelines PipelineBuilder - 单值管道的流式构建器static final classTryPipelineBuilder - Builder for pipelines that may fail TryPipelineBuilder - 可能失败的管道构建器 -
Method Summary
Modifier and TypeMethodDescriptionChain another transformation 链接另一个转换Apply the pipeline to a value 将管道应用于值Apply the pipeline safely, returning Try 安全地应用管道,返回 TryCompose with another pipeline 与另一个管道组合static <T,R> Pipeline <T, R> Create a pipeline from a function 从函数创建管道static <T> Pipeline<T, T> identity()Create an identity pipeline 创建恒等管道static <T> Pipeline.PipelineBuilder<T> of(T value) Create a pipeline starting with a value 创建以值开始的管道static <T> Pipeline.CollectionPipeline<T, T> ofCollection(Collection<T> collection) Create a collection pipeline 创建集合管道Get the underlying function 获取底层函数
-
Method Details
-
of
Create a pipeline starting with a value 创建以值开始的管道- Type Parameters:
T- value type - 值类型- Parameters:
value- starting value - 起始值- Returns:
- pipeline builder
-
identity
Create an identity pipeline 创建恒等管道- Type Parameters:
T- type - 类型- Returns:
- identity pipeline
-
from
-
ofCollection
Create a collection pipeline 创建集合管道- Type Parameters:
T- element type - 元素类型- Parameters:
collection- the collection - 集合- Returns:
- collection pipeline builder
-
apply
-
applyTry
-
andThen
-
compose
-
toFunction
-