Class GraphSerializer
java.lang.Object
cloud.opencode.base.graph.serializer.GraphSerializer
Graph Serializer
图序列化器
Utility class for serializing and deserializing graphs.
用于序列化和反序列化图的工具类。
Supported Formats | 支持的格式:
- DOT format (Graphviz) | DOT格式(Graphviz)
- Adjacency list format | 邻接表格式
- Edge list format | 边列表格式
Features | 主要功能:
- Export to DOT format for Graphviz visualization - 导出为DOT格式用于Graphviz可视化
- Serialize and parse adjacency list format - 序列化和解析邻接表格式
- Serialize and parse edge list format - 序列化和解析边列表格式
- Support for weighted and unweighted edges - 支持有权和无权边
- Graph statistics calculation (density, degree distribution) - 图统计信息计算(密度、度分布)
- Handles both directed and undirected graphs - 处理有向图和无向图
Usage Examples | 使用示例:
// Export to DOT format
String dot = GraphSerializer.toDot(graph);
// Export to adjacency list
String adjList = GraphSerializer.toAdjacencyList(graph);
// Parse from adjacency list
Graph<String> graph = GraphSerializer.fromAdjacencyList(adjListString, true);
Security | 安全性:
- Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
- Null-safe: Yes (returns empty string for null graph) - 空值安全: 是(null图返回空字符串)
Security | 安全性:
- Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
- Null-safe: Yes (returns empty string for null graph) - 空值安全: 是(null图返回空字符串)
Performance | 性能特性:
- Time complexity: O(V + E) - 时间复杂度: O(V + E)
- Space complexity: O(V + E) - 空间复杂度: O(V + E)
- Since:
- JDK 25, opencode-base-graph V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionfromAdjacencyList(String input, boolean directed) Parse graph from adjacency list format 从邻接表格式解析图fromEdgeList(String input, boolean directed) Parse graph from edge list format 从边列表格式解析图static <V> StringgetStatistics(Graph<V> graph) Get graph statistics as string 获取图统计信息字符串static <V> StringtoAdjacencyList(Graph<V> graph) Convert graph to adjacency list format 将图转换为邻接表格式static <V> StringConvert graph to DOT format (Graphviz) 将图转换为DOT格式(Graphviz)static <V> StringConvert graph to DOT format with custom name 将图转换为带自定义名称的DOT格式static <V> StringtoEdgeList(Graph<V> graph) Convert graph to edge list format 将图转换为边列表格式
-
Method Details
-
toDot
-
toDot
-
toAdjacencyList
-
fromAdjacencyList
-
toEdgeList
-
fromEdgeList
-
getStatistics
-