Interface ValueGraph<N,V>
- Type Parameters:
N- node type | 节点类型V- edge value type | 边值类型
- All Known Subinterfaces:
MutableValueGraph<N,V>
public interface ValueGraph<N,V>
ValueGraph - Value Graph Interface
ValueGraph - 值图接口
An interface for graph data structures where edges have associated values (weights).
边带有关联值(权重)的图数据结构接口。
Features | 主要功能:
- Node and edge operations - 节点和边操作
- Edge value queries - 边值查询
- Directed/undirected support - 有向/无向支持
- Adjacency queries - 邻接查询
Usage Examples | 使用示例:
MutableValueGraph<String, Double> graph = MutableValueGraph.directed();
graph.addNode("A");
graph.addNode("B");
graph.putEdgeValue("A", "B", 3.5);
Optional<Double> weight = graph.edgeValue("A", "B"); // Optional[3.5]
boolean connected = graph.hasEdgeConnecting("A", "B"); // true
Security | 安全性:
- Thread-safe: No (interface, implementation-dependent) - 否(接口,取决于实现)
- Null-safe: No - 否
- Since:
- JDK 25, opencode-base-collections V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordEndpoint pair representing an edge between two nodes. -
Method Summary
Modifier and TypeMethodDescriptionadjacentNodes(N node) Return all adjacent nodes (both successors and predecessors).intReturn the degree of a node (number of edges incident to it).default intReturn the number of edges.edges()Return the set of all edges in this graph.Return the value of the edge connectingnodeUtonodeV, if present.edgeValueOrDefault(N nodeU, N nodeV, V defaultValue) Return the value of the edge connectingnodeUtonodeV, ordefaultValueif no edge exists.booleanhasEdgeConnecting(N nodeU, N nodeV) Check if there is an edge connectingnodeUtonodeV.booleanCheck if this graph is directed.default intReturn the number of nodes.nodes()Return the set of all nodes in this graph.predecessors(N node) Return the predecessors (incoming neighbors) of a node.successors(N node) Return the successors (outgoing neighbors) of a node.
-
Method Details
-
nodes
-
edges
Set<ValueGraph.EndpointPair<N>> edges()Return the set of all edges in this graph. 返回此图中所有边的集合。- Returns:
- the set of edges | 边集合
-
edgeValue
Return the value of the edge connectingnodeUtonodeV, if present. 返回连接nodeU到nodeV的边的值(如果存在)。- Parameters:
nodeU- the source node | 源节点nodeV- the target node | 目标节点- Returns:
- the edge value, or empty if no edge exists | 边值,如果不存在则返回空
- Throws:
IllegalArgumentException- if either node is not in the graph | 如果节点不在图中则抛出异常
-
edgeValueOrDefault
Return the value of the edge connectingnodeUtonodeV, ordefaultValueif no edge exists. 返回连接nodeU到nodeV的边的值,如果不存在则返回默认值。- Parameters:
nodeU- the source node | 源节点nodeV- the target node | 目标节点defaultValue- the default value | 默认值- Returns:
- the edge value, or default if no edge exists | 边值或默认值
- Throws:
IllegalArgumentException- if either node is not in the graph | 如果节点不在图中则抛出异常
-
hasEdgeConnecting
-
adjacentNodes
Return all adjacent nodes (both successors and predecessors). 返回所有邻接节点(后继和前驱)。- Parameters:
node- the node | 节点- Returns:
- the set of adjacent nodes | 邻接节点集合
- Throws:
IllegalArgumentException- if node is not in the graph | 如果节点不在图中则抛出异常
-
predecessors
Return the predecessors (incoming neighbors) of a node. 返回节点的前驱(入边邻居)。- Parameters:
node- the node | 节点- Returns:
- the set of predecessors | 前驱集合
- Throws:
IllegalArgumentException- if node is not in the graph | 如果节点不在图中则抛出异常
-
successors
Return the successors (outgoing neighbors) of a node. 返回节点的后继(出边邻居)。- Parameters:
node- the node | 节点- Returns:
- the set of successors | 后继集合
- Throws:
IllegalArgumentException- if node is not in the graph | 如果节点不在图中则抛出异常
-
degree
Return the degree of a node (number of edges incident to it). 返回节点的度数(入射边的数量)。- Parameters:
node- the node | 节点- Returns:
- the degree | 度数
- Throws:
IllegalArgumentException- if node is not in the graph | 如果节点不在图中则抛出异常
-
isDirected
boolean isDirected()Check if this graph is directed. 检查此图是否有向。- Returns:
- true if directed | 如果有向则返回 true
-
nodeCount
default int nodeCount()Return the number of nodes. 返回节点数量。- Returns:
- the number of nodes | 节点数量
-
edgeCount
default int edgeCount()Return the number of edges. 返回边数量。- Returns:
- the number of edges | 边数量
-