Class GraphValidator
java.lang.Object
cloud.opencode.base.graph.validation.GraphValidator
Graph Validator
图验证器
Utility class for validating graph structures and inputs.
用于验证图结构和输入的工具类。
Features | 特性:
- Vertex validation | 顶点验证
- Edge validation | 边验证
- Graph structure validation | 图结构验证
- Weight validation | 权重验证
Usage Examples | 使用示例:
// Validate a vertex
GraphValidator.validateVertex(vertex);
// Validate an edge
GraphValidator.validateEdge(from, to, weight);
// Validate entire graph structure
ValidationResult result = GraphValidator.validateGraph(graph);
if (result.hasErrors()) {
// Handle errors
}
Security | 安全性:
- Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
- Null-safe: Yes (throws exception for null vertices, returns error result for null graph) - 空值安全: 是(null顶点抛出异常,null图返回错误结果)
- Since:
- JDK 25, opencode-base-graph V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <V> booleanedgeExists(Graph<V> graph, V from, V to) Validate edge exists in graph 验证边在图中存在static <V> ValidationResultvalidateDAG(Graph<V> graph) Check if graph is a valid DAG (Directed Acyclic Graph) 检查图是否为有效的DAG(有向无环图)static <V> voidvalidateEdge(V from, V to) Validate an edge 验证边static <V> voidvalidateEdge(V from, V to, double weight) Validate an edge with weight 验证带权重的边static <V> ValidationResultvalidateGraph(Graph<V> graph) Validate graph structure 验证图结构static <V> voidvalidateGraphStructure(Graph<V> graph) Validate graph structure and throw exception if errors found 验证图结构,如果发现错误则抛出异常static <V> voidvalidateVertex(V vertex) Validate a vertex 验证顶点static voidvalidateWeight(double weight) Validate edge weight 验证边权重static <V> booleanvertexExists(Graph<V> graph, V vertex) Validate vertex exists in graph 验证顶点在图中存在
-
Method Details
-
validateVertex
public static <V> void validateVertex(V vertex) Validate a vertex 验证顶点- Type Parameters:
V- the vertex type | 顶点类型- Parameters:
vertex- the vertex to validate | 要验证的顶点- Throws:
InvalidVertexException- if vertex is invalid | 如果顶点无效则抛出异常
-
validateEdge
public static <V> void validateEdge(V from, V to) Validate an edge 验证边- Type Parameters:
V- the vertex type | 顶点类型- Parameters:
from- source vertex | 源顶点to- target vertex | 目标顶点- Throws:
InvalidVertexException- if vertices are invalid | 如果顶点无效则抛出异常
-
validateEdge
public static <V> void validateEdge(V from, V to, double weight) Validate an edge with weight 验证带权重的边- Type Parameters:
V- the vertex type | 顶点类型- Parameters:
from- source vertex | 源顶点to- target vertex | 目标顶点weight- edge weight | 边权重- Throws:
InvalidVertexException- if vertices are invalid | 如果顶点无效则抛出异常InvalidEdgeException- if weight is invalid | 如果权重无效则抛出异常
-
validateWeight
public static void validateWeight(double weight) Validate edge weight 验证边权重- Parameters:
weight- the weight to validate | 要验证的权重- Throws:
InvalidEdgeException- if weight is invalid | 如果权重无效则抛出异常
-
validateGraph
Validate graph structure 验证图结构- Type Parameters:
V- the vertex type | 顶点类型- Parameters:
graph- the graph to validate | 要验证的图- Returns:
- validation result | 验证结果
-
validateGraphStructure
Validate graph structure and throw exception if errors found 验证图结构,如果发现错误则抛出异常- Type Parameters:
V- the vertex type | 顶点类型- Parameters:
graph- the graph to validate | 要验证的图- Throws:
InvalidEdgeException- if graph has errors | 如果图有错误则抛出异常
-
validateDAG
Check if graph is a valid DAG (Directed Acyclic Graph) 检查图是否为有效的DAG(有向无环图)- Type Parameters:
V- the vertex type | 顶点类型- Parameters:
graph- the graph to check | 要检查的图- Returns:
- validation result | 验证结果
-
vertexExists
Validate vertex exists in graph 验证顶点在图中存在- Type Parameters:
V- the vertex type | 顶点类型- Parameters:
graph- the graph | 图vertex- the vertex to check | 要检查的顶点- Returns:
- true if vertex exists | 如果顶点存在返回true
-
edgeExists
Validate edge exists in graph 验证边在图中存在- Type Parameters:
V- the vertex type | 顶点类型- Parameters:
graph- the graph | 图from- source vertex | 源顶点to- target vertex | 目标顶点- Returns:
- true if edge exists | 如果边存在返回true
-