Record Class Edge<V>
java.lang.Object
java.lang.Record
cloud.opencode.base.graph.node.Edge<V>
- Type Parameters:
V- the vertex type | 顶点类型- Record Components:
from- the source vertex | 源顶点to- the target vertex | 目标顶点weight- the edge weight | 边权重Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Null-safe: Yes (rejects null vertices, NaN and infinite weights) - 空值安全: 是(拒绝null顶点、NaN和无穷权重)
Edge
边
Immutable record representing a weighted edge in a graph.
表示图中加权边的不可变记录。
Features | 特性:
- Immutable - 不可变
- Supports weighted edges - 支持加权边
- Default weight is 1.0 - 默认权重为1.0
Usage Examples | 使用示例:
// Unweighted edge
Edge<String> edge1 = new Edge<>("A", "B");
// Weighted edge
Edge<String> edge2 = new Edge<>("A", "B", 5.0);
// Access properties
String from = edge2.from();
String to = edge2.to();
double weight = edge2.weight();
- Since:
- JDK 25, opencode-base-graph V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.from()Returns the value of thefromrecord component.final inthashCode()Returns a hash code value for this object.booleanCheck if this is a self-loop 检查是否为自环reversed()Create a reversed edge 创建反向边to()Returns the value of thetorecord component.toString()Returns a string representation of this record class.doubleweight()Returns the value of theweightrecord component.withWeight(double newWeight) Create an edge with a new weight 创建具有新权重的边
-
Field Details
-
DEFAULT_WEIGHT
public static final double DEFAULT_WEIGHTDefault edge weight 默认边权重- See Also:
-
-
Constructor Details
-
Edge
-
Edge
-
-
Method Details
-
reversed
-
withWeight
-
isSelfLoop
public boolean isSelfLoop()Check if this is a self-loop 检查是否为自环- Returns:
- true if self-loop | 如果是自环返回true
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
from
-
to
-
weight
-