public interface OnlyToDirectedGraphNodeI
Implementations of this interface define the structure of a graph by specifying the direct successors (or "children" in a tree context) of a node. This is fundamental for algorithms involving forward traversal, such as reachability analysis, pathfinding from a source, or exploring tree-like structures.
The core contract involves providing access to these successor nodes via
getToNodes()
, and by extension, the outgoing edges via
getOutgoingEdges()
.
Modifier and Type | Method and Description |
---|---|
default java.util.Collection<GraphEdgeI> |
getOutgoingEdges()
Retrieves all outgoing directed edges that originate from this node.
|
java.util.Collection<? extends OnlyToDirectedGraphNodeI> |
getToNodes()
Retrieves all direct successor nodes to which outgoing edges from this node lead.
|
java.util.Collection<? extends OnlyToDirectedGraphNodeI> getToNodes()
Contract:
null
.
If a node has no outgoing edges (i.e., no successors), an empty, non-null
collection must be returned.
Collections.unmodifiableCollection(Collection)
).
null
elements.Collection
of OnlyToDirectedGraphNodeI
instances representing all direct successor nodes. Each element in the
collection is a node reachable via a single outgoing edge from this node.default java.util.Collection<GraphEdgeI> getOutgoingEdges()
getToNodes()
).
This default implementation iterates over the nodes returned by getToNodes()
and, for each valid successor node, constructs a DefaultGraphEdge
where
this
current node instance is the source (from-node) and the successor node is the
destination (to-node).
Behavior of this default implementation:
getToNodes()
returns an empty collection, this method will
also return an empty, non-null collection.
getToNodes()
returns a collection containing null
elements,
this default implementation will skip such null
elements when creating edges.
getToNodes()
(contrary to its contract) were to return null
,
this default implementation currently returns an empty list for robustness.
However, implementers of getToNodes()
must adhere to its
non-null return contract.
Overriding this method:
Implementers of OnlyToDirectedGraphNodeI
may choose to override this default method if:
GraphEdgeI
(other than DefaultGraphEdge
) or carry additional state or behavior.
GraphEdgeI
returned,
or if DefaultGraphEdge(OnlyToDirectedGraphNodeI, OnlyToDirectedGraphNodeI)
is not suitable for their edge creation logic.
Collection
of GraphEdgeI
instances representing all outgoing edges from this node.
In this default implementation, these are typically DefaultGraphEdge
instances.getToNodes()
,
GraphEdgeI
,
DefaultGraphEdge
Copyright © 2000-2025 OAshi S.à r.l. All Rights Reserved.