Package model.graph
Record Class UEdge<A>
java.lang.Object
java.lang.Record
model.graph.UEdge<A>
- Type Parameters:
A- the type of vertices that form the undirected edge.
A representation of an undirected edge on a simple undirected graph. More formally, an
unordered pair of objects of the same type which represent the two vertices that form
the ends of an undirected edge. Moreover, the two vertices are not equal as simple
undirected graphs do not allow self-loops.
This class models such an undirected edge as a record with two components of the same
type <A>, namely u and v, which represent the two vertices that
form the ends of an undirected edge.
Note: To ensure undirected / unordered pair behaviour, specifically that
new UEdge<>(u, v).equals(new UEdge<>(v, u)) returns true, the end vertices
u and v are stored internally in a canonical order. This is done by
comparing hashCode() and using toString() as a tiebreaker in case hashCode()
is equal for u and v. Therefore, ensure that toString() for objects of type
<A> are stable and deterministic.
- Since:
- 2025
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.toString()Returns a string representation of this record class.u()Returns the value of theurecord component.v()Returns the value of thevrecord component.
-
Constructor Details
-
UEdge
Constructs an undirected edge between the verticesuandvboth of type<A>.- Parameters:
u- End vertex of the undirected edgev- End vertex of the undirected edge- Throws:
exceptions.InvalidEdgeException- ifu.equals(v) = trueas self-loops are not allowed
-
-
Method Details
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
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. All components in this record class are compared withObjects::equals(Object,Object). -
u
Returns the value of theurecord component.- Returns:
- the value of the
urecord component
-
v
Returns the value of thevrecord component.- Returns:
- the value of the
vrecord component
-