public class LinkGraph extends Object
IServiceProvider
instances providing ILinkService
)
represented as an adjacency list.Constructor and Description |
---|
LinkGraph()
Initializes a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addLink(IServiceProvider link)
Adds a link to the graph.
|
boolean |
contains(IServiceProvider link)
Determines whether the given link is in the graph.
|
IServiceProvider[] |
findAllLinksAtNode(IServiceProvider node,
LinkGraphDirection direction)
Find all the links which contain the given node and are in the correct direction.
|
LinkPath[] |
findAllPaths(IServiceProvider initial,
IServiceProvider _final,
LinkGraphDirection direction)
Finds all paths between two objects.
|
LinkPath[] |
findAllPaths(IServiceProvider initial,
IServiceProvider _final,
LinkGraphDirection direction,
int maximumLength)
Finds all paths between two objects.
|
LinkPath |
findShortestPath(IServiceProvider initial,
IServiceProvider _final,
LinkGraphDirection direction)
Finds the shortest path between an initial object and a final object.
|
public final void addLink(@Nonnull IServiceProvider link)
link
- The link to add.@Nullable public final LinkPath findShortestPath(IServiceProvider initial, IServiceProvider _final, @Nonnull LinkGraphDirection direction)
initial
- The initial object._final
- The final object.direction
- The direction of the signal. If this parameter is LinkGraphDirection.TRANSMIT
, the
initial
object is transmitting to the _final
object and all links
along the way must be in the transmit direction. If this parameter is LinkGraphDirection.RECEIVE
,
the _final
object is receiving from the _final
object and all
links along the way must be in the receive direction. If this parameter is LinkGraphDirection.IGNORE
,
the signal direction is ignored and links in either direction can be traversed.initial
to _final
.
If a path does not exist, null
is returned. If the initial and final objects are the same
an empty array is returned.@Nullable public final LinkPath[] findAllPaths(IServiceProvider initial, IServiceProvider _final, @Nonnull LinkGraphDirection direction)
initial
- The source object._final
- The destination object.direction
- The direction of the signal. If this parameter is LinkGraphDirection.TRANSMIT
, the
initial
object is transmitting to the _final
object and all links
along the way must be in the transmit direction. If this parameter is LinkGraphDirection.RECEIVE
,
the _final
object is receiving from the _final
object and all
links along the way must be in the receive direction. If this parameter is LinkGraphDirection.IGNORE
,
the signal direction is ignored and links in either direction can be traversed.null
if either object is not in the graph.
Each path is a list of links that are traversed along the path.@Nullable public final LinkPath[] findAllPaths(IServiceProvider initial, IServiceProvider _final, @Nonnull LinkGraphDirection direction, int maximumLength)
initial
- The source object._final
- The destination object.direction
- The direction of the signal. If this parameter is LinkGraphDirection.TRANSMIT
, the
initial
object is transmitting to the _final
object and all links
along the way must be in the transmit direction. If this parameter is LinkGraphDirection.RECEIVE
,
the _final
object is receiving from the _final
object and all
links along the way must be in the receive direction. If this parameter is LinkGraphDirection.IGNORE
,
the signal direction is ignored and links in either direction can be traversed.maximumLength
- The maximum length of paths to explore. The length of a path is the number of links in the path.null
if either object is not in the graph.
Each path is a list of links that are traversed along the path.@Nonnull public final IServiceProvider[] findAllLinksAtNode(IServiceProvider node, @Nonnull LinkGraphDirection direction)
node
- The node for which to search.direction
- The direction for which to search.public final boolean contains(IServiceProvider link)
link
- The link to locate in the graph.true
if the link is in the graph; otherwise false
.