Class GraphBuilder<V>
java.lang.Object
cloud.opencode.base.graph.builder.GraphBuilder<V>
- Type Parameters:
V- the vertex type | 顶点类型Performance | 性能特性:
- Time complexity: O(1) per operation - 时间复杂度: O(1) 每次操作
- Space complexity: O(V + E) - 空间复杂度: O(V + E)
Graph Builder
图构建器
Fluent builder for constructing graphs.
用于构建图的流式构建器。
Features | 特性:
- Fluent API for graph construction | 流式API用于图构建
- Batch edge/vertex addition | 批量添加边/顶点
- Validation support | 验证支持
- Initial capacity configuration | 初始容量配置
Usage Examples | 使用示例:
// Build a directed graph
Graph<String> graph = GraphBuilder.<String>directed()
.addEdge("A", "B", 1.0)
.addEdge("B", "C", 2.0)
.addEdge("C", "D", 3.0)
.build();
// Build with validation
Graph<String> validGraph = GraphBuilder.<String>directed()
.addEdge("A", "B")
.addEdge("B", "C")
.buildAndValidate();
Security | 安全性:
- Thread-safe: No (builder is not thread-safe, built graph is) - 线程安全: 否(构建器非线程安全,构建的图是)
- Null-safe: No (does not validate inputs during building) - 空值安全: 否(构建过程中不验证输入)
- Since:
- JDK 25, opencode-base-graph V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAdd an edge 添加边Add an edge with default weight 添加默认权重的边Add an edge with weight 添加带权重的边addEdges(Collection<Edge<V>> edges) Add multiple edges 添加多个边Add a vertex 添加顶点addVertices(Collection<V> vertices) Add vertices from collection 从集合添加顶点final GraphBuilder<V> addVertices(V... vertices) Add multiple vertices 添加多个顶点build()Build the graph 构建图Build and validate the graph 构建并验证图configure(Consumer<GraphBuilder<V>> configurer) Configure the builder 配置构建器static <V> GraphBuilder<V> directed()Create a builder for directed graph 创建有向图构建器initialCapacity(int capacity) Set initial capacity for the graph 设置图的初始容量static <V> GraphBuilder<V> Create a builder for undirected graph 创建无向图构建器
-
Method Details
-
directed
Create a builder for directed graph 创建有向图构建器- Type Parameters:
V- the vertex type | 顶点类型- Returns:
- a new graph builder | 新的图构建器
-
undirected
Create a builder for undirected graph 创建无向图构建器- Type Parameters:
V- the vertex type | 顶点类型- Returns:
- a new graph builder | 新的图构建器
-
initialCapacity
Set initial capacity for the graph 设置图的初始容量- Parameters:
capacity- the initial capacity | 初始容量- Returns:
- this builder | 此构建器
-
addVertex
Add a vertex 添加顶点- Parameters:
vertex- the vertex to add | 要添加的顶点- Returns:
- this builder | 此构建器
-
addVertices
Add multiple vertices 添加多个顶点- Parameters:
vertices- the vertices to add | 要添加的顶点- Returns:
- this builder | 此构建器
-
addVertices
Add vertices from collection 从集合添加顶点- Parameters:
vertices- the vertices to add | 要添加的顶点- Returns:
- this builder | 此构建器
-
addEdge
Add an edge with default weight 添加默认权重的边- Parameters:
from- source vertex | 源顶点to- target vertex | 目标顶点- Returns:
- this builder | 此构建器
-
addEdge
Add an edge with weight 添加带权重的边- Parameters:
from- source vertex | 源顶点to- target vertex | 目标顶点weight- edge weight | 边权重- Returns:
- this builder | 此构建器
-
addEdge
Add an edge 添加边- Parameters:
edge- the edge to add | 要添加的边- Returns:
- this builder | 此构建器
-
addEdges
Add multiple edges 添加多个边- Parameters:
edges- the edges to add | 要添加的边- Returns:
- this builder | 此构建器
-
configure
Configure the builder 配置构建器- Parameters:
configurer- the configuration function | 配置函数- Returns:
- this builder | 此构建器
-
build
-
buildAndValidate
-