public class GraphPath
extends java.lang.Object
edges
originating from a specific startNode
(an OnlyToDirectedGraphNodeI
)
in a graph. A GraphPath
defines a concrete route or walk through the graph.
Immutability:
Once a GraphPath
instance is created, its state (including the start node
and the sequence of edges) cannot be changed. Methods that appear to modify the path,
such as appendEdge(GraphEdgeI)
, actually return a new GraphPath
instance, leaving the original path unaltered. This immutability makes
GraphPath
objects inherently thread-safe and reliable for use in
concurrent environments or as keys in hash-based collections (provided
equals(Object)
and hashCode()
are correctly implemented).
Structure:
A path is fundamentally defined by its start node
and an
ordered sequence of its edges
(which are GraphEdgeI
instances).
getStartNode()
is also considered the getEndNode()
.
edges[0]
) should originate from the
getStartNode()
(i.e., edges[0].getFromNode()
should be
equivalent to startNode
).
edges[i]
should start from the node where the
previous edge edges[i-1]
ended (i.e.,
edges[i].getFromNode()
should be equivalent to
edges[i-1].getToNode()
).
getEndNode()
.
Usage: This class is typically used to:
getStartNode()
, getEndNode()
,
and appendEdge(GraphEdgeI)
for creating a new, extended path.Modifier and Type | Field and Description |
---|---|
GraphEdgeI[] |
edges
The sequence of edges forming this path.
|
OnlyToDirectedGraphNodeI |
startNode
The starting node of this path.
|
Constructor and Description |
---|
GraphPath(GraphPath basePath,
GraphEdgeI newEdge)
Constructs a new GraphPath by taking a base path and appending a new edge.
|
GraphPath(OnlyToDirectedGraphNodeI startNode)
Constructs a GraphPath with a specified start node and no edges.
|
Modifier and Type | Method and Description |
---|---|
GraphPath |
appendEdge(GraphEdgeI newEdge)
Appends a new edge to the current path, returning a new
GraphPath instance. |
boolean |
equals(java.lang.Object o) |
OnlyToDirectedGraphNodeI |
getEndNode()
Returns the ending node of this path.
|
OnlyToDirectedGraphNodeI |
getStartNode()
Returns the starting node of this path.
|
int |
hashCode() |
java.lang.String |
toString() |
public final OnlyToDirectedGraphNodeI startNode
public final GraphEdgeI[] edges
public GraphPath(OnlyToDirectedGraphNodeI startNode)
startNode
- The starting node of the path. Must not be null.public GraphPath(GraphPath basePath, GraphEdgeI newEdge)
appendEdge(GraphEdgeI)
.basePath
- The base path. Must not be null.newEdge
- The new edge to append. Must not be null.java.lang.IllegalArgumentException
- if the newEdge does not logically follow the basePath
(Note: specific internal validation for edge connectivity might be subject to
implementation details or specific use-case relaxations, as indicated
by any FIXME comments within the constructor's source).public GraphPath appendEdge(GraphEdgeI newEdge)
GraphPath
instance.
The original GraphPath
remains unchanged, ensuring immutability.newEdge
- The edge to append. Must not be null.GraphPath
instance representing the current path extended by the new edge.public OnlyToDirectedGraphNodeI getStartNode()
OnlyToDirectedGraphNodeI
of the path.public OnlyToDirectedGraphNodeI getEndNode()
startNode
. Otherwise, it's the
'toNode' of the last edge in the path.OnlyToDirectedGraphNodeI
of the path.public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
Copyright © 2000-2025 OAshi S.à r.l. All Rights Reserved.