public class DefaultGraphEdge extends java.lang.Object implements GraphEdgeI
GraphEdgeI interface.
This class represents a directed edge connecting a specified source node
(fromNode) to a target node (toNode). Both nodes are instances
of OnlyToDirectedGraphNodeI.
Instances of DefaultGraphEdge are immutable: the source and target nodes
are set at construction time via the constructor
DefaultGraphEdge(OnlyToDirectedGraphNodeI, OnlyToDirectedGraphNodeI)
and cannot be changed thereafter. This design makes them inherently thread-safe
and suitable for use in various graph data structures and algorithms.
This class also provides standard and consistent implementations for
equals(Object), hashCode(), and toString() methods,
making it well-behaved for use in collections and for debugging.
| Constructor and Description |
|---|
DefaultGraphEdge(OnlyToDirectedGraphNodeI fromNode,
OnlyToDirectedGraphNodeI toNode)
Constructs a new
DefaultGraphEdge connecting the specified source and target nodes. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(java.lang.Object o)
Indicates whether some other object is "equal to" this one.
|
OnlyToDirectedGraphNodeI |
getFromNode()
Retrieves the source node from which this directed edge originates.
|
OnlyToDirectedGraphNodeI |
getToNode()
Retrieves the target node to which this directed edge points.
|
int |
hashCode()
Returns a hash code value for the edge.
|
java.lang.String |
toString()
Returns a string representation of this edge, primarily for debugging and logging.
|
public DefaultGraphEdge(OnlyToDirectedGraphNodeI fromNode, OnlyToDirectedGraphNodeI toNode)
DefaultGraphEdge connecting the specified source and target nodes.fromNode - The non-null source node (from-node or tail) from which this edge originates.toNode - The non-null target node (to-node or head) to which this edge points.java.lang.IllegalArgumentException - if either fromNode or toNode is null.public OnlyToDirectedGraphNodeI getFromNode()
This method is contractually obligated to return a non-null
OnlyToDirectedGraphNodeI instance, as every valid edge must
have a defined starting point.
In this implementation, this method returns the source node that was provided at the time of construction.
getFromNode in interface GraphEdgeIpublic OnlyToDirectedGraphNodeI getToNode()
This method is contractually obligated to return a non-null
OnlyToDirectedGraphNodeI instance, as every valid edge must
have a defined ending point.
In this implementation, this method returns the target node that was provided at the time of construction.
getToNode in interface GraphEdgeIpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object o)
Two DefaultGraphEdge instances are considered equal if they are of the
same class and their source nodes are equal and their target nodes are equal.
The equality of the nodes is determined by their respective equals methods.
equals in class java.lang.Objecto - The reference object with which to compare.true if this edge is the same as the o argument
(i.e., same class, same from-node, and same to-node);
false otherwise.public int hashCode()
DefaultGraphEdge instances will have the same hash code.hashCode in class java.lang.ObjectCopyright © 2000-2025 OAshi S.à r.l. All Rights Reserved.