public interface DirectedGraphNodeI extends OnlyToDirectedGraphNodeI
OnlyToDirectedGraphNodeI by adding
the capability to identify predecessor nodes and incoming edges.
Implementations of this interface provide a complete view of a node's local connectivity within a directed graph, allowing for bidirectional traversal and more comprehensive graph analysis (e.g., finding all paths, cycle detection, centrality measures).
In addition to the contract from OnlyToDirectedGraphNodeI for outgoing
connections, this interface defines methods to access direct predecessor nodes
(getFromNodes()) and the corresponding incoming edges
(getIncomingEdges()).
| Modifier and Type | Method and Description |
|---|---|
java.util.Collection<? extends OnlyToDirectedGraphNodeI> |
getFromNodes()
Retrieves all direct predecessor nodes from which incoming edges to this node originate.
|
default java.util.Collection<GraphEdgeI> |
getIncomingEdges()
Retrieves all incoming directed edges that lead to this node.
|
getOutgoingEdges, getToNodesjava.util.Collection<? extends OnlyToDirectedGraphNodeI> getFromNodes()
Contract:
null.
If a node has no incoming edges (i.e., no predecessors, like a source node
in a Directed Acyclic Graph (DAG)), an empty, non-null collection must be returned.
Collections.unmodifiableCollection(Collection)).
null elements.Collection of nodes (each implementing
OnlyToDirectedGraphNodeI) representing all direct predecessor nodes.
Each element in the collection is a node from which a single incoming edge
leads to this node.default java.util.Collection<GraphEdgeI> getIncomingEdges()
getFromNodes())
to this node (as the destination/to-node).
This default implementation utilizes Java Streams. It processes the collection of
nodes returned by getFromNodes(), filters out any null predecessor nodes,
and then maps each valid predecessor node to a new DefaultGraphEdge.
In these constructed edges, the predecessor node serves as the source (from-node),
and this current node instance is the destination (to-node). The resulting
edges are collected into a List.
Behavior of this default implementation:
getFromNodes() returns an empty collection, this method will
also return an empty, non-null List.
getFromNodes() returns a collection containing null elements,
these null elements are filtered out by the stream operation and
will not result in edge creation.
getFromNodes() (contrary to its contract) were to return null,
this default implementation returns an empty List due to the initial
null check, ensuring robustness. However, implementers of getFromNodes()
must adhere to its non-null return contract.
List, specifically an ArrayList,
as created by Collectors.toList().
Overriding this method:
Implementers of DirectedGraphNodeI 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 for incoming edges.
Collection is preferred for the result (e.g., a Set).Collection (specifically a List in this
default implementation) of GraphEdgeI instances representing all incoming edges to this node.
In this default implementation, these are typically DefaultGraphEdge instances.getFromNodes(),
GraphEdgeI,
DefaultGraphEdge,
For outgoing edges.Copyright © 2000-2025 OAshi S.à r.l. All Rights Reserved.